示例#1
0
    def __init__( self, resolution ):
        self._camHW = opencv.highgui.cvCreateCameraCapture(0)
        highgui.cvSetCaptureProperty( self._camHW, opencv.highgui.CV_CAP_PROP_FRAME_WIDTH, resolution[ 'WIDTH' ] )
        highgui.cvSetCaptureProperty( self._camHW, opencv.highgui.CV_CAP_PROP_FRAME_HEIGHT, resolution[ 'HEIGHT' ] )
        #highgui.cvSetCaptureProperty( self._camHW, opencv.highgui.CV_CAP_PROP_SATURATION, 0.0 )

        self._iplFrame = None
示例#2
0
文件: __init__.py 项目: aoloe/shoebot
 def __init__(self, cam=0, width=None, height=None):
     self.path = cam
     self.video = hg.cvCreateCameraCapture(self.path)
     if width:
         hg.cvSetCaptureProperty(self.video, hg.CV_CAP_PROP_FRAME_WIDTH, width)
     if height:
         hg.cvSetCaptureProperty(self.video, hg.CV_CAP_PROP_FRAME_HEIGHT, height)
示例#3
0
 def __init__(self, cam=0, width=None, height=None):
     self.path = cam
     self.video = hg.cvCreateCameraCapture(self.path)
     if width:
         hg.cvSetCaptureProperty(self.video, hg.CV_CAP_PROP_FRAME_WIDTH, width)
     if height:
         hg.cvSetCaptureProperty(self.video, hg.CV_CAP_PROP_FRAME_HEIGHT, height)
示例#4
0
def init_cam(width=320, height=240):
    capture = highgui.cvCreateCameraCapture(0)
    highgui.cvSetCaptureProperty(capture, highgui.CV_CAP_PROP_FRAME_WIDTH,
                                 int(width))
    highgui.cvSetCaptureProperty(capture, highgui.CV_CAP_PROP_FRAME_HEIGHT,
                                 int(height))
    return capture
def setup_camera_capture(device_num=0):
    """Perform camera setup for the device number (default device = 0).
    Returns a reference to the camera Capture.

    """
    try:
        device = int(device_num)
    except (IndexError, ValueError):
        # assume we want the 1st device
        device = 0
    print 'Using Camera device %d' % device

    # Try to start capturing frames
    capture = highgui.cvCreateCameraCapture(device)

    # set the wanted image size from the camera
    highgui.cvSetCaptureProperty(
        capture,
        highgui.CV_CAP_PROP_FRAME_WIDTH,
        cam_width
    )
    highgui.cvSetCaptureProperty(
        capture,
        highgui.CV_CAP_PROP_FRAME_HEIGHT,
        cam_height
    )

    # check that capture device is OK
    if not capture:
        print "Error opening capture device"
        sys.exit(1)
    return capture
示例#6
0
def setup_camera_capture(device_num=0):
    ''' perform camera setup for the device number (default device = 0) i
        return a reference to the camera Capture
    '''
    try:
        # try to get the device number from the command line
        device = int(device_num)
    except (IndexError, ValueError):
        # no device number on the command line, assume we want the 1st device
        device = 0
    print 'Using Camera device %d'%device

    # no argument on the command line, try to use the camera
    capture = highgui.cvCreateCameraCapture (device)

    # set the wanted image size from the camera
    highgui.cvSetCaptureProperty (capture,highgui.CV_CAP_PROP_FRAME_WIDTH, cam_width)
    highgui.cvSetCaptureProperty (capture,highgui.CV_CAP_PROP_FRAME_HEIGHT, cam_height)

    # check that capture device is OK
    if not capture:
        print "Error opening capture device"
        sys.exit (1)
    
    return capture    
示例#7
0
 def seek(self, pos):
     #if pos <= self.framepos:
     #    self._destr_cap()
     #    self._init_cap()
     if pos <= self.framepos:
         hg.cvSetCaptureProperty(self.cap, hg.CV_CAP_PROP_POS_FRAMES, 0.0)
         self.framepos = -1
     return super(video_file, self).seek(pos)
