Ejemplo n.º 1
0
Archivo: chroma.py Proyecto: bmiro/vpc
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")    
Ejemplo n.º 2
0
def main(args):
	global capture
	global hmax, hmin
	global stats, startTime

	highgui.cvNamedWindow('Camera', highgui.CV_WINDOW_AUTOSIZE)
	highgui.cvNamedWindow('Red Hue', highgui.CV_WINDOW_AUTOSIZE)
	highgui.cvNamedWindow('Green Hue', highgui.CV_WINDOW_AUTOSIZE)
	highgui.cvNamedWindow('Value', highgui.CV_WINDOW_AUTOSIZE)
	highgui.cvNamedWindow('Red Laser', highgui.CV_WINDOW_AUTOSIZE)
	highgui.cvNamedWindow('Green Laser', highgui.CV_WINDOW_AUTOSIZE)
	highgui.cvMoveWindow('Camera', 0, 10)
	highgui.cvMoveWindow('Value', 10, 420)
	highgui.cvMoveWindow('Red Laser', 360, 10)
	highgui.cvMoveWindow('Green Laser', 360, 360)
	highgui.cvMoveWindow('Red Hue',700, 10 )
	highgui.cvMoveWindow('Green Hue',700, 420) 

	highgui.cvCreateTrackbar("Brightness Trackbar","Camera",0,255, change_brightness);
	highgui.cvCreateTrackbar("vmin Trackbar","Value",vmin,255, change_vmin);
	highgui.cvCreateTrackbar("vmax Trackbar","Value",vmax,255, change_vmax);
	highgui.cvCreateTrackbar("red hmin Trackbar","Red Hue",red_hmin,180, change_red_hmin);
	highgui.cvCreateTrackbar("red hmax Trackbar","Red Hue",red_hmax,180, change_red_hmax);
	highgui.cvCreateTrackbar("green hmin Trackbar","Green Hue",green_hmin,180, change_green_hmin);
	highgui.cvCreateTrackbar("green hmax Trackbar","Green Hue",green_hmax,180, change_green_hmax);

	print "grabbing camera"
	capture = highgui.cvCreateCameraCapture(0)
	print "found camera"
	highgui.cvSetCaptureProperty(capture,highgui.CV_CAP_PROP_FRAME_WIDTH, iwidth)
	highgui.cvSetCaptureProperty(capture,highgui.CV_CAP_PROP_FRAME_HEIGHT, iheight)

	frame = highgui.cvQueryFrame(capture)
	frameSize = cv.cvGetSize(frame)

	hsv = cv.cvCreateImage(frameSize,8,3)
	mask = cv.cvCreateImage(frameSize,8,1)
	red_hue = cv.cvCreateImage(frameSize,8,1)
	green_hue = cv.cvCreateImage(frameSize,8,1)
	saturation = cv.cvCreateImage(frameSize,8,1)
	value = cv.cvCreateImage(frameSize,8,1)
	red_laser = cv.cvCreateImage(frameSize,8,1)
	green_laser = cv.cvCreateImage(frameSize,8,1)
	turret = FuzzyController(frameSize.width,frameSize.height,True)	
	
	while 1:
		frame = highgui.cvQueryFrame(capture)

		cv.cvCvtColor(frame, hsv, cv.CV_BGR2HSV)	
		cv.cvSplit(hsv,red_hue,saturation,value,None)
		cv.cvSplit(hsv,green_hue,saturation,value,None)
	
		cv.cvInRangeS(red_hue, cv.cvScalar(red_hmin), cv.cvScalar(red_hmax), red_hue)
		cv.cvInRangeS(green_hue, cv.cvScalar(green_hmin), cv.cvScalar(green_hmax), green_hue)
		cv.cvInRangeS(value, cv.cvScalar(vmin), cv.cvScalar(vmax), value)

		cv.cvAnd(red_hue, value, red_laser)
		cv.cvAnd(green_hue, value, green_laser)

		green_cenX,green_cenY =  averageWhitePoints(green_laser)
		draw_target(frame, green_cenX, green_cenY, "GREEN")
		red_cenX, red_cenY = averageWhitePoints(red_laser)
		draw_target(frame, red_cenX, red_cenY, "RED")
		
		if(green_cenX >= 0 and green_cenY >= 0):# and move_count <= 0):
			turret.update(green_cenX,green_cenY)
		
		highgui.cvShowImage('Camera',frame)
		highgui.cvShowImage('Red Hue', red_hue)
		highgui.cvShowImage('Green Hue', green_hue)
		highgui.cvShowImage('Value',value)
		highgui.cvShowImage('Red Laser',red_laser)
		highgui.cvShowImage('Green Laser',green_laser)

		if stats:
			printRunningStats((green_cenX, green_cenY), (red_cenX, red_cenY))

		k = highgui.cvWaitKey(10)
		if k == '\x1b' or k == 'q':
			sys.exit()
		if k == 'p':
			if stats:
				printTotalStats()
				stats = False
			else:
				startTime = time()
				stats = True
