Esempio n. 1
0
def getData():
	frame = highgui.cvQueryFrame(capture)
	if frame is None:
		return None

	cv.cvSplit(frame, b_img, g_img, r_img, None)
	cv.cvInRangeS(r_img, 150, 255, r_img)
	cv.cvInRangeS(g_img, 0, 100, g_img)
	cv.cvInRangeS(b_img, 0, 100, b_img)

	cv.cvAnd(r_img, g_img, laser_img)
	cv.cvAnd(laser_img, b_img, laser_img)
	cv.cvErode(laser_img,laser_img) #,0,2)
	cv.cvDilate(laser_img,laser_img)
		
	c_count, contours = cv.cvFindContours (laser_img, 
											storage,
											cv.sizeof_CvContour,
											cv.CV_RETR_LIST,
											cv.CV_CHAIN_APPROX_NONE,
											cv.cvPoint (0,0))
	if c_count:
		return returnEllipses(contours)
	else:
		return None
Esempio n. 2
0
File: chroma.py Progetto: 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")    
Esempio n. 3
0
def threshold_image(image, n=[]):
    """Record the first 5 images to get a background, then diff current frame with the last saved frame.
    """
    if len(n) < 5:
        # n[4] will be our background
        # First capture a few images
        n.append(cv.cvCloneMat(image))
        if len(n) == 5:
            # last time here
            # could do averaging here.
            pass
        return image

    original = n[4]
    differenceImage = cv.cvCloneMat(image)
    cv.cvAbsDiff(image, original, differenceImage)
    """The threshold value determines the amount of "Change" required 
    before something will show up"""
    thresholdValue = 50  # 32
    cv.cvThreshold(differenceImage, differenceImage, thresholdValue, 255,
                   cv.CV_THRESH_BINARY)

    # Convert to one channel
    gray = cv.cvCreateImage(cv.cvGetSize(differenceImage), 8, 1)
    cv.cvCvtColor(differenceImage, gray, cv.CV_BGR2GRAY)

    # Use median filter to remove salt and pepper noise.
    cv.cvSmooth(gray, gray, cv.CV_MEDIAN, 15)

    # Dilate and the threshold image
    # It adds a border to the object.
    #cv.cvDilate(gray,gray, None, 9)

    # Add a bit of Blur to the threshold mask
    cv.cvSmooth(gray, gray, cv.CV_GAUSSIAN, 5)

    result = cv.cvCloneMat(image)
    cv.cvSetZero(result)

    cv.cvAnd(image, image, result, gray)
    return result
Esempio n. 4
0
def threshold_image(image, n=[]):
    """Record the first 5 images to get a background, then diff current frame with the last saved frame.
    """
    if len(n) < 5:
        # n[4] will be our background
        # First capture a few images
        n.append(cv.cvCloneMat(image))
        if len(n) == 5:
            # last time here 
            # could do averaging here.
            pass
        return image

    original = n[4]
    differenceImage  = cv.cvCloneMat( image )
    cv.cvAbsDiff( image, original, differenceImage )
    
    """The threshold value determines the amount of "Change" required 
    before something will show up"""
    thresholdValue = 50     # 32 
    cv.cvThreshold( differenceImage, differenceImage, thresholdValue, 255, cv.CV_THRESH_BINARY )
    
    # Convert to one channel
    gray = cv.cvCreateImage( cv.cvGetSize(differenceImage), 8, 1 )
    cv.cvCvtColor( differenceImage, gray, cv.CV_BGR2GRAY )   
    
    # Use median filter to remove salt and pepper noise.
    cv.cvSmooth(gray, gray, cv.CV_MEDIAN, 15)
    
    # Dilate and the threshold image
    # It adds a border to the object.
    #cv.cvDilate(gray,gray, None, 9)
    
    # Add a bit of Blur to the threshold mask
    cv.cvSmooth(gray, gray, cv.CV_GAUSSIAN, 5)
    
    result  = cv.cvCloneMat( image)
    cv.cvSetZero(result)
    
    cv.cvAnd(image,image, result, gray)
    return result
Esempio n. 5
0
File: chroma.py Progetto: bmiro/vpc
def startChroma(background, frameWidht, frameHeight):
    #cvNamedWindow("Original")
    cvNamedWindow("Chroma")
    
    hlsFrame = cvCreateImage(cvSize(frameWidth, frameHeight), IPL_DEPTH_8U, 3)
    transparency = 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)

        cvAnd(ThHFrame, ThSFrame, mask)
               
        cvCopy(background, frame, mask)
        
        cvShowImage("Chroma", frame)

        key = cvWaitKey(10)
        
    cvDestroyWindow("Chroma")