示例#8
0
	def init_camera(self,cam_num=0):
		self.capture=highgui.cvCreateCameraCapture(cam_num)

		if not self.capture:
			raise IOError('Unable to open camera %d'%cam_num)

		highgui.cvSetCaptureProperty(self.capture,highgui.CV_CAP_PROP_FRAME_WIDTH,self.image_dims[0])
		highgui.cvSetCaptureProperty(self.capture,highgui.CV_CAP_PROP_FRAME_HEIGHT,self.image_dims[1])
示例#9
0
    def __init__(self, resolution):
        self._camHW = opencv.highgui.cvCreateCameraCapture(0)
        highgui.cvSetCaptureProperty(self._camHW,
                                     opencv.highgui.CV_CAP_PROP_FRAME_WIDTH,
                                     resolution['WIDTH'])
        highgui.cvSetCaptureProperty(self._camHW,
                                     opencv.highgui.CV_CAP_PROP_FRAME_HEIGHT,
                                     resolution['HEIGHT'])
        #highgui.cvSetCaptureProperty( self._camHW, opencv.highgui.CV_CAP_PROP_SATURATION, 0.0 )

        self._iplFrame = None
示例#10
0
	def start_capture(self, device):

#		video_dimensions = [176, 144]
		video_dimensions = [320, 240]

                if not self.capture:

			self.capture = highgui.cvCreateCameraCapture (device)
			
			highgui.cvSetCaptureProperty(self.capture, highgui.CV_CAP_PROP_FRAME_WIDTH, video_dimensions[0])
			highgui.cvSetCaptureProperty(self.capture, highgui.CV_CAP_PROP_FRAME_HEIGHT, video_dimensions[1])
示例#11
0
def seek_onChange(pos, capture, windowName):
    '''Callback for the seek trackbar'''
    print 'Seeking to frame: %d' % pos

    # Set the pointer to frame pos and grab the frame
    highgui.cvSetCaptureProperty(capture, highgui.CV_CAP_PROP_POS_FRAMES, 
                                 pos*3600 - 1)
    frame = highgui.cvQueryFrame(capture)

    # Display the frame on the window
    highgui.cvShowImage(windowName, frame)
示例#12
0
文件: camera.py 项目: Foued70/pycam
    def __init__(self, device, size, mode, imageType='opencv'):
        self.imageType = imageType
        self.size = self.width, self.height = size
        self.device = device
  
        # todo: would be nice if this didn't make a whole lot of noise about firewire...
        self.capture = hg.cvCreateCameraCapture(self.device)

        # set the wanted image size from the camera
        hg.cvSetCaptureProperty (self.capture, hg.CV_CAP_PROP_FRAME_WIDTH, self.width)
        hg.cvSetCaptureProperty (self.capture, hg.CV_CAP_PROP_FRAME_HEIGHT, self.height)
示例#13
0
def seek_onChange(pos, capture, windowName):
    '''Callback for the seek trackbar'''
    print 'Seeking to frame: %d' % pos

    # Set the pointer to frame pos and grab the frame
    highgui.cvSetCaptureProperty(capture, highgui.CV_CAP_PROP_POS_FRAMES,
                                 pos * 3600 - 1)
    frame = highgui.cvQueryFrame(capture)

    # Display the frame on the window
    highgui.cvShowImage(windowName, frame)
示例#14
0
    def __init__(self, path, start=0, stop=None):
        self.path = path
        self.video = hg.cvCreateFileCapture(self.path)

        # these functions don't seem to work at present on my linux system

        # self.fps = hg.cvGetCaptureProperty(self.video, hg.CV_CAP_PROP_FPS)
        # self.n_of_frames = hg.cvGetCaptureProperty(self.video, hg.CV_CAP_PROP_FRAME_COUNT)
        # self.duration = self.n_of_frames/self.fps
        # self.width = hg.cvGetCaptureProperty(self.video, hg.CV_CAP_PROP_FRAME_WIDTH)
        # self.height = hg.cvGetCaptureProperty(self.video, hg.CV_CAP_PROP_FRAME_HEIGHT)
        hg.cvSetCaptureProperty(self.video, hg.CV_CAP_PROP_POS_FRAMES, start)
