Esempio n. 1
0
	def camera_detector(self,cap,wait = 10):
		detect_timer = Timer()
		ret,_ = cap.read()
		
		while ret:
			ret,frame = cap.read()
			detect_timer.tic()
			result = self.detect(frame)
			detect_timer.toc()
			print('Average detecting time: {:.3f}s'.format(      #统计处理一帧数据的平均检测时间
                detect_timer.average_time))
			
			self.draw_result(frame,result)
			cv2.imshow('camera',frame)
			cv2.waiKey(wait)
			
			ret,frame = cap.read()
Esempio n. 2
0
	def img_cv_show(self, image_data, contour=[], centroid=[]):
        if (contour != []  and centroid != [])
            cv2.drawContours(image_data, 
                            contours=[contour],
                            contourIdx=1,
                            color=(0,255,0),
                            thickness=2)
            offCenterX = str(centroid[0] - image_data.shape[0]/2)
            offCenterY = str(image_data.shape[1] - centroid[1])
            offCenter = "(" + offCenterX + "," + offCenterY + ")"

            cv2.putText(image_data,
                        text=offCenter,
                        org=(centroid[0]-20, centroid[1]-20),
                        fontFace=cv2.FONT_HERSHEY_SIMPLEX,
                        fontScale=0.5,
                        color=(0,0,0))
		cv2.imshow('Image Window', image_data)
		cv2.waiKey(3)
     print 'processing %s...' % fn,
     img = cv2.imread(fn, 0)
     if img is None:
         print "Failed to load", fn
         continue
     
     h, w = img.shape[:2]
     print("%d,%d" %(h,w))
     found, corners = cv2.findChessboardCorners(img, pattern_size)
     if found:
         term = ( cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_COUNT, 30, 0.1 )
         cv2.cornerSubPix(img, corners, (5, 5), (-1, -1), term)
     if debug_dir:
         vis = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
         cv2.drawChessboardCorners(vis, pattern_size, corners, found)
         cv2.imshow("Image",vis)
         cv2.waiKey(0)
         # path, name, ext = splitfn(fn)
         # cv2.imwrite('%s/%s_chess.bmp' % (debug_dir, name), vis)
     if not found:
         print 'chessboard not found'
         continue
     img_points.append(corners.reshape(-1, 2))
     obj_points.append(pattern_points)
     
     print 'ok'
 rms, camera_matrix, dist_coefs, rvecs, tvecs = cv2.calibrateCamera(obj_points, img_points, (w, h), None, None)
 print "RMS:", rms
 print "camera matrix:\n", camera_matrix
 print "distortion coefficients: ", dist_coefs.ravel()
 cv2.destroyAllWindows()
Esempio n. 4
0
from picamera.array import PiRGBArray
from picamera import PiCamera
import cv2
import time

camera = PiCamera() 
rawCapture = PiRGBArray(camera)

time.sleep(0.1)


camera.capture(rawCapture, format="bgr")
image = rawCapture.array
cv2.imshow("Image", image)
cv2.waiKey(0)

Esempio n. 5
0
    # CV_CAP_PROP_FORMAT由返回的Mat对象的格式retrieve()。
    # CV_CAP_PROP_MODE特定于后端的值,指示当前的捕获模式。
    # CV_CAP_PROP_BRIGHTNESS图像的亮度(仅适用于相机)。
    # CV_CAP_PROP_CONTRAST图像的对比度(仅适用于相机)。
    # CV_CAP_PROP_SATURATION图像的饱和度(仅适用于相机)。
    # CV_CAP_PROP_HUE图像的色相(仅适用于相机)。
    # CV_CAP_PROP_GAIN图像的增益(仅适用于相机)。
    # CV_CAP_PROP_EXPOSURE曝光(仅适用于相机)。
    # CV_CAP_PROP_CONVERT_RGB布尔型标志,指示是否应将图像转换为RGB。
    # CV_CAP_PROP_WHITE_BALANCE_U白平衡设置的U值(注意:当前仅由DC1394 v 2.x后端支持)
    # CV_CAP_PROP_WHITE_BALANCE_V白平衡设置的V值(注意:当前仅受DC1394 v 2.x后端支持)
    # CV_CAP_PROP_RECTIFICATION立体摄像机的纠正标志(注意:当前仅受DC1394 v 2.x后端支持)
    # CV_CAP_PROP_ISO_SPEED摄像机的ISO速度(注意:当前仅受DC1394 v 2.x后端支持)
    CV_CAP_PROP_BUFFERSIZE存储在内部缓冲存储器中的帧数(注意:当前仅受DC1394 v 2.x后端支持)

    注意:在播放每一帧时,使用 cv2.waiKey() 设置适当的持续时间。如果设置的太低视频就会播放的非常快,如果设置的太高就
    会播放的很慢(你可以使用这种方法控制视频的播放速度)。通常情况下 25 毫秒就可以了。