Ejemplo n.º 3
0
    highgui.cvNamedWindow ("image", 1)
    highgui.cvShowImage ("image", image)

    # create the storage area
    storage = cv.cvCreateMemStorage (0)
    
    # find the contours
    nb_contours, contours = cv.cvFindContours (image,
                                               storage,
                                               cv.sizeof_CvContour,
                                               cv.CV_RETR_TREE,
                                               cv.CV_CHAIN_APPROX_SIMPLE,
                                               cv.cvPoint (0,0))

    # comment this out if you do not want approximation
    contours = cv.cvApproxPoly (contours, cv.sizeof_CvContour,
                                storage,
                                cv.CV_POLY_APPROX_DP, 3, 1)
    
    # create the window for the contours
    highgui.cvNamedWindow ("contours", 1)

    # create the trackbar, to enable the change of the displayed level
    highgui.cvCreateTrackbar ("levels+3", "contours", 3, 7, on_trackbar)

    # call one time the callback, so we will have the 1st display done
    on_trackbar (_DEFAULT_LEVEL)

    # wait a key pressed to end
    highgui.cvWaitKey (0)
Ejemplo n.º 4
0
def main(args):
	global capture
	global hmax, hmin
	highgui.cvNamedWindow('Camera', highgui.CV_WINDOW_AUTOSIZE)
	highgui.cvNamedWindow('Hue', highgui.CV_WINDOW_AUTOSIZE)
	highgui.cvNamedWindow('Satuation', highgui.CV_WINDOW_AUTOSIZE)
	highgui.cvNamedWindow('Value', highgui.CV_WINDOW_AUTOSIZE)
	highgui.cvNamedWindow('Laser', highgui.CV_WINDOW_AUTOSIZE)
	highgui.cvMoveWindow('Camera', 0, 10)
	highgui.cvMoveWindow('Hue', 0, 350)
	highgui.cvMoveWindow('Satuation', 360, 10)
	highgui.cvMoveWindow('Value', 360, 350)
	highgui.cvMoveWindow('Laser', 700, 40)

	highgui.cvCreateTrackbar("Brightness Trackbar","Camera",0,255, change_brightness);
	highgui.cvCreateTrackbar("hmin Trackbar","Hue",hmin,180, change_hmin);
	highgui.cvCreateTrackbar("hmax Trackbar","Hue",hmax,180, change_hmax);
	highgui.cvCreateTrackbar("smin Trackbar","Satuation",smin,255, change_smin);
	highgui.cvCreateTrackbar("smax Trackbar","Satuation",smax,255, change_smax);
	highgui.cvCreateTrackbar("vmin Trackbar","Value",vmin,255, change_vmin);
	highgui.cvCreateTrackbar("vmax Trackbar","Value",vmax,255, change_vmax);

	print "grabbing camera"
	capture = highgui.cvCreateCameraCapture(0)
	print "found camera"
	highgui.cvSetCaptureProperty(capture,highgui.CV_CAP_PROP_FRAME_WIDTH, 320)
	highgui.cvSetCaptureProperty(capture,highgui.CV_CAP_PROP_FRAME_HEIGHT, 240)

	frame = highgui.cvQueryFrame(capture)
	frameSize = cv.cvGetSize(frame)

	hsv = cv.cvCreateImage(frameSize,8,3)
	mask = cv.cvCreateImage(frameSize,8,1)
	hue = cv.cvCreateImage(frameSize,8,1)
	satuation = cv.cvCreateImage(frameSize,8,1)
	value = cv.cvCreateImage(frameSize,8,1)
	laser = cv.cvCreateImage(frameSize,8,1)
	turret = FuzzyController(frameSize.width,frameSize.height,True)	
	move_count = 0
	while 1:
		frame = highgui.cvQueryFrame(capture)

		cv.cvCvtColor(frame, hsv, cv.CV_BGR2HSV)	
		#cv.cvInRangeS(hsv,hsv_min,hsv_max,mask)
		cv.cvSplit(hsv,hue,satuation,value,None)
	
		cv.cvInRangeS(hue,cv.cvScalar(hmin),cv.cvScalar(hmax),hue)
		cv.cvInRangeS(satuation,cv.cvScalar(smin),cv.cvScalar(smax),satuation)
		cv.cvInRangeS(value,cv.cvScalar(vmin),cv.cvScalar(vmax),value)
		#cv.cvInRangeS(hue,0,180,hue)

        	cv.cvAnd(hue, value, laser)
        	#cv.cvAnd(laser, value, laser)
		
		cenX,cenY =  averageWhitePoints(laser)
		#print cenX,cenY
		draw_target(frame,cenX,cenY)
	
		if(cenX != 0 and cenY != 0):# and move_count <= 0):
			turret.update(cenX,cenY,False)
		"""
			turret.reset()
			move_count = 3	
			if(cenX < 100):
				turret.left(20)
			elif(cenX > 200):
				turret.right(20)
		
			if(cenY < 80):
				turret.up(40)
			elif(cenY > 170):
				print "DOWN please.."
				turret.down(40)
			print cenY
		"""
		#move_count -= 1
		#draw_target(frame,200,1)
		
		highgui.cvShowImage('Camera',frame)
		highgui.cvShowImage('Hue',hue)
		highgui.cvShowImage('Satuation',satuation)
		highgui.cvShowImage('Value',value)
		highgui.cvShowImage('Laser',laser)

		k = highgui.cvWaitKey(10)
		if k == 'q':
			sys.exit()
