Esempio n. 1
0
 def onIdle(self, event):
     """
     Event to grab and display a frame from the camera. (internal use).
     """
     if self.cap == None:  #Should be cvCameraCapture instance.
         #unbind the idle instance, change to click.
         highgui.cvReleaseCapture(self.cap)  #release the old instance and
         self.cap = highgui.cvCreateCameraCapture(
             self.camera)  #try new one.
         self.displayError(self.errorBitmap, (128, 128))
         raise CameraError('Unable to open camera, retrying....')
         event.Skip()
     try:
         img = highgui.cvQueryFrame(self.cap)
     except cv2.error as e:
         raise CameraError('Error when querying for frame: {0}'.format(e))
     self._error = 0  #worked successfully
     img = opencv.cvGetMat(img)
     cv.cvCvtColor(img, img, cv.CV_BGR2RGB)
     if conf.as_bool(conf.config['webcam']['cropBars']):
         #Draw cropping region
         cv.cvRectangle(img, (80, -1), (560, 480), (205.0, 0.0, 0.0, 0.0),
                        2)
     self.displayImage(img)
     event.RequestMore()
Esempio n. 2
0
def snapshot():
    cam = highgui.cvCreateCameraCapture(1)
    img = highgui.cvQueryFrame(cam)

    pilImage = opencv.adaptors.Ipl2PIL(img)

    highgui.cvReleaseCapture(cam)
    
    return pilImage
Esempio n. 3
0
def capture_webcam():
    """
    Grab a frame from the first detected webcam using OpenCV.
    """
    import opencv
    from opencv import highgui

    camera = highgui.cvCreateCameraCapture(0)
    cv_img = highgui.cvQueryFrame(camera)
    img = opencv.adaptors.Ipl2PIL(cv_img)
    highgui.cvReleaseCapture(camera)
    return img
Esempio n. 4
0
def recognize_face():
    try:
        argsnum=len(sys.argv)
        print "args:",argsnum
        #if(argsnum<5):
         #   print "usage:python pyfaces.py imgname dirname numofeigenfaces threshold "
          #  sys.exit(2)                
        #imgname=sys.argv[1]
        #dirname=sys.argv[2]
        #egfaces=int(sys.argv[3])
        #thrshld=float(sys.argv[4])

        capture=hg.cvCreateCameraCapture(0)
        hg.cvNamedWindow("Snapshot")
        i=0
        #time.sleep(1)
        myframe=0
        imgname='sample.png'
        dirname='images'
        egfaces=5
        thrshld=0.3
        #frame=0
        
        while 1:     
            frame=hg.cvQueryFrame(capture)
            #print type(frame)
            hg.cvShowImage("Snapshot",frame)
            key = hg.cvWaitKey(5)
            if key=='c' or key=='C':
                hg.cvDestroyWindow("Snapshot")
                hg.cvSaveImage(imgname,frame)
                global_frame=frame
                break   
                #print frame   

        #sys.exit(0)

        pyf=PyFaces(imgname,dirname,egfaces,thrshld,frame)
        #if pyfaces returns false then save this image into images folder
        hg.cvReleaseCapture(capture) 
        return pyf.getFileName()

    except Exception,detail:
        print detail
        print "usage:python pyfaces.py imgname dirname numofeigenfaces threshold "
Esempio n. 5
0
def do_dream():
    colour_sensed = Color20(b,PORT_3).get_color()

    print "LEGO Colour: "+colours[colour_sensed]
    im = get_image()

    dream = get_dream(im, colour_sensed)
    assert 0 <= dream < len(pbm_images)

    print "writing image %s to peggy" % pbm_images[dream]
    write_frame(pbm_lines(IMG_DIR + pbm_images[dream]))

    im.save('dream' + time.strftime('%H%M%S') + '.jpg', 'JPEG')

    print "saving photo"
    highgui.cvReleaseCapture(camera)#reset camera
    global camera
    camera = highgui.cvCreateCameraCapture(1)

    time.sleep(DISPLAY_TIME)
    write_frame()