Esempio n. 6
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()
Esempio n. 7
0
                          cv.cvScalar(180, 256, max(vmin, vmax), 0), mask)
            cv.cvSplit(hsv, hue, None, None, None)

            if track_object < 0:
                # Calculate the histogram for the mouse_selection box
                hue_roi_rect = cv.cvGetSubRect(hue, mouse_selection)
                mask_roi_rect = cv.cvGetSubRect(mask, mouse_selection)
                cv.cvCalcHist(hue_roi_rect, obj_hist, 0, mask_roi_rect)
                min_val, max_val, min_idx, max_idx = cv.cvGetMinMaxHistValue(
                    obj_hist)

                track_window = mouse_selection
                track_object = 1

            cv.cvCalcBackProject(hue, backproject, obj_hist)
            cv.cvAnd(backproject, mask, backproject)

            #niter, track_comp, track_box =
            cv.cvCamShift(
                backproject, track_window,
                cv.cvTermCriteria(cv.CV_TERMCRIT_EPS | cv.CV_TERMCRIT_ITER, 10,
                                  1), track_comp, track_box)
            track_window = track_comp.rect

            #if backproject_mode:
            #    cvCvtColor( backproject, image, CV_GRAY2BGR )

            if not frame.origin:
                track_box.angle = -track_box.angle
            cv.cvEllipseBox(frame, track_box, cv.CV_RGB(255, 0, 0), 3,
                            cv.CV_AA, 0)
Esempio n. 8
0
def main():

    print "OpenCV version: %s (%d, %d, %d)" % (cv.CV_VERSION,
                                               cv.CV_MAJOR_VERSION,
                                               cv.CV_MINOR_VERSION,
                                               cv.CV_SUBMINOR_VERSION)

    # create windows 
    create_and_position_window('Thresholded_HSV_Image', 10, 10)
    create_and_position_window('RGB_VideoFrame', 10+cam_width, 10)

    create_and_position_window('Hue', 10, 10+cam_height)
    create_and_position_window('Saturation', 210, 10+cam_height)
    create_and_position_window('Value', 410, 10+cam_height)
    create_and_position_window('LaserPointer', 0,0)

    capture = setup_camera_capture()

    # create images for the different channels
    h_img = cv.cvCreateImage (cv.cvSize (cam_width,cam_height), 8, 1)
    s_img = cv.cvCreateImage (cv.cvSize (cam_width,cam_height), 8, 1)
    v_img = cv.cvCreateImage (cv.cvSize (cam_width,cam_height), 8, 1)
    laser_img = cv.cvCreateImage (cv.cvSize (cam_width,cam_height), 8, 1)
    cv.cvSetZero(h_img)
    cv.cvSetZero(s_img)
    cv.cvSetZero(v_img)
    cv.cvSetZero(laser_img)

    while True: 
        # 1. capture the current image
        frame = highgui.cvQueryFrame (capture)
        if frame is None:
            # no image captured... end the processing
            break

        hsv_image = cv.cvCloneImage(frame) # temporary copy of the frame
        cv.cvCvtColor(frame, hsv_image, cv.CV_BGR2HSV) # convert to HSV

        # split the video frame into color channels
        cv.cvSplit(hsv_image, h_img, s_img, v_img, None)

        # Threshold ranges of HSV components.
        cv.cvInRangeS(h_img, hmin, hmax, h_img)
        cv.cvInRangeS(s_img, smin, smax, s_img)
        cv.cvInRangeS(v_img, vmin, vmax, v_img)

        # Perform an AND on HSV components to identify the laser!
        cv.cvAnd(h_img, v_img, laser_img)
        # This actually Worked OK for me without using Saturation.
        #cv.cvAnd(laser_img, s_img,laser_img) 

        # Merge the HSV components back together.
        cv.cvMerge(h_img, s_img, v_img, None, hsv_image)

        #-----------------------------------------------------
        # NOTE: default color space in OpenCV is BGR!!
        # we can now display the images 
        highgui.cvShowImage ('Thresholded_HSV_Image', hsv_image)
        highgui.cvShowImage ('RGB_VideoFrame', frame)
        highgui.cvShowImage ('Hue', h_img)
        highgui.cvShowImage ('Saturation', s_img)
        highgui.cvShowImage ('Value', v_img)
        highgui.cvShowImage('LaserPointer', laser_img)

        # handle events
        k = highgui.cvWaitKey (10)

        if k == '\x1b' or k == 'q':
            # user has press the ESC key, so exit
            break