Ejemplo n.º 5
0
    # create window and display the original picture in it
    highgui.cvNamedWindow("image", 1)
    highgui.cvShowImage("image", image)

    # create the storage area
    storage = cv.cvCreateMemStorage(0)

    # find the contours
    nb_contours, contours = cv.cvFindContours(image, storage,
                                              cv.sizeof_CvContour,
                                              cv.CV_RETR_TREE,
                                              cv.CV_CHAIN_APPROX_SIMPLE,
                                              cv.cvPoint(0, 0))

    # comment this out if you do not want approximation
    contours = cv.cvApproxPoly(contours, cv.sizeof_CvContour, storage,
                               cv.CV_POLY_APPROX_DP, 3, 1)

    # create the window for the contours
    highgui.cvNamedWindow("contours", 1)

    # create the trackbar, to enable the change of the displayed level
    highgui.cvCreateTrackbar("levels+3", "contours", 3, 7, on_trackbar)

    # call one time the callback, so we will have the 1st display done
    on_trackbar(_DEFAULT_LEVEL)

    # wait a key pressed to end
    highgui.cvWaitKey(0)
Ejemplo n.º 6
0
    # load image and force it to be grayscale
    image03 = highgui.cvLoadImage(filename, 0)
    if not image03:
        print "Could not load image " + filename
        sys.exit(-1)

    # Create the destination images
    image02 = cv.cvCloneImage(image03)
    image04 = cv.cvCloneImage(image03)

    # Create windows.
    highgui.cvNamedWindow("Source", 1)
    highgui.cvNamedWindow("Result", 1)

    # Show the image.
    highgui.cvShowImage("Source", image03)

    # Create toolbars. HighGUI use.
    highgui.cvCreateTrackbar("Threshold", "Result", slider_pos, 255,
                             process_image)

    process_image(1)

    #Wait for a key stroke; the same function arranges events processing
    print "Press any key to exit"
    highgui.cvWaitKey(0)

    highgui.cvDestroyWindow("Source")
    highgui.cvDestroyWindow("Result")