Esempio n. 6
0
def opencvSnap(dev,size):
    """
    An example use of the "camera" taking a single picture frame using opencv's cvMat as the return method.
    """
    # First lets take a picture using opencv, and display it using opencv...
    cvWin = hg.cvNamedWindow( "Opencv Rendering and Capture", 0 )

    print("Opening device %s, with video size (%s,%s)" % (dev,size[0],size[1]))
    
    # creates the camera of the specified size and in RGB colorspace
    cam = Camera(dev, size, "RGB")
    a = cam.get_image()
    hg.cvShowImage ('Opencv Rendering and Capture', a)
    
    # close the capture stream to avoid problems later, should see the camera turn off
    hg.cvReleaseCapture(cam.capture)
    del cam
    
    # Wait for any key then clean up
    print("Press any key to continue")
    k = hg.cvWaitKey()
    hg.cvDestroyWindow("Opencv Rendering and Capture")
Esempio n. 7
0
def opencvSnap(dev, size):
    """
    An example use of the "camera" taking a single picture frame using opencv's cvMat as the return method.
    """
    # First lets take a picture using opencv, and display it using opencv...
    cvWin = hg.cvNamedWindow("Opencv Rendering and Capture", 0)

    print("Opening device %s, with video size (%s,%s)" %
          (dev, size[0], size[1]))

    # creates the camera of the specified size and in RGB colorspace
    cam = Camera(dev, size, "RGB")
    a = cam.get_image()
    hg.cvShowImage('Opencv Rendering and Capture', a)

    # close the capture stream to avoid problems later, should see the camera turn off
    hg.cvReleaseCapture(cam.capture)
    del cam

    # Wait for any key then clean up
    print("Press any key to continue")
    k = hg.cvWaitKey()
    hg.cvDestroyWindow("Opencv Rendering and Capture")
Esempio n. 8
0
 def onIdle(self, event):
     """
     Event to grab and display a frame from the camera. (internal use).
     """
     if self.cap == None: #Should be cvCameraCapture instance.
         #unbind the idle instance, change to click.
         highgui.cvReleaseCapture(self.cap)  #release the old instance and
         self.cap = highgui.cvCreateCameraCapture(self.camera) #try new one.
         self.displayError(self.errorBitmap, (128, 128))
         raise CameraError('Unable to open camera, retrying....')
         event.Skip()
     try:
         img = highgui.cvQueryFrame(self.cap)
     except cv2.error as e:
         raise CameraError('Error when querying for frame: {0}'.format(e))
     self._error = 0  #worked successfully
     img = opencv.cvGetMat(img)
     cv.cvCvtColor(img, img, cv.CV_BGR2RGB)
     if conf.as_bool(conf.config['webcam']['cropBars']):
         #Draw cropping region
         cv.cvRectangle(img, (80, -1), (560, 480), (205.0, 0.0, 0.0, 0.0), 2)
     self.displayImage(img)
     event.RequestMore()
Esempio n. 9
0
 def crear_imagen(self, nombre_imagen):
     captura = cvCreateCameraCapture(0)
     imagen = cvQueryFrame(captura)
     cvSaveImage("imagenes/%s.png" %nombre_imagen, imagen)
     cvReleaseCapture(captura)
Esempio n. 10
0
File: chroma.py Progetto: 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)
        

Esempio n. 11
0
 def _destr_cap(self):
     hg.cvReleaseCapture(self.cap)
Esempio n. 12
0
	def __del__(self):
		highgui.cvReleaseCapture(self.camera)
		print('Releasing WebCam ...')
Esempio n. 13
0
        #img = highgui.cvRetrieveFrame (capture)
        #cvGrabFrame(capture);          // capture a frame
        #img=cvRetrieveFrame(capture);  // retrieve the captured frame
        #cvWriteFrame(writer,img);      // add the frame to the file
        highgui.cvShowImage ('Camera', frame)


        # handle events
        #k = highgui.cvWaitKey ()
        #print

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                highgui.cvReleaseVideoWriter (writer)
                highgui.cvDestroyAllWindows()
                highgui.cvReleaseCapture (capture)
                pygame.quit()
                #sys.exit()
                break
        
        keyinput = pygame.key.get_pressed()
        #print "key pressed: ", keyinput
        
        if keyinput[K_SPACE]:
            #frame = highgui.cvQueryFrame (capture)
            #frame = highgui.cvGrabFrame (capture)
            img = highgui.cvQueryFrame (capture)
            img = highgui.cvRetrieveFrame (capture)
            if frame is None:
                # no image captured... end the processing
                break
Esempio n. 14
0
    def stop_capture(self):
        if self.capture:
            highgui.cvReleaseCapture(self.capture)

        self.capture = None
Esempio n. 15
0
 def __del__(self):
     highgui.cvReleaseCapture(self.camera)
     print('Releasing WebCam ...')