示例#15
0
文件: __init__.py 项目: aoloe/shoebot
    def __init__(self, path, start=0, stop=None):
        self.path = path
        self.video = hg.cvCreateFileCapture(self.path)

        # these functions don't seem to work at present on my linux system
        
        #self.fps = hg.cvGetCaptureProperty(self.video, hg.CV_CAP_PROP_FPS)
        #self.n_of_frames = hg.cvGetCaptureProperty(self.video, hg.CV_CAP_PROP_FRAME_COUNT)
        #self.duration = self.n_of_frames/self.fps
        #self.width = hg.cvGetCaptureProperty(self.video, hg.CV_CAP_PROP_FRAME_WIDTH)
        #self.height = hg.cvGetCaptureProperty(self.video, hg.CV_CAP_PROP_FRAME_HEIGHT)
        hg.cvSetCaptureProperty(self.video, hg.CV_CAP_PROP_POS_FRAMES, start)
示例#16
0
    def __init__(self, src="", time=None, flipped=False, thresh=128, thmode=0):

        self.src = src
        self.time = time
        self.bthresh = thresh
        self.bthreshmode = thmode
        if self.time:
            hg.cvSetCaptureProperty(self.src, hg.CV_CAP_PROP_POS_FRAMES, self.time)
        self.iplimage = hg.cvQueryFrame(self.src)
        if flipped:
            opencv.cvFlip(self.iplimage, None, 1)
        self.width = self.iplimage.width
        self.height = self.iplimage.height
示例#17
0
    def __init__(self, cam=0, width=None, height=None):
        self.path = cam
        self.video = hg.cvCreateCameraCapture(self.path)
        if width:
            hg.cvSetCaptureProperty(self.video, hg.CV_CAP_PROP_FRAME_WIDTH, width)
        if height:
            hg.cvSetCaptureProperty(self.video, hg.CV_CAP_PROP_FRAME_HEIGHT, height)

        def release_camera(camera=self.video):
            print(camera)  # this for debugging, do not leave it!!!
            print(dir(camera))  # same as above
            opencv.cvReleaseCapture(camera)
        _ctx.drawing_closed = release_camera
示例#18
0
文件: __init__.py 项目: aoloe/shoebot
 def __init__(self, cam=0, width=None, height=None):
     self.path = cam
     self.video = hg.cvCreateCameraCapture(self.path)
     if width:
         hg.cvSetCaptureProperty(self.video, hg.CV_CAP_PROP_FRAME_WIDTH, width)
     if height:
         hg.cvSetCaptureProperty(self.video, hg.CV_CAP_PROP_FRAME_HEIGHT, height)
           
     def release_camera(camera=self.video):
         print camera # this for debugging, do not leave it!!!     
         print dir(camera) #same as above 
         opencv.cvReleaseCapture(camera)
     _ctx.drawing_closed = release_camera                
示例#19
0
文件: __init__.py 项目: aoloe/shoebot
    def __init__(self, src="", time=None, flipped=False, thresh=128, thmode=0):

        self.src = src
        self.time = time
        self.bthresh = thresh
        self.bthreshmode = thmode
        if self.time:
            hg.cvSetCaptureProperty(self.src, hg.CV_CAP_PROP_POS_FRAMES, self.time)    
        self.iplimage = hg.cvQueryFrame(self.src)
        if flipped:
            opencv.cvFlip (self.iplimage, None, 1)    
        self.width = self.iplimage.width
        self.height = self.iplimage.height
示例#20
0
    def __init__(self, device, size, mode, imageType='opencv'):
        self.imageType = imageType
        self.size = self.width, self.height = size
        self.device = device

        # todo: would be nice if this didn't make a whole lot of noise about firewire...
        self.capture = hg.cvCreateCameraCapture(self.device)

        # set the wanted image size from the camera
        hg.cvSetCaptureProperty(self.capture, hg.CV_CAP_PROP_FRAME_WIDTH,
                                self.width)
        hg.cvSetCaptureProperty(self.capture, hg.CV_CAP_PROP_FRAME_HEIGHT,
                                self.height)