Ejemplo n.º 7
0
def main(args):
    global capture
    global hmax, hmin
    highgui.cvNamedWindow('Camera', highgui.CV_WINDOW_AUTOSIZE)
    highgui.cvNamedWindow('Hue', highgui.CV_WINDOW_AUTOSIZE)
    highgui.cvNamedWindow('Satuation', highgui.CV_WINDOW_AUTOSIZE)
    highgui.cvNamedWindow('Value', highgui.CV_WINDOW_AUTOSIZE)
    highgui.cvNamedWindow('Laser', highgui.CV_WINDOW_AUTOSIZE)
    highgui.cvMoveWindow('Camera', 0, 10)
    highgui.cvMoveWindow('Hue', 0, 350)
    highgui.cvMoveWindow('Satuation', 360, 10)
    highgui.cvMoveWindow('Value', 360, 350)
    highgui.cvMoveWindow('Laser', 700, 40)

    highgui.cvCreateTrackbar("Brightness Trackbar", "Camera", 0, 255,
                             change_brightness)
    highgui.cvCreateTrackbar("hmin Trackbar", "Hue", hmin, 180, change_hmin)
    highgui.cvCreateTrackbar("hmax Trackbar", "Hue", hmax, 180, change_hmax)
    highgui.cvCreateTrackbar("smin Trackbar", "Satuation", smin, 255,
                             change_smin)
    highgui.cvCreateTrackbar("smax Trackbar", "Satuation", smax, 255,
                             change_smax)
    highgui.cvCreateTrackbar("vmin Trackbar", "Value", vmin, 255, change_vmin)
    highgui.cvCreateTrackbar("vmax Trackbar", "Value", vmax, 255, change_vmax)

    print "grabbing camera"
    capture = highgui.cvCreateCameraCapture(0)
    print "found camera"
    highgui.cvSetCaptureProperty(capture, highgui.CV_CAP_PROP_FRAME_WIDTH, 320)
    highgui.cvSetCaptureProperty(capture, highgui.CV_CAP_PROP_FRAME_HEIGHT,
                                 240)

    frame = highgui.cvQueryFrame(capture)
    frameSize = cv.cvGetSize(frame)

    hsv = cv.cvCreateImage(frameSize, 8, 3)
    mask = cv.cvCreateImage(frameSize, 8, 1)
    hue = cv.cvCreateImage(frameSize, 8, 1)
    satuation = cv.cvCreateImage(frameSize, 8, 1)
    value = cv.cvCreateImage(frameSize, 8, 1)
    laser = cv.cvCreateImage(frameSize, 8, 1)

    while 1:
        frame = highgui.cvQueryFrame(capture)

        cv.cvCvtColor(frame, hsv, cv.CV_BGR2HSV)
        #cv.cvInRangeS(hsv,hsv_min,hsv_max,mask)
        cv.cvSplit(hsv, hue, satuation, value, None)

        cv.cvInRangeS(hue, hmin, hmax, hue)
        cv.cvInRangeS(satuation, smin, smax, satuation)
        cv.cvInRangeS(value, vmin, vmax, value)
        #cv.cvInRangeS(hue,0,180,hue)

        cv.cvAnd(hue, value, laser)
        #cv.cvAnd(laser, value, laser)

        cenX, cenY = averageWhitePoints(laser)
        #print cenX,cenY
        draw_target(frame, cenX, cenY)
        #draw_target(frame,200,1)

        highgui.cvShowImage('Camera', frame)
        highgui.cvShowImage('Hue', hue)
        highgui.cvShowImage('Satuation', satuation)
        highgui.cvShowImage('Value', value)
        highgui.cvShowImage('Laser', laser)

        k = highgui.cvWaitKey(10)
        if k == " ":
            highgui.cvDestroyAllWindows()
            highgui.cvReleaseCapture(capture)
            sys.exit()
Ejemplo n.º 8
0
    tmp_img = cv.cvCreateImage(cv.cvGetSize(bw_im1),cv.IPL_DEPTH_32F, 1)
    cv.cvResize(realInput,tmp_img)
    cv.cvScale(tmp_img, bw_im1, 255,0)
    return bw_im1



##    return outp_image

if __name__ == '__main__':
    print "OpenCV python"
    
    highgui.cvNamedWindow ('Camera', highgui.CV_WINDOW_AUTOSIZE)
    highgui.cvNamedWindow ('Result', highgui.CV_WINDOW_AUTOSIZE)
    highgui.cvNamedWindow ('TEST', highgui.CV_WINDOW_AUTOSIZE)
    highgui.cvCreateTrackbar('Threshold', 'Result', thresh, 1000, on_trackbar)
    highgui.cvCreateTrackbar('Scale', 'Result', thresh, 10, on_scalebar)
    highgui.cvNamedWindow ('BW', highgui.CV_WINDOW_AUTOSIZE)
       # move the new window to a better place
    highgui.cvMoveWindow ('Camera', 10, 10)

    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