cv2.VideoWriter()   # 保存视频流、

cv2.VideoWriter_fourcc(*'XVID') # 视频的编码格式

    In Fedora: DIVX, XVID, MJPG, X264, WMV1, WMV2. (XVID is more preferable. MJPG results in high size video. X264 givesvery small size video)
    In Windows: DIVX (More to be tested and added)
    In OSX : (I don’t have access to OSX. Can some one fill this?)
    FourCC 码以下面的格式传给程序,以 MJPG 为例:
    cv2.cv.FOURCC('M','J','P','G') 或者 cv2.cv.FOURCC(*'MJPG')。

cv2.VideoWriter('output.avi',fourcc, 20.0, (640,480))  #1.保存视频流名称,编码格式,帧率,每一帧大小

Esempio n. 6
0
    for (i,c) in enumerate(cnts):

        #zapewniamy wykrycie jedynie 3 markerów
        #break if more than 3 contours appears
        if i >= 3:
            break
        M=cv2.moments(c)
        cX=int((M['m10']/(0.00001+M['m00']))*ratio)
        cY=int((M['m01']/(0.00001+M['m00']))*ratio)
        shape=sd.detect(c)

        #rysujemy kontury z nazwą kształtu
        c=c.astype('float')
        c*=ratio
        c=c.astype('int')
        cv2.drawContours(frame, [c], -1, (0, 255, 0), 2)
        cv2.putText(frame, shape, (cX, cY), cv2.FONT_HERSHEY_SIMPLEX,
                    0.5, (255,255,255), 2)

    cv2.imshow('Image', frame)
    key=cv2.waiKey(1)&0xFF
    if key==ord('q'):
        break

cv2.destroyAllWindows()
vs.stop()
        
        

        
Esempio n. 7
0
lables=[]
faceData=[]
label=0

for nameDir in peoplelist:
    personPath= dataPath + '/' + nameDir
    print ('Leyendo las imagenes')

    for fileName in os.listdir(personPath):
        print ('Rostros:', nameDir + '/' +fileName)
        labels.append (label)
        faceData.append(cv2.imread (personPath+'/'+fileName,0))
        image= cv2.imread(personPath+'/'+fileName, 0)
        cv2.imshow( "image", image)
        cv2.waiKey(10)

    label= label +1

print ('labels',labels)
print ('Número de etiquetas 0: ' np.count_nonzero(np.array(labels)==0))
print ('Número de etiquetas 1: ' np.count_nonzero(np.array(labels)==1))

face_recognizer = cv2.face.EigenFaceRecognizer_create()

#Entrenando el reconocedor de rostros
print('Entrenando...')
face_recognizer.train(facesData, np.array(lables))

#Almacenamiendo el modelo obtenido
face_recognizer.write('modeloEigenFace.xml')
Esempio n. 8
0
#1.导入与显示
#导入模块
import cv2 as cv
#读取图片
img = cv.imread("test1.jpg")  #路径非中文;
#显示图片
cv.imshow("read_img", img)
#等待键盘输入 单位毫秒 0为无限等待 1000ms=1s
cv.waitKey(0)
cv.waiKey(3000)
#释放内存 由于Opencv底层由C++编写
cv.destroyAllWindows()