示例#21
0
    def __init__(self, src="", time=None):

        self.src = src
        self.time = time
        if self.time:
            hg.cvSetCaptureProperty(self.src, hg.CV_CAP_PROP_POS_FRAMES, self.time)
        self.iplimage = hg.cvQueryFrame(self.src)
        self.width = self.iplimage.width
        self.height = self.iplimage.height
        self.image = opencv.cvCreateImage(opencv.cvGetSize(self.iplimage), 8, 4)
        opencv.cvCvtColor(self.iplimage, self.image, opencv.CV_BGR2BGRA)
        self.buffer = numpy.fromstring(self.image.imageData, dtype=numpy.uint32).astype(numpy.uint32)
        self.buffer.shape = (self.image.width, self.image.height)
        self.time = hg.cvGetCaptureProperty(self.src, hg.CV_CAP_PROP_POS_MSEC)
示例#22
0
文件: __init__.py 项目: aoloe/shoebot
    def __init__(self, src="", time=None):

        self.src = src
        self.time = time
        if self.time:
            hg.cvSetCaptureProperty(self.src, hg.CV_CAP_PROP_POS_FRAMES, self.time)    
        self.iplimage = hg.cvQueryFrame(self.src)
        self.width = self.iplimage.width
        self.height = self.iplimage.height
        self.image = opencv.cvCreateImage(opencv.cvGetSize(self.iplimage),8, 4)
        opencv.cvCvtColor(self.iplimage,self.image,opencv.CV_BGR2BGRA)
        self.buffer = numpy.fromstring(self.image.imageData, dtype=numpy.uint32).astype(numpy.uint32)
        self.buffer.shape = (self.image.width, self.image.height)
        self.time = hg.cvGetCaptureProperty(self.src, hg.CV_CAP_PROP_POS_MSEC)
示例#23
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)
示例#24
0
    def start_capture(self, device):

        #		video_dimensions = [176, 144]
        video_dimensions = [320, 240]

        if not self.capture:

            self.capture = highgui.cvCreateCameraCapture(device)

            highgui.cvSetCaptureProperty(self.capture,
                                         highgui.CV_CAP_PROP_FRAME_WIDTH,
                                         video_dimensions[0])
            highgui.cvSetCaptureProperty(self.capture,
                                         highgui.CV_CAP_PROP_FRAME_HEIGHT,
                                         video_dimensions[1])
示例#25
0
文件: head.py 项目: haldean/headtrack
    def __init__(self):
        """Initialize the camera and the pygame subsystem."""
        # Initialize the camera and set the dimensions. I use a small
        # frame size because speed is more important than accuracy.
        self.camera = cv.highgui.cvCreateCameraCapture(0)
        highgui.cvSetCaptureProperty(self.camera, cv.highgui.CV_CAP_PROP_FRAME_WIDTH, 160)
        highgui.cvSetCaptureProperty(self.camera, cv.highgui.CV_CAP_PROP_FRAME_HEIGHT, 120)

        self.blur_factor = 0
        self.diff_threshold = 40
        self.update_threshold = 1500
        self.mean_period = 6
        self.last_image = None
        self.last_centers = collections.deque()
        self.scale_mean = 0.3

        self.last_mean = None
        self.this_mean = None
        self.diff_mean = None
示例#26
0
文件: head.py 项目: haldean/headtrack
    def __init__(self):
        """Initialize the camera and the pygame subsystem."""
        # Initialize the camera and set the dimensions. I use a small
        # frame size because speed is more important than accuracy.
        self.camera = cv.highgui.cvCreateCameraCapture(0)
        highgui.cvSetCaptureProperty(self.camera,
                                     cv.highgui.CV_CAP_PROP_FRAME_WIDTH, 160)
        highgui.cvSetCaptureProperty(self.camera,
                                     cv.highgui.CV_CAP_PROP_FRAME_HEIGHT, 120)

        self.blur_factor = 0
        self.diff_threshold = 40
        self.update_threshold = 1500
        self.mean_period = 6
        self.last_image = None
        self.last_centers = collections.deque()
        self.scale_mean = 0.3

        self.last_mean = None
        self.this_mean = None
        self.diff_mean = None