Ejemplo n.º 9
0
def main(args):
        global capture
        global hmax, hmin
        highgui.cvNamedWindow('Camera', highgui.CV_WINDOW_AUTOSIZE)
        highgui.cvNamedWindow('Hue', highgui.CV_WINDOW_AUTOSIZE)
        highgui.cvNamedWindow('Satuation', highgui.CV_WINDOW_AUTOSIZE)
        highgui.cvNamedWindow('Value', highgui.CV_WINDOW_AUTOSIZE)
        highgui.cvNamedWindow('Laser', highgui.CV_WINDOW_AUTOSIZE)
        highgui.cvMoveWindow('Camera', 0, 10)
        highgui.cvMoveWindow('Hue', 0, 350)
        highgui.cvMoveWindow('Satuation', 360, 10)
        highgui.cvMoveWindow('Value', 360, 350)
        highgui.cvMoveWindow('Laser', 700, 40)

        highgui.cvCreateTrackbar("Brightness Trackbar","Camera",0,255, change_brightness);
        highgui.cvCreateTrackbar("hmin Trackbar","Hue",hmin,180, change_hmin);
        highgui.cvCreateTrackbar("hmax Trackbar","Hue",hmax,180, change_hmax);
        highgui.cvCreateTrackbar("smin Trackbar","Satuation",smin,255, change_smin);
        highgui.cvCreateTrackbar("smax Trackbar","Satuation",smax,255, change_smax);
        highgui.cvCreateTrackbar("vmin Trackbar","Value",vmin,255, change_vmin);
        highgui.cvCreateTrackbar("vmax Trackbar","Value",vmax,255, change_vmax);

        print "grabbing camera"
        capture = highgui.cvCreateCameraCapture(0)
        print "found camera"
        highgui.cvSetCaptureProperty(capture,highgui.CV_CAP_PROP_FRAME_WIDTH, 320)
        highgui.cvSetCaptureProperty(capture,highgui.CV_CAP_PROP_FRAME_HEIGHT, 240)

        frame = highgui.cvQueryFrame(capture)
        frameSize = cv.cvGetSize(frame)

        hsv = cv.cvCreateImage(frameSize,8,3)
        mask = cv.cvCreateImage(frameSize,8,1)
        hue = cv.cvCreateImage(frameSize,8,1)
        satuation = cv.cvCreateImage(frameSize,8,1)
        value = cv.cvCreateImage(frameSize,8,1)
        laser = cv.cvCreateImage(frameSize,8,1)
        
        while 1:
                frame = highgui.cvQueryFrame(capture)

                cv.cvCvtColor(frame, hsv, cv.CV_BGR2HSV)        
                #cv.cvInRangeS(hsv,hsv_min,hsv_max,mask)
                cv.cvSplit(hsv,hue,satuation,value,None)
        
                cv.cvInRangeS(hue,hmin,hmax,hue)
                cv.cvInRangeS(satuation,smin,smax,satuation)
                cv.cvInRangeS(value,vmin,vmax,value)
                #cv.cvInRangeS(hue,0,180,hue)

                cv.cvAnd(hue, value, laser)
                #cv.cvAnd(laser, value, laser)
                
                cenX,cenY =  averageWhitePoints(laser)
                #print cenX,cenY
                draw_target(frame,cenX,cenY)
                #draw_target(frame,200,1)
                
                highgui.cvShowImage('Camera',frame)
                highgui.cvShowImage('Hue',hue)
                highgui.cvShowImage('Satuation',satuation)
                highgui.cvShowImage('Value',value)
                highgui.cvShowImage('Laser',laser)

                k = highgui.cvWaitKey(10)
                if k == " ":
                  highgui.cvDestroyAllWindows()
                  highgui.cvReleaseCapture (capture)
                  sys.exit()
Ejemplo n.º 10
0
        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
            break
Ejemplo n.º 11
0
def main(): # ctrl+c to end
    global h,s,v,h2,v2,s2,d,e
    highgui.cvNamedWindow("Camera 1", 1)
    highgui.cvNamedWindow("Orig", 1)
    highgui.cvCreateTrackbar("H", "Camera 1", h, 256, tb_h)
    highgui.cvCreateTrackbar("S", "Camera 1", s, 256, tb_s)
    highgui.cvCreateTrackbar("V", "Camera 1", v, 256, tb_v)
    highgui.cvCreateTrackbar("H2", "Camera 1", h2, 256, tb_h2)
    highgui.cvCreateTrackbar("S2", "Camera 1", s2, 256, tb_s2)
    highgui.cvCreateTrackbar("V2", "Camera 1", v2, 256, tb_v2)
    highgui.cvCreateTrackbar("Dilate", "Camera 1", d, 30, tb_d)
    highgui.cvCreateTrackbar("Erode", "Camera 1", e, 30, tb_e)
    
    cap = highgui.cvCreateCameraCapture(1)
    highgui.cvSetCaptureProperty(cap, highgui.CV_CAP_PROP_FRAME_WIDTH, IMGW)
    highgui.cvSetCaptureProperty(cap, highgui.CV_CAP_PROP_FRAME_HEIGHT, IMGH)
    c = 0
    t1 = tdraw = time.clock()
    t = 1
    font = cv.cvInitFont(cv.CV_FONT_HERSHEY_PLAIN, 1, 1)
    while c != 0x27:
        image = highgui.cvQueryFrame(cap)
        if not image:
            print "capture failed"
            break
            
        thresh = cv.cvCreateImage(cv.cvSize(IMGW,IMGH),8,1)
        cv.cvSetZero(thresh)
        cv.cvCvtColor(image,image,cv.CV_RGB2HSV)
        cv.cvInRangeS(image, (h,s,v,0), (h2,s2,v2,0), thresh)
        result = cv.cvCreateImage(cv.cvSize(IMGW,IMGH),8,3)
        cv.cvSetZero(result)
        
        cv.cvOr(image,image,result,thresh)
        for i in range(1,e):
            cv.cvErode(result,result)
        for i in range(1,d):
            cv.cvDilate(result,result)
            
        # floodfill objects back in, allowing threshold differences outwards
        
        t2 = time.clock()
        if t2 > tdraw+0.3:
            t = t2-t1
            tdraw=t2
        cv.cvPutText(result, "FPS: " + str(1 / (t)), (0,25), font, (255,255,255))
        t1 = t2
        highgui.cvShowImage("Orig", image)
        highgui.cvShowImage("Camera 1", result)
        c = highgui.cvWaitKey(10)