Esempio n. 9
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
Esempio n. 10
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()
Esempio n. 11
0
                
                # extract the min and max value of the histogram
                min_val, max_val, min_idx, max_idx = cv.cvGetMinMaxHistValue (hist)
                
                if (max_val):
                    cv.cvConvertScale( hist.bins, hist.bins, 255.0 / max_val, 0)
                else:
                    cv.cvConvertScale( hist.bins, hist.bins, 0.0, 0 )

                track_window = selection
                track_object = 1


            cv.cvCalcArrBackProject( hue, backproject, hist )
            
            cv.cvAnd( backproject, mask, backproject, 0 )
            cv.cvCamShift( backproject, track_window,
                           cv.cvTermCriteria( cv.CV_TERMCRIT_EPS | cv.CV_TERMCRIT_ITER, 10, 1 ),
                           track_comp, track_box )
            track_window = track_comp.rect
            
            if backproject_mode:
                cv.cvCvtColor( backproject, image, cv.CV_GRAY2BGR )
            if not image.origin:
                track_box.angle = -track_box.angle

            cv.cvEllipseBox(image, track_box, cv.CV_RGB(255,0,0), 3, cv.CV_AA, 0)
            
            if (track_box.size.width > 10 or track_box.size.height  > 10):

                rotate = ( (image.width/2.0) - track_box.center.x) / (image.width/2.0)
Esempio n. 12
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)
Esempio n. 13
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()
Esempio n. 14
0
        if frame is None:
            # no image captured... end the processing
            break

        ################   traitement de l'image   ################
        cv.cvCvtColor(frame, frameGray, cv.CV_BGR2GRAY)
        # niveau de gris
        cv.cvSub(frameGray, frameGrayBg, framewithoutbg)
        # soustraction du background
        cv.cvMul(framewithoutbg, framewithoutbg, framemul, get_gain())
        # amplification
        cv.cvSmooth(framemul, framelisser1, cv.CV_BLUR, param_liss[0],
                    param2_liss[0])
        # lissage
        if first == 0:  # "moyenne" sur deux image
            cv.cvAnd(framelisser1, framelisser2, framelisser)
        if first == 1:
            framelisser = cv.cvCloneImage(framelisser1)

        framelisser2 = cv.cvCloneImage(framelisser1)

        cv.cvThreshold(framelisser, frameBin, get_seuil(), float(255),
                       cv.CV_THRESH_BINARY)  # binaristaion de l image

        ################   run detection   ################
        zone_active = zoneActivePremier(zone_active, frameBin)
        if len(zone_active) == 0:
            centrePointeur = []
            info_size = []
        if len(zone_active) != 0:
            for i in range(1, nb_div_zone[0] + 1):
Esempio n. 15
0
while True:
    img = highgui.cvQueryFrame(cap)
    cv.cvZero(img_h)
    cv.cvZero(img_s)
    cv.cvZero(img_v)
    cv.cvZero(thresh_mask)
    highgui.cvShowImage("Input", img)
    # 5x5 Gaussian Blur
    cv.cvSmooth(img, img, cv.CV_GAUSSIAN, 5, 5)
    # convert to HSV
    cv.cvCvtColor(img, img, cv.CV_BGR2HSV)

    # threshold bad values
    cv.cvInRangeS(img, hsv_min, hsv_max, thresh_mask)

    cv.cvAnd(thresh_mask, mask_bw, thresh_mask)
    # Hue(0,180), Saturation(0,255), Value(0,255)
    cv.cvSplit(img, img_h, img_s, img_v, 0)

    # calculate histogram
    cv.cvCalcHist(img_h, h_hue, 0, thresh_mask)
    cv.cvCalcHist(img_s, h_sat, 0, thresh_mask)
    cv.cvCalcHist(img_v, h_val, 0, thresh_mask)

    # Don't normalize, use total mask pixels to calculate relative importance
    # cv.cvNormalizeHist(h_hue, 180)
    # cv.cvNormalizeHist(h_sat, 255)
    # cv.cvNormalizeHist(h_val, 255)
    # minv,maxv,minp,maxp = cv.cvMinMaxLoc(img_h)
    # print minv,maxv