示例#27
0
    def _init_camera(self, cam_num):
        """Initializes the camera associated with the given camera number"""

        # Create the OpenCV camera capture object if one has not been created already
        if cam_num not in self._captures:
            self._captures[cam_num] = highgui.cvCreateCameraCapture(cam_num)
        self._capture = self._captures[cam_num]

        # Make sure the camera object was created
        if not self._capture:
            raise AetherCameraError("Unable to open camera %d" % cam_num)

            # cvCreateCameraCapture(id) takes ownership of the camera pointer
            # cvSetCaptureProperty won't work unless we disown it before setting
        self._capture.disown()

        # Set the capture dimensions
        highgui.cvSetCaptureProperty(self._capture, highgui.CV_CAP_PROP_FRAME_WIDTH, self.capture_dims[0])
        highgui.cvSetCaptureProperty(self._capture, highgui.CV_CAP_PROP_FRAME_HEIGHT, self.capture_dims[1])

        # Take ownership again
        self._capture.acquire()

        # Read the capture dims and see if they were set to what we specified
        read_dims = (
            int(highgui.cvGetCaptureProperty(self._capture, highgui.CV_CAP_PROP_FRAME_WIDTH)),
            int(highgui.cvGetCaptureProperty(self._capture, highgui.CV_CAP_PROP_FRAME_HEIGHT)),
        )

        # Set the scale flag depending on the results of setting the capture dimensions
        # If we are reading frames in the correct dimensions, we don't need to scale
        if self.capture_dims == read_dims:
            self.scale = False
        else:
            print "Tried setting capture resolution:", self.capture_dims, ", got:", read_dims
            self.scale = True
示例#28
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)
    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)

        # set the wanted image size from the camera
        highgui.cvSetCaptureProperty (capture,
                                      highgui.CV_CAP_PROP_FRAME_WIDTH, 320)
        highgui.cvSetCaptureProperty (capture,
                                      highgui.CV_CAP_PROP_FRAME_HEIGHT,240)
    else:
        # we have an argument on the command line,
        # 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)
        
    # create an image to put in the histogram
    histimg = cv.cvCreateImage (cv.cvSize (320,240), 8, 3)
示例#30
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 = highgui.CV_CAP_ANY

    if len(sys.argv) == 1:
        # no argument on the command line, try to use the camera
        capture = highgui.cvCreateCameraCapture(device)

        # set the wanted image size from the camera
        highgui.cvSetCaptureProperty(capture, highgui.CV_CAP_PROP_FRAME_WIDTH,
                                     320)
        highgui.cvSetCaptureProperty(capture, highgui.CV_CAP_PROP_FRAME_HEIGHT,
                                     240)

    # capture the 1st frame to get some propertie on it
    frame = highgui.cvQueryFrame(capture)

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

    # create some images useful later
    my_grayscale = cv.cvCreateImage(frame_size, 8, 1)
    mask = cv.cvCreateImage(frame_size, 8, 1)
    cv.cvSet(mask, 1)

    blob_overlay = False
示例#31
0
def change_brightness(p):
    global capture
    highgui.cvSetCaptureProperty(capture, highgui.CV_CAP_PROP_BRIGHTNESS, p)
    print "change brightness", p
示例#32
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()
示例#33
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)

        # set the wanted image size from the camera
        highgui.cvSetCaptureProperty(capture, highgui.CV_CAP_PROP_FRAME_WIDTH,
                                     1600)
        highgui.cvSetCaptureProperty(capture, highgui.CV_CAP_PROP_FRAME_HEIGHT,
                                     1200)
    else:
        # we have an argument on the command line,
        # 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)

    # create an image to put in the histogram
    histimg = cv.cvCreateImage(cv.cvSize(320, 240), 8, 3)
示例#34
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()
示例#35
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()
示例#36
0
 def setResolution(self, x,y):
     x = float(x)
     y = float(y)
     self.resolution = (x, y)
     highgui.cvSetCaptureProperty(self.camera, highgui.CV_CAP_PROP_FRAME_WIDTH, x)
     highgui.cvSetCaptureProperty(self.camera, highgui.CV_CAP_PROP_FRAME_HEIGHT, y)