Ejemplo n.º 12
0
        highgui.cvNamedWindow('1-without background',
                              highgui.CV_WINDOW_AUTOSIZE)
        highgui.cvNamedWindow('2-amplifie', highgui.CV_WINDOW_AUTOSIZE)
        highgui.cvNamedWindow('3-lisser-Smooth', highgui.CV_WINDOW_AUTOSIZE)
        highgui.cvNamedWindow('4-lisser-And', highgui.CV_WINDOW_AUTOSIZE)

        # move the new window to a better place
        highgui.cvMoveWindow('Camera', 0, 0)
        highgui.cvMoveWindow('Binarisation', 0, 280)
        highgui.cvMoveWindow('1-without background', 320, 0)
        highgui.cvMoveWindow('2-amplifie', 320, 280)
        highgui.cvMoveWindow('3-lisser-Smooth', 640, 0)
        highgui.cvMoveWindow('4-lisser-And', 640, 280)

        #trackbar pour la modification des variables de reglages
        highgui.cvCreateTrackbar("nombre division", "Camera", get_nb_div(), 6,
                                 set_nb_div)
        highgui.cvCreateTrackbar("seuil binarisation", "Binarisation",
                                 get_seuil(), 255, set_seuil)
        highgui.cvCreateTrackbar("gain", "2-amplifie", get_gain(), 100,
                                 set_gain)
        #highgui.cvCreateTrackbar ("param lissage", "3-lisser", 3, 3, set_param_liss)
        #highgui.cvCreateTrackbar ("param 2 lissage", "3-lisser", 1, 10, set_param2_liss)

    #############################  GO WORK  ######################################
    frame = highgui.cvQueryFrame(capture)
    frame_size = cv.cvGetSize(frame)
    hauteur_image = cv.cvGetSize(frame).height
    largeur_image = cv.cvGetSize(frame).width

    print "hauteur_image:" + str(hauteur_image) + " largeur_image:" + str(
        largeur_image) + " depth:" + str(frame.depth)
Ejemplo n.º 13
0
        return;

    if event==CV_EVENT_LBUTTONDOWN:
        cvLogPolar( src, dst, cvPoint2D32f(x,y), 40, CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS );
        cvLogPolar( dst, src2, cvPoint2D32f(x,y), 40, CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS+CV_WARP_INVERSE_MAP );
        #cvShowImage( "log-polar", dst );
        #cvShowImage( "inverse log-polar", src2 );


if __name__ == "__main__":
	highgui.cvNamedWindow(wname, 1)

	img = highgui.cvLoadImage(sys.argv[1])
	#highgui.cvShowImage("Image", img)

	highgui.cvCreateTrackbar("Canny1", wname, 87, 250, on_trackbar1)
	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)
Ejemplo n.º 14
0

def cb_hue(v):
    global hue_cutoff
    hue_cutoff = v


def cb_val(v):
    global val_cutoff
    val_cutoff = v


# windows
highgui.cvNamedWindow("Input")
highgui.cvNamedWindow("Histogram - Hue")
highgui.cvCreateTrackbar("Threshold", "Histogram - Hue", hue_cutoff, int(sample_pixels), cb_hue)
highgui.cvNamedWindow("Histogram - Value")
highgui.cvCreateTrackbar("Threshold", "Histogram - Value", val_cutoff, int(sample_pixels), cb_val)
highgui.cvNamedWindow("Obstacles")

highgui.cvMoveWindow("Input", 0, 0)
highgui.cvMoveWindow("Histogram - Hue", 0, size.height + 75)
highgui.cvMoveWindow("Histogram - Value", int(h_bins * scalewidth) + 25, size.height + 75)
highgui.cvMoveWindow("Obstacles", size.width + 25, 0)


def hsv2rgb(hue):
    # convert the hue value to the corresponding rgb value

    sector_data = [[0, 2, 1], [1, 2, 0], [1, 0, 2], [2, 0, 1], [2, 1, 0], [0, 1, 2]]
    hue *= 0.1 / 3
