def getFilter(frameWidht, frameHeight): cvNamedWindow("Filtred") cvCreateTrackbar("hmax", "Filtred", getHlsFilter('hmax'), 180, trackBarChangeHmax) cvCreateTrackbar("hmin", "Filtred", getHlsFilter('hmin'), 180, trackBarChangeHmin) #cvCreateTrackbar("lmax", "Filtred", hlsFilter['lmax'], 255, trackBarChangeLmax) #cvCreateTrackbar("lmin", "Filtred", hlsFilter['lmin'], 255, trackBarChangeLmin) cvCreateTrackbar("smax", "Filtred", getHlsFilter('smax'), 255, trackBarChangeSmax) cvCreateTrackbar("smin", "Filtred", getHlsFilter('smin'), 255, trackBarChangeSmin) cvSetMouseCallback("Filtred", mouseClick, None) frame = cvCreateImage(cvSize(frameWidth, frameHeight), IPL_DEPTH_8U, 3) hlsFrame = cvCreateImage(cvSize(frameWidth, frameHeight), IPL_DEPTH_8U, 3) filtredFrame = cvCreateImage(cvSize(frameWidth, frameHeight), IPL_DEPTH_8U, 3) mask = cvCreateImage(cvSize(frameWidth, frameHeight), IPL_DEPTH_8U, 1) hFrame = cvCreateImage(cvSize(frameWidth, frameHeight), IPL_DEPTH_8U, 1) lFrame = cvCreateImage(cvSize(frameWidth, frameHeight), IPL_DEPTH_8U, 1) sFrame = cvCreateImage(cvSize(frameWidth, frameHeight), IPL_DEPTH_8U, 1) ThHFrame = cvCreateImage(cvSize(frameWidth, frameHeight), IPL_DEPTH_8U, 1) ThLFrame = cvCreateImage(cvSize(frameWidth, frameHeight), IPL_DEPTH_8U, 1) ThSFrame = cvCreateImage(cvSize(frameWidth, frameHeight), IPL_DEPTH_8U, 1) key = -1 while key == -1: if not cvGrabFrame(CAM): print "Could not grab a frame" exit frame = cvQueryFrame(CAM) cvCvtColor(frame, hlsFrame, CV_BGR2HLS) cvSplit(hlsFrame, hFrame, lFrame, sFrame, None) pixelInRange(hFrame, getHlsFilter('hmin'), getHlsFilter('hmax'), 0, 180, ThHFrame) #pixelInRange(lFrame, getHlsFilter('lmin'), getHlsFilter('lmax'), 0, 255, ThLFrame) pixelInRange(sFrame, getHlsFilter('smin'), getHlsFilter('smax'), 0, 255, ThSFrame) cvSetZero(mask) cvAnd(ThHFrame, ThSFrame, mask) cvSetZero(filtredFrame) cvCopy(frame, filtredFrame, mask) cvShowImage("Filtred", filtredFrame) key = cvWaitKey(10) if key == 'r': key = -1 resetHlsFilter() cvDestroyWindow("Filtred")
highgui.cvMoveWindow('Histogram', 10, 270) global mouse_origin global mouse_selection global mouse_select_object mouse_select_object = False global track_object track_object = 0 global track_comp global track_box track_comp = cv.CvConnectedComp() track_box = cv.CvBox2D() highgui.cvSetMouseCallback("Camera", on_mouse, 0) try: # try to get the device number from the command line device = int(sys.argv[1]) # got it ! so remove it from the arguments del sys.argv[1] except (IndexError, ValueError): # no device number on the command line, assume we want the 1st device device = 0 if len(sys.argv) == 1: # no argument on the command line, try to use the camera capture = highgui.cvCreateCameraCapture(device)
ymatch = y def cb_roi(v): global variable_roi variable_roi = v def cb_buf(v): global variable_buf variable_buf = v def cb_focal(v): global variable_focal variable_focal=v def cb_base(v): global variable_base variable_base = v/10.0 xmatch = size.width / 2 + 1 ymatch = size.height / 2 + 1 highgui.cvSetMouseCallback("depthmatch - left", mousecb) highgui.cvCreateTrackbar("ROI", "depthmatch - left", variable_roi, size.width, cb_roi) highgui.cvCreateTrackbar("Buffer", "depthmatch - left", variable_buf, size.width, cb_buf) highgui.cvCreateTrackbar("Focal Length", "depthmatch - left", variable_focal, 1000, cb_focal) highgui.cvCreateTrackbar("Baseline/10", "depthmatch - left", variable_base, 1000, cb_base) leftdraw = cv.cvCreateImage(size, 8, 3) rightdraw = cv.cvCreateImage(size, 8, 3) while 1: depth = depthmatch(xmatch, ymatch, left, right, roi=variable_roi, buf=variable_buf,baseline=variable_base, focal_length=variable_focal) cv.cvCopy(left, leftdraw) cv.cvCopy(right, rightdraw) cv.cvLine(leftdraw, depth[1], depth[2], (0,255,0), 2) cv.cvPutText(leftdraw, "%2f(m) at (%2f,%2f)" % (depth[0][2],depth[0][0],depth[0][1]), (xmatch,ymatch), font, (0,0,255)) cv.cvLine(rightdraw, depth[2], depth[2], (0,0,255), 5) highgui.cvShowImage("depthmatch - left", leftdraw) highgui.cvShowImage("depthmatch - right", rightdraw)
tx = 100 ty = 100 showoriginal = True def mousecb(event,x,y,flag,param): global tx,ty,showoriginal if event == highgui.CV_EVENT_RBUTTONDOWN: tx = x ty = y print x, y showoriginal = False elif event == highgui.CV_EVENT_LBUTTONDOWN: showoriginal = True print "Orig" highgui.cvSetMouseCallback("Blob", mousecb, 0) while True: if not fromfile: img = highgui.cvQueryFrame(cap0) cv.cvCvtColor(img,img,cv.CV_RGB2HSV) (h,s,v) = (img[ty][tx][0],img[ty][tx][1],img[ty][tx][2]) thresh = cv.cvCreateImage(cv.cvSize(IMGW,IMGH),8,1) cv.cvSetZero(thresh) # dynamic floodfill import queue q = queue.Queue(0) q.put({"x":tx,"y":ty}) thresh[ty][tx] = 255 while True:
print "Error opening capture device" sys.exit (1) # display a small howto use it print "Hot keys: \n" \ "\tESC - quit the program\n" \ "\tr - auto-initialize tracking\n" \ "\tc - delete all the points\n" \ "\tn - switch the \"night\" mode on/off\n" \ "To add/remove a feature point click it\n" # first, create the necessary windows highgui.cvNamedWindow ('LkDemo', highgui.CV_WINDOW_AUTOSIZE) # register the mouse callback highgui.cvSetMouseCallback ('LkDemo', on_mouse, None) while 1: # do forever # 1. capture the current image frame = highgui.cvQueryFrame (capture) if frame is None: # no image captured... end the processing break if image is None: # create the images we need image = cv.cvCreateImage (cv.cvGetSize (frame), 8, 3) grey = cv.cvCreateImage (cv.cvGetSize (frame), 8, 1) prev_grey = cv.cvCreateImage (cv.cvGetSize (frame), 8, 1)
print "Error opening capture device" sys.exit(1) # display a small howto use it print "Hot keys: \n" \ "\tESC - quit the program\n" \ "\tr - auto-initialize tracking\n" \ "\tc - delete all the points\n" \ "\tn - switch the \"night\" mode on/off\n" \ "To add/remove a feature point click it\n" # first, create the necessary windows highgui.cvNamedWindow('LkDemo', highgui.CV_WINDOW_AUTOSIZE) # register the mouse callback highgui.cvSetMouseCallback('LkDemo', on_mouse, None) while 1: # do forever # 1. capture the current image frame = highgui.cvQueryFrame(capture) if frame is None: # no image captured... end the processing break if image is None: # create the images we need image = cv.cvCreateImage(cv.cvGetSize(frame), 8, 3) image.origin = frame.origin grey = cv.cvCreateImage(cv.cvGetSize(frame), 8, 1)
# we can assume this is a file name, so open it capture = highgui.cvCreateFileCapture(sys.argv[1]) # check that capture device is OK if not capture: print "Error opening capture device" sys.exit(1) # display a small howto use it print "Hot keys: \n" "\tESC - quit the program\n" "\tr - auto-initialize tracking\n" "\tc - delete all the points\n" '\tn - switch the "night" mode on/off\n' "To add/remove a feature point click it\n" # first, create the necessary windows highgui.cvNamedWindow("LkDemo", highgui.CV_WINDOW_AUTOSIZE) # register the mouse callback highgui.cvSetMouseCallback("LkDemo", on_mouse, None) while 1: # do forever # 1. capture the current image frame = highgui.cvQueryFrame(capture) if frame is None: # no image captured... end the processing break if image is None: # create the images we need image = cv.cvCreateImage(cv.cvGetSize(frame), 8, 3) image.origin = frame.origin grey = cv.cvCreateImage(cv.cvGetSize(frame), 8, 1)
if not capture: print "Error opening capture device" sys.exit (1) # display a small howto use it print "Hot keys: \n" print "\tESC - quit the program\n" print "\tc - stop the tracking\n" print "\tb - switch to/from backprojection view\n" print "To initialize tracking, select the object with mouse\n" # first, create the necessary windows highgui.cvNamedWindow ('VisualJoystick', highgui.CV_WINDOW_AUTOSIZE) # register the mouse callback highgui.cvSetMouseCallback ('VisualJoystick', on_mouse, None) highgui.cvCreateTrackbar( "Vmin", "VisualJoystick", vmin, 256, set_vmin) highgui.cvCreateTrackbar( "Vmax", "VisualJoystick", vmax, 256, set_vmax) highgui.cvCreateTrackbar( "Smin", "VisualJoystick", smin, 256, set_smin) if go: init() print getBattery() while True: frame = highgui.cvQueryFrame (capture) if frame is None:
global mouse_origin global mouse_selection global mouse_select_object mouse_select_object = False global track_object track_object = 0 global track_comp global track_box track_comp = cv.CvConnectedComp() track_box = cv.CvBox2D() highgui.cvSetMouseCallback( "Camera", on_mouse, 0 ) try: # try to get the device number from the command line device = int (sys.argv [1]) # got it ! so remove it from the arguments del sys.argv [1] except (IndexError, ValueError): # no device number on the command line, assume we want the 1st device device = 0 if len (sys.argv) == 1: # no argument on the command line, try to use the camera capture = highgui.cvCreateCameraCapture (device)
dbh = DatabaseHelper() camera.init() keep_running = True def mouse_callback(event, x, y, flags, params): global keep_running if event == highgui.CV_EVENT_LBUTTONDOWN: keep_running = False wname = 'Monitor de Camara[ {0} ]'.format(options.device) highgui.cvNamedWindow(wname, 1) highgui.cvSetMouseCallback(wname, mouse_callback, ()) while keep_running: img, match = camera.get_frame(options.face) if match: dbh.insert_activity('Rostro detectado') highgui.cvShowImage(wname, img) key = highgui.cvWaitKey(10) if key > 0: break
if not capture: print "Error opening capture device" sys.exit(1) # display a small howto use it print "Hot keys: \n" print "\tESC - quit the program\n" print "\tc - stop the tracking\n" print "\tb - switch to/from backprojection view\n" print "To initialize tracking, select the object with mouse\n" # first, create the necessary windows highgui.cvNamedWindow('VisualJoystick', highgui.CV_WINDOW_AUTOSIZE) # register the mouse callback highgui.cvSetMouseCallback('VisualJoystick', on_mouse, None) highgui.cvCreateTrackbar("Vmin", "VisualJoystick", vmin, 256, set_vmin) highgui.cvCreateTrackbar("Vmax", "VisualJoystick", vmax, 256, set_vmax) highgui.cvCreateTrackbar("Smin", "VisualJoystick", smin, 256, set_smin) if go: init() print getBattery() while True: frame = highgui.cvQueryFrame(capture) if frame is None: # no image captured... end the processing
highgui.cvCreateTrackbar("Canny2", wname, 175, 250, on_trackbar2) highgui.cvCreateTrackbar("minDistance", wname, 40, 150, on_trackbar3) highgui.cvCreateTrackbar("accumThresh", wname, 55, 100, on_trackbar4) highgui.cvCreateTrackbar("minRadius", wname, 190, 500, on_trackbar5) highgui.cvCreateTrackbar("maxRadius", wname, 210, 1200, on_trackbar6) highgui.cvCreateTrackbar("SearchRadius", wname, 50, 100, on_trackbar7) pos1 = highgui.cvGetTrackbarPos("Canny1", wname) pos2 = highgui.cvGetTrackbarPos("Canny2", wname) pos3 = highgui.cvGetTrackbarPos("minDistance", wname) pos4 = highgui.cvGetTrackbarPos("accumThresh", wname) pos5 = highgui.cvGetTrackbarPos("minRadius", wname) pos6 = highgui.cvGetTrackbarPos("maxRadius", wname) pos7 = highgui.cvGetTrackbarPos("SearchRadius", wname) pos1 = int(pos2/2) highgui.cvSetTrackbarPos("Canny1", wname, pos1) on_trackbar1(pos1) #highgui.cvNamedWindow( "original",1 ); #highgui.cvNamedWindow( "log-polar", 1 ); #highgui.cvNamedWindow( "inverse log-polar", 1 ); dst = cv.cvCreateImage( cv.cvSize(256,256), 8, 3 ); src = cv.cvCloneImage(img) src2 = cv.cvCreateImage( cv.cvGetSize(src), 8, 3 ); #cvShowImage( "original", src ); highgui.cvSetMouseCallback( "original", on_mouse ); on_mouse( CV_EVENT_LBUTTONDOWN, src.width/2, src.height/2, None, None) highgui.cvWaitKey()