示例#37
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)

        # set the wanted image size from the camera
        highgui.cvSetCaptureProperty (capture,
                                      highgui.CV_CAP_PROP_FRAME_WIDTH, 1600)
        highgui.cvSetCaptureProperty (capture,
                                      highgui.CV_CAP_PROP_FRAME_HEIGHT, 1200)
    else:
        # we have an argument on the command line,
        # 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)
        
    # create an image to put in the histogram
    histimg = cv.cvCreateImage (cv.cvSize (320,240), 8, 3)
示例#38
0
文件: chroma.py 项目: bmiro/vpc
    
    if len(argv) > 2:
        writeVideo = True
        outputVideoPath = argv[1]
    else:
        writeVideo = False

    frameWidth = 640
    frameHeight = 480

    fps = 15.0

    if writeVideo:
        writer = cvCreateVideoWriter(argv[1], CV_FOURCC('M','J','P','G'), fps, cvSize(640,480))
    
    cvSetCaptureProperty(CAM, CV_CAP_PROP_FRAME_WIDTH, frameWidth)
    cvSetCaptureProperty(CAM, CV_CAP_PROP_FRAME_HEIGHT, frameHeight)
    cvSetCaptureProperty(CAM, CV_CAP_PROP_FPS, fps)
    
    getFilter(frameWidth, frameHeight)

    background = getBackground(frameWidth, frameHeight)

    startChroma(background, frameWidth, frameHeight)

    cvReleaseCapture(CAM)

    if writeVideo:
        cvReleaseVideoWriter(writer)
        
示例#39
0

if len(sys.argv) >= 2:
    imgorig = highgui.cvLoadImage(sys.argv[1])
    img = cv.cvCloneImage(imgorig)
    cv.cvCvtColor(img,img,cv.CV_RGB2HSV)
    size = cv.cvGetSize(img)
    IMGW = size.width
    IMGH = size.height
    fromfile = True
else:
    fromfile = False
    IMGW = 640
    IMGH = 480
    cap0 = highgui.cvCreateCameraCapture(0)
    highgui.cvSetCaptureProperty(cap0, highgui.CV_CAP_PROP_FRAME_WIDTH, IMGW)
    highgui.cvSetCaptureProperty(cap0, highgui.CV_CAP_PROP_FRAME_HEIGHT, IMGH)

joined = cv.cvCreateImage(cv.cvSize(IMGW,IMGH), 8, 3)

highgui.cvNamedWindow("Blob")

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
示例#40
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
示例#41
0
                
                """
                sys.exit(1)
            elif sys.argv[i] == "-s" or sys.argv[i] == "--size":
                capture = init_cam(sys.argv[i + 1], sys.argv[i + 2])
                i = i + 2
            elif sys.argv[i] == "-f" or sys.argv[i] == "--file":
                capture = highgui.cvCreateFileCapture(str(sys.argv[i + 1]))
                i = i + 1
            elif sys.argv[i] == "--noGUI":
                GUI = 0
                capture = init_cam()
                i = i + 1
            elif sys.argv[i] == "--fps":
                capture = init_cam()
                highgui.cvSetCaptureProperty(capture, highgui.CV_CAP_PROP_FPS,
                                             int(sys.argv[i + 1]))
                i = i + 1
    # check that capture device is OK
    if not capture:
        print "Error opening capture device"
        sys.exit(1)

    # Load config
    frameGrayBg = highgui.cvLoadImage("background.bmp",
                                      highgui.CV_LOAD_IMAGE_GRAYSCALE)
    logfile = open('config', 'r')
    nb_div_zone[0] = int(logfile.readline())
    seuil_binary[0] = int(logfile.readline())
    gain[0] = int(logfile.readline())
    param_liss[0] = int(logfile.readline())
    param2_liss[0] = int(logfile.readline())
示例#42
0
def change_brightness(p):
	global capture
	highgui.cvSetCaptureProperty(capture,highgui.CV_CAP_PROP_BRIGHTNESS, p)
	print "change brightness",p;