Ejemplo n.º 15
0
    # capture the 1st frame to get some propertie on it
    frame = highgui.cvQueryFrame(capture)

    # get size of the frame
    frame_size = cv.cvGetSize(frame)

    # get the frame rate of the capture device
    fps = highgui.cvGetCaptureProperty(capture, highgui.CV_CAP_PROP_FPS)
    if fps == 0:
        # no fps getted, so set it to 30 by default
        fps = 25

    frame_count = highgui.cvGetCaptureProperty(capture,
                                               highgui.CV_CAP_PROP_FRAME_COUNT)
    frame_count = int(frame_count / 3600)
    highgui.cvCreateTrackbar('Seek', 'Camera', 0, int(frame_count),
                             lambda pos: seek_onChange(pos, capture, 'Camera'))

    # display the frames to have a visual output
    highgui.cvShowImage('Camera', frame)

    i = 0
    start = 0
    play = False
    writer = None
    while 1:
        if play:
            frame = highgui.cvQueryFrame(capture)
            if frame is None:
                # no image captured... end the processing
                break
            # display the frames to have a visual output
Ejemplo n.º 16
0
def main(args):
	global capture
	global hmax, hmin
	highgui.cvNamedWindow('Hue', highgui.CV_WINDOW_AUTOSIZE)
	highgui.cvNamedWindow('Camera', highgui.CV_WINDOW_AUTOSIZE)
	highgui.cvNamedWindow('Saturation', highgui.CV_WINDOW_AUTOSIZE)
	highgui.cvNamedWindow('Value', highgui.CV_WINDOW_AUTOSIZE)
	highgui.cvNamedWindow('Laser', highgui.CV_WINDOW_AUTOSIZE)
	highgui.cvMoveWindow('Camera', 0, 10)
	highgui.cvMoveWindow('Hue', 0, 350)
	highgui.cvMoveWindow('Saturation', 360, 10)
	highgui.cvMoveWindow('Value', 360, 350)
	highgui.cvMoveWindow('Laser', 700, 40)

	highgui.cvCreateTrackbar("Brightness Trackbar","Camera",0,255, change_brightness);
	highgui.cvCreateTrackbar("hmin Trackbar","Hue",hmin,180, change_hmin);
	highgui.cvCreateTrackbar("hmax Trackbar","Hue",hmax,180, change_hmax);
	highgui.cvCreateTrackbar("smin Trackbar","Saturation",smin,255, change_smin);
	highgui.cvCreateTrackbar("smax Trackbar","Saturation",smax,255, change_smax);
	highgui.cvCreateTrackbar("vmin Trackbar","Value",vmin,255, change_vmin);
	highgui.cvCreateTrackbar("vmax Trackbar","Value",vmax,255, change_vmax);

	print "grabbing camera"
	capture = highgui.cvCreateCameraCapture(0)
	print "found camera"
	highgui.cvSetCaptureProperty(capture,highgui.CV_CAP_PROP_FRAME_WIDTH, iwidth)
	highgui.cvSetCaptureProperty(capture,highgui.CV_CAP_PROP_FRAME_HEIGHT, iheight)

	frame = highgui.cvQueryFrame(capture)
	frameSize = cv.cvGetSize(frame)

	hsv = cv.cvCreateImage(frameSize,8,3)
	mask = cv.cvCreateImage(frameSize,8,1)
	hue = cv.cvCreateImage(frameSize,8,1)
	saturation = cv.cvCreateImage(frameSize,8,1)
	value = cv.cvCreateImage(frameSize,8,1)
	laser = cv.cvCreateImage(frameSize,8,1)
	
	while 1:
		frame = highgui.cvQueryFrame(capture)

		cv.cvCvtColor(frame, hsv, cv.CV_BGR2HSV)	
		#cv.cvInRangeS(hsv,hsv_min,hsv_max,mask)
		cv.cvSplit(hsv,hue,saturation,value,None)
	

		#print hmin, hmax
		cv.cvInRangeS(hue,cv.cvScalar(hmin),cv.cvScalar(hmax),hue)
		cv.cvInRangeS(saturation,cv.cvScalar(smin),cv.cvScalar(smax),saturation)
		cv.cvInRangeS(value,cv.cvScalar(vmin),cv.cvScalar(vmax),value)
		
		#cv.cvInRangeS(hue,cv.cvScalar(0),cv.cvScalar(180),hue)

        	cv.cvAnd(hue, value, laser)
        	#cv.cvAnd(laser, value, laser)
		
		# stupid filter
		#removeErrantPoints(laser)

		cenX,cenY =  averageWhitePoints(laser)

		px = iwidth/2 - cenX
		dis = 57.18832855 / ( px - 5.702350176) + .05753797721  

		print cenX,px,dis 
		draw_target(frame,cenX,cenY)
		#draw_target(frame,200,1)
		
		highgui.cvShowImage('Hue',hue)
		highgui.cvShowImage('Camera',frame)
		highgui.cvShowImage('Saturation',saturation)
		highgui.cvShowImage('Value',value)
		highgui.cvShowImage('Laser',laser)

		highgui.cvWaitKey(10)