Esempio n. 16
0
#log# Automatic Logger file. *** THIS MUST BE THE FIRST LINE ***
#log# DO NOT CHANGE THIS LINE OR THE TWO BELOW
#log# opts = Struct({'__allownew': True, 'logfile': 'ipython-logs/opencv-camlist.py'})
#log# args = []
#log# It is safe to make manual edits below here.
#log#-----------------------------------------------------------------------
import opencv
import opencv.cv as cv
import opencv.highgui as hg
import conversionUtils
# on the olpc this takes ages!
cap = hg.cvCreateCameraCapture(0)

cap
#?cap
q = hg.cvQueryFrame(cap)
del cap
#cam still on
hg.cvReleaseCapture(2)
hg.cvReleaseCapture(cap)
#bugger
quit()
Esempio n. 17
0
 def close(self):
     """
     Close a capture device and stops writing frames to the screen.
     """
     highgui.cvReleaseCapture(self.cap)
     self.Unbind(wx.EVT_IDLE)
Esempio n. 18
0
 def stop(self):
     return hg.cvReleaseCapture(self.capture)
Esempio n. 19
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. 20
0
 def close(self):
     """
     Close a capture device and stops writing frames to the screen.
     """
     highgui.cvReleaseCapture(self.cap)
     self.Unbind(wx.EVT_IDLE)
Esempio n. 21
0
 def stop(self):
     return hg.cvReleaseCapture(self.capture)
Esempio n. 22
0
        return True


def list_cameras():
    #return [0]  # Just use this line if errors occur
    cams = []
    for i in range(3):
        try:
            capture = hg.cvCreateCameraCapture(
                i)  # Must be a better way of doing this...
            if capture is not None:
                cams.append(i)
        except Exception, e:
            pass
        finally:
            hg.cvReleaseCapture(capture)
    return cams


def init():
    """
    Work out at this point what we will use...
    """
    pass


def opencvSnap(dev, size):
    """
    An example use of the "camera" taking a single picture frame using opencv's cvMat as the return method.
    """
    # First lets take a picture using opencv, and display it using opencv...
Esempio n. 23
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. 24
0
            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)

        # we can now display the images
        highgui.cvShowImage('Camera', frame)
        highgui.cvShowImage('Histogram', histimg)

        # handle events
        k = highgui.cvWaitKey(10)

        if k == '\x1b':
            # user has press the ESC key, so exit
            break
    highgui.cvReleaseCapture(capture)
Esempio n. 25
0
    
    def query_image(self):
        return True
    
def list_cameras():
    #return [0]  # Just use this line if errors occur
    cams = []
    for i in range(3):
        try:
            capture = hg.cvCreateCameraCapture( i )  # Must be a better way of doing this...
            if capture is not None:
                cams.append(i)
        except Exception, e:
            pass
        finally:
            hg.cvReleaseCapture(capture)
    return cams
       
        
def init():
    """
    Work out at this point what we will use...
    """
    pass

def opencvSnap(dev,size):
    """
    An example use of the "camera" taking a single picture frame using opencv's cvMat as the return method.
    """
    # First lets take a picture using opencv, and display it using opencv...
    cvWin = hg.cvNamedWindow( "Opencv Rendering and Capture", 0 )
Esempio n. 26
0
def cleanup(camera):
	highgui.cvReleaseCapture(camera)
Esempio n. 27
0
  # KLUDGE : convert back to RGB for display
  im_mod=im_mod.convert('RGB')
  
  # insert modified image in stream
  pg_img = pygame.image.frombuffer(im_mod.tostring(), im_mod.size, im_mod.mode)
  screen.blit(pg_img, (0,0))
  pygame.display.flip()
  pygame.time.delay(int(1000 * 1.0/fps))
  i+=1
  print "current frame rate = %2.2f fps"%(i/(time.time()-starttime))
  
  
  
# cleaning
pygame.quit()
highgui.cvReleaseCapture(camera)




#  Webcam properties
#  #    name
#  0    CV_CAP_PROP_POS_MSEC
#  1    CV_CAP_PROP_POS_FRAMES
#  2    CV_CAP_PROP_POS_AVI_RATIO
#  3    CV_CAP_PROP_FRAME_WIDTH
#  4    CV_CAP_PROP_FRAME_HEIGHT
#  5    CV_CAP_PROP_FPS
#  6    CV_CAP_PROP_FOURCC
#  7    CV_CAP_PROP_FRAME_COUNT
#  8    CV_CAP_PROP_FORMAT