Ejemplo n.º 17
0
    if len(sys.argv) > 1:
        filename = sys.argv[1]

    # load the image gived on the command line
    image = highgui.cvLoadImage(filename)

    if not image:
        print "Error loading image '%s'" % filename
        sys.exit(-1)

    # create the output image
    col_edge = cv.cvCreateImage(cv.cvSize(image.width, image.height), 8, 3)

    # convert to grayscale
    gray = cv.cvCreateImage(cv.cvSize(image.width, image.height), 8, 1)
    edge = cv.cvCreateImage(cv.cvSize(image.width, image.height), 8, 1)
    cv.cvCvtColor(image, gray, cv.CV_BGR2GRAY)

    # create the window
    highgui.cvNamedWindow(win_name, highgui.CV_WINDOW_AUTOSIZE)

    # create the trackbar
    highgui.cvCreateTrackbar(trackbar_name, win_name, 1, 100, on_trackbar)

    # show the image
    on_trackbar(0)

    # wait a key pressed to end
    highgui.cvWaitKey(0)
Ejemplo n.º 18
0
        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
            break
Ejemplo n.º 19
0
 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)
     print depth
Ejemplo n.º 20
0
    # load image and force it to be grayscale
    image03 = highgui.cvLoadImage(filename, 0)
    if not image03:
        print "Could not load image " + filename
        sys.exit(-1)

    # Create the destination images
    image02 = cv.cvCloneImage( image03 );
    image04 = cv.cvCloneImage( image03 );

    # Create windows.
    highgui.cvNamedWindow("Source", 1);
    highgui.cvNamedWindow("Result", 1);

    # Show the image.
    highgui.cvShowImage("Source", image03);

    # Create toolbars. HighGUI use.
    highgui.cvCreateTrackbar( "Threshold", "Result", slider_pos, 255, process_image );


    process_image( 1 );

    #Wait for a key stroke; the same function arranges events processing                
    print "Press any key to exit"
    highgui.cvWaitKey(0);

    highgui.cvDestroyWindow("Source");
    highgui.cvDestroyWindow("Result");

Ejemplo n.º 21
0
    if len(sys.argv)>1:
        filename = sys.argv[1]

    # load the image gived on the command line
    image = highgui.cvLoadImage (filename)

    if not image:
        print "Error loading image '%s'" % filename
        sys.exit(-1)

    # create the output image
    col_edge = cv.cvCreateImage (cv.cvSize (image.width, image.height), 8, 3)

    # convert to grayscale
    gray = cv.cvCreateImage (cv.cvSize (image.width, image.height), 8, 1)
    edge = cv.cvCreateImage (cv.cvSize (image.width, image.height), 8, 1)
    cv.cvCvtColor (image, gray, cv.CV_BGR2GRAY)

    # create the window
    highgui.cvNamedWindow (win_name, highgui.CV_WINDOW_AUTOSIZE)

    # create the trackbar
    highgui.cvCreateTrackbar (trackbar_name, win_name, 1, 100, on_trackbar)

    # show the image
    on_trackbar (0)

    # wait a key pressed to end
    highgui.cvWaitKey (0)
Ejemplo n.º 22
0
    # capture the 1st frame to get some propertie on it
    frame = highgui.cvQueryFrame (capture)

    # get size of the frame
    frame_size = cv.cvGetSize (frame)

    # get the frame rate of the capture device
    fps = highgui.cvGetCaptureProperty (capture, highgui.CV_CAP_PROP_FPS)
    if fps == 0:
        # no fps getted, so set it to 30 by default
        fps = 25

    frame_count = highgui.cvGetCaptureProperty(capture, 
                                               highgui.CV_CAP_PROP_FRAME_COUNT)
    frame_count = int(frame_count / 3600)
    highgui.cvCreateTrackbar('Seek', 'Camera', 0, int(frame_count),
                             lambda pos: seek_onChange(pos, capture, 'Camera'))

    # display the frames to have a visual output
    highgui.cvShowImage ('Camera', frame)

    i = 0
    start = 0
    play = False
    writer = None
    while 1:
        if play:
            frame = highgui.cvQueryFrame (capture)
            if frame is None:
                # no image captured... end the processing
                break
            # display the frames to have a visual output