コード例 #1
0
ファイル: lrf.py プロジェクト: Mnemonic7/lrf
def init_capture_device(device=-1):
    print "init capture device"
    capture = cv.CreateCameraCapture(device)

    # check that capture device is OK
    if not capture:
        print "Error opening capture device"
        sys.exit(1)

    #call specific camera initialization
    camera_init(capture)

    #Get inital image to set parameters
    image = cv.QueryFrame(capture)  #inital image

    CAMERA_WIDTH = cv.GetSize(image)[0]
    #print CAMERA_WIDTH
    CAMERA_HEIGHT = cv.GetSize(image)[1]
    #print CAMERA_HEIGHT

    #load calibration
    intrinsics = cv.Load(INTRINSICS_FILE)
    distortion = cv.Load(DISTORTION_FILE)
    mapx = cv.CreateImage(cv.GetSize(image), cv.IPL_DEPTH_32F, 1)
    mapy = cv.CreateImage(cv.GetSize(image), cv.IPL_DEPTH_32F, 1)
    cv.InitUndistortMap(intrinsics, distortion, mapx, mapy)

    return capture, mapx, mapy
コード例 #2
0
 def __init__(self, queue, webcam):
     super(WebcamImageProvider, self).__init__(queue)
     self.camera = cv.CreateCameraCapture(webcam)
     img = cv.QueryFrame(self.camera)
     if img is None:
         raise queue.Empty
     self.running = True
コード例 #3
0
    def __init__(self):
        os.system('sudo modprobe bcm2835-v4l2')  # Use pi camera as usb device
        self.camera = cv.CreateCameraCapture(0)  # Set up camera
        # Load cascade data
        self.cascade = cv.Load(
            '/usr/share/opencv/haarcascades/haarcascade_frontalface_default.xml'
        )

        self.cam_pan = 90  # Initial pan angle
        self.cam_tilt = 90  # Initial tilt angle

        pan(self.cam_pan - 90)  # Pan to initial position
        tilt(self.cam_tilt - 90)  # Tilt to initial position

        self.min_size = (15, 15)  # Minimum window size
        self.image_scale = 5  # Image shrink scale
        # The factor by which the search window is scaled between the
        # subsequent scans
        self.haar_scale = 1.2
        self.min_neighbors = 2  # Minimum number of neighbor rectangles that makes up an object
        self.haar_flags = cv.CV_HAAR_DO_CANNY_PRUNING  # Mode of operation

        if self.camera:
            self.frame_copy = None

        # Camera warm up
        time.sleep(2)
コード例 #4
0
def InitCamera(port=0):
    """ Initialisation de la webcam """
    global CAMERA, CASCADE, DEFAULT_DEVICE_WIDTH, DEFAULT_DEVICE_HEIGHT
    try:
        if hasattr(cv, "CreateCameraCapture"):
            CAMERA = cv.CreateCameraCapture(port)
            frame = cv.QueryFrame(CAMERA)
            if frame == None:
                return False
            DEFAULT_DEVICE_WIDTH = frame.width
            DEFAULT_DEVICE_HEIGHT = frame.height
            CASCADE = cv.Load(
                Chemins.GetStaticPath(
                    "Divers/haarcascade_frontalface_alt2.xml"))

        else:
            CAMERA = cv.VideoCapture(port)
            ret, frame = CAMERA.read()
            if not ret:
                return False
            DEFAULT_DEVICE_HEIGHT, DEFAULT_DEVICE_WIDTH = frame.shape[:2]
            CASCADE = cv.CascadeClassifier(
                Chemins.GetStaticPath(
                    "Divers/haarcascade_frontalface_alt2.xml"))

        return True
    except Exception as err:
        print("Connexion camera impossible :", err)
        return False
コード例 #5
0
    def setUpOpenCV(self):

        # Setup OpenCV Window
        cv.NamedWindow("Camera", 1)
        self.capture = cv.CreateCameraCapture(0)

        # Width
        cv.SetCaptureProperty(self.capture, cv.CV_CAP_PROP_FRAME_WIDTH, 640)

        # Height
        cv.SetCaptureProperty(self.capture, cv.CV_CAP_PROP_FRAME_HEIGHT, 480)
コード例 #6
0
ファイル: scanReadQr.py プロジェクト: bradllj/soulScroll
    def __init__(self):
        cv.NamedWindow("w1", cv.CV_WINDOW_NORMAL)

#        self.capture = cv.CaptureFromCAM(camera_index) #for some reason, this doesn't work
        self.capture = cv.CreateCameraCapture(-1)
#        cv.SetCaptureProperty(self.capture, cv.CV_CAP_PROP_FRAME_WIDTH, 1280)
#        cv.SetCaptureProperty(self.capture, cv.CV_CAP_PROP_FRAME_HEIGHT, 1024)
        #self.capture = cv2.VideoCapture(-1)
        #self.capture.set(cv.CV_CAP_PROP_FRAME_WIDTH, 1280)
        #self.capture.set(cv.CV_CAP_PROP_FRAME_HEIGHT, 1024)
        self.vid_contour_selection()
コード例 #7
0
def main():

    # captured image size, change to whatever you want
    width = 320
    height = 240

    capture = cv.CreateCameraCapture(0)

    # Over-write default captured image size
    cv.SetCaptureProperty(capture,cv.CV_CAP_PROP_FRAME_WIDTH,width)
    cv.SetCaptureProperty(capture,cv.CV_CAP_PROP_FRAME_HEIGHT,height)

    cv.NamedWindow( "output", 1 )
    cv.NamedWindow( "processed", 1 )

    while True:

        frame = cv.QueryFrame(capture)
        cv.Smooth(frame, frame, cv.CV_BLUR, 3)

        imgColorProcessed = ColorProcess(frame)
        mat = cv.GetMat(imgColorProcessed)

        # Calculating the moments
        moments = cv.Moments(mat, 0)
        area = cv.GetCentralMoment(moments, 0, 0)
        moment10 = cv.GetSpatialMoment(moments, 1, 0)
        moment01 = cv.GetSpatialMoment(moments, 0,1)

        # Finding a big enough blob
        if(area > 60000):

            # Calculating the center postition of the blob
            posX = int(moment10 / area)
            posY = int(moment01 / area)

            # check slave status and send coordinates
            state = readData()
            if state == 1:
                sendData(posX)
                sendData(posY)
                print 'x: ' + str(posX) + ' y: ' + str(posY)

		# update video windows
        cv.ShowImage("processed", imgColorProcessed)
        cv.ShowImage("output", frame)

        if cv.WaitKey(10) >= 0:
            break

    return;
コード例 #8
0
def InitCamera(port=0):
    """ Initialisation de la webcam """
    global CAMERA, CASCADE, DEFAULT_DEVICE_WIDTH, DEFAULT_DEVICE_HEIGHT
    try :
        CAMERA = cv.CreateCameraCapture(port)
        frame = cv.QueryFrame(CAMERA)
        if frame == None :
            return False
        DEFAULT_DEVICE_WIDTH = frame.width
        DEFAULT_DEVICE_HEIGHT = frame.height
        CASCADE = cv.Load(Chemins.GetStaticPath("Divers/haarcascade_frontalface_alt2.xml"))
        return True
    except Exception, err :
        print err
        return False
コード例 #9
0
ファイル: faceModule.py プロジェクト: arasharchor/deepmodel
    def retrieveCam(self):
        if self.capture:
            frame_copy = None
            frame = cv.QueryFrame(self.capture)
            if not frame:
                return 0
            if not frame_copy:
                frame_copy = cv.CreateImage((frame.width, frame.height),
                                            cv.IPL_DEPTH_8U, frame.nChannels)
            if frame.origin == cv.IPL_ORIGIN_TL:
                cv.Copy(frame, frame_copy)
            else:
                cv.Flip(frame, frame_copy, 0)
            face_set, img_rectangle = self.detect_and_draw(frame_copy)
            return face_set, img_rectangle
        else:
            return [0, 0]

        self.capture = cv.CreateCameraCapture(2)
        return self.capture
コード例 #10
0
ファイル: getface.py プロジェクト: tihancock/pareidolia
    def __init__(self):
        self.capture = cv.CreateCameraCapture(-1)
        self.cascade = cv.Load('res/haarcascade_frontalface_default.xml')
        self.num_cloud_faces = 0

        date = datetime.datetime.now().strftime("%Y_%m_%d")

        self.output_folder = "output/" + date

        if os.path.exists(self.output_folder):
            existing_faces = glob.glob(self.output_folder + "/*.jpg")
            if len(existing_faces) > 0:
                print existing_faces
                im_nums = [
                    int(f.rstrip(".jpg").split("_")[-1])
                    for f in existing_faces
                ]
                print im_nums
                self.num_cloud_faces = max(im_nums) + 1
        else:
            os.makedirs(self.output_folder)
コード例 #11
0
    def __init__(self, without_robot=True, next_face=None):
        self.without_robot = without_robot

        self.capture = cv.CreateCameraCapture(0)
        cv.NamedWindow("cube_capture.py", 1)
        frame = cv.QueryFrame(self.capture)
        if not frame:
            raise IOError, "Couldn't find camera."
        self.W, self.H = cv.GetSize(frame)
        self.W = self.W / SRATE
        self.H = self.H / SRATE
        self.img = cv.CreateImage((self.W, self.H), 8, 3)
        self.hsv = cv.CreateImage((self.W, self.H), 8, 3)
        if self.W >= self.H:
            self.one_side = self.H / 9 * 2.  # the length of one side of the sqare of one sticker
        else:
            self.one_side = self.W / 9 * 2.
        self.left_top = ((self.W - 9 / 2 * self.one_side) / 2 +
                         self.one_side / 4,
                         (self.H - 9 / 2 * self.one_side) / 2 +
                         self.one_side / 4)

        self.colors_list = [None] * 6
        self.fnum_list = [[[None, None, None], [None, None, None],
                           [None, None, None]],
                          [[None, None, None], [None, None, None],
                           [None, None, None]],
                          [[None, None, None], [None, None, None],
                           [None, None, None]],
                          [[None, None, None], [None, None, None],
                           [None, None, None]],
                          [[None, None, None], [None, None, None],
                           [None, None, None]],
                          [[None, None, None], [None, None, None],
                           [None, None, None]]]
        self.facenum = 0
        self.colors = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]

        self.solver = next_face
        self.counter = 0
コード例 #12
0
    def _run_camera(self, camera_position):
        cascade = cv.Load("haarcascades/haarcascade_frontalface_alt2.xml")
        capture = cv.CreateCameraCapture(self.camera_number[camera_position])
        if self.show_main_view[camera_position]:
            cv.NamedWindow("result" + str(camera_position), 1)
        if capture:
            frame_copy = None
            #i=0
            prev_t, now_t = time.time(), 0
            while self.should_camera_be_able_to_run:
                frame = cv.QueryFrame(capture)
                if self.flip_image_verticaly[camera_position]:
                    cv.Flip(frame, frame)
                if not frame:
                    print "not frame"
                else:
                    now_t = time.time()
                    fps = 1 / (now_t - prev_t)
                    prev_t = now_t
                    print fps
                    self.detect_and_draw(frame, cascade, camera_position)
                    #cv.WaitKey(1)
                    #continue
                #if self.show_main_view[camera_position]: cv.ShowImage("result"+str(camera_position), frame)
                #if not frame_copy:
                #    frame_copy = cv.CreateImage((frame.width,frame.height),cv.IPL_DEPTH_8U, frame.nChannels)
                #if frame.origin == cv.IPL_ORIGIN_TL:
                #    cv.Copy(frame, frame_copy)
                #else:
                #    cv.Flip(frame, frame_copy, 0)
                #if cascade:
            #self.detect_and_draw(frame, cascade,  camera_position)
        #else:
        #image = cv.LoadImage(input_name, 1)

        #cv.WaitKey(0)
        try:
            cv.DestroyWindow("result" + str(camera_position))
        except:
            print "could not destroy window"
コード例 #13
0
ファイル: LaserDuck.py プロジェクト: wrericsson/MirrorTest
def main():
    # create windows for use later
    cv.NamedWindow("LaserDuckOut", 1)
    cv.NamedWindow("Theshold_IMG", 1)
    cv.NamedWindow("HSV Histogram", 1)
    # initiate camera
    capture = cv.CreateCameraCapture(0)

    # grab frame from camera

    while True:
        frame = cv.QueryFrame(capture)

        #             cv.Flip(frame, frame, 1)

        hist = histogram(frame)

        img = thresholdImage(frame)
        img = erodeImage(img)

        findImageContour(img, frame)

        # Mark out sampling region for histogram
        cv.Rectangle(frame, (10, 10), (110, 110), (0, 255, 0), 1, 0)

        # outputs image to windows created previously
        cv.ShowImage("Threshold_IMG", img)
        cv.ShowImage("LaserDuckOut", frame)
        cv.ShowImage("HSV_Histogram", hist)

        if cv.WaitKey(10) >= 0:
            break

    cv.DestroyWindow("LaserDuckOut")
    cv.DestroyWindow("Threshold_IMG")
    cv.DestroyWindow("HSV_Histogram")
コード例 #14
0
line1 = 0
line2 = 0
import os.path

subject = str(input("Subject: "))
video = str(input("Video: "))

if (os.path.isfile('data/' + subject + '/' + video +
                   '/diagnostics.txt')) == True:
    print(
        "Diagnostics file exists! System will not overwrite without deleting it first."
    )
    sys.exit()

cv.NamedWindow("camera", 1)
capture = cv.CreateCameraCapture(0)

f = open('data/' + subject + '/' + video + '/diagnostics.txt', 'w')
#font = cv.CvFont
font = cv.InitFont(1, 1, 1, 1, 1, 1)

width = None
height = None
width = 320
height = 240

if width is None:
    width = int(cv.GetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_WIDTH))
else:
    cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_WIDTH, width)
コード例 #15
0
ファイル: laplace.py プロジェクト: 2RoN4eG/Regula-Test-Task
#!/usr/bin/python
import urllib2
import cv2.cv as cv
import sys

if __name__ == "__main__":
    laplace = None
    colorlaplace = None
    planes = [ None, None, None ]
    capture = None

    if len(sys.argv) == 1:
        capture = cv.CreateCameraCapture(0)
    elif len(sys.argv) == 2 and sys.argv[1].isdigit():
        capture = cv.CreateCameraCapture(int(sys.argv[1]))
    elif len(sys.argv) == 2:
        capture = cv.CreateFileCapture(sys.argv[1])

    if not capture:
        print "Could not initialize capturing..."
        sys.exit(-1)

    cv.NamedWindow("Laplacian", 1)

    while True:
        frame = cv.QueryFrame(capture)
        if frame:
            if not laplace:
                planes = [cv.CreateImage((frame.width, frame.height), 8, 1) for i in range(3)]
                laplace = cv.CreateImage((frame.width, frame.height), cv.IPL_DEPTH_16S, 1)
                colorlaplace = cv.CreateImage((frame.width, frame.height), 8, 3)
コード例 #16
0
    # configure the serial connections (the parameters differs on the device you are connecting to)
    serialConnection = serial.Serial(port='/dev/ttyUSB1',
                                     baudrate=9600,
                                     parity=serial.PARITY_ODD,
                                     stopbits=serial.STOPBITS_TWO,
                                     bytesize=serial.SEVENBITS)

    serialConnection.open()
    serialConnection.isOpen()

    # create windows
    cv.NamedWindow('Original', cv.CV_WINDOW_AUTOSIZE)
    cv.NamedWindow('Threshold', cv.CV_WINDOW_AUTOSIZE)

    # create capture device
    capture = cv.CreateCameraCapture(0)  # assume we want first device
    cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_WIDTH, 640)
    cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_HEIGHT, 480)

    # check if capture device is OK
    if not capture:
        print "Error opening capture device"
        sys.exit(1)

    while 1:
        # do forever

        #capture the current frame
        frame = cv.QueryFrame(capture)

        if frame is None:
コード例 #17
0
if __name__ == '__main__':

    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 = cv.CreateCameraCapture (device)

    else:
        # we have an argument on the command line,
        # we can assume this is a file name, so open it
        capture = cv.CreateFileCapture (sys.argv [1])            

    # check that capture device is OK
    if not capture:
        print "Error opening capture device"
        sys.exit (1)
        
    # display a small howto use it
    print "Hot keys: \n" \
          "\tESC - quit the program\n" \
          "\tr - auto-initialize tracking\n" \
コード例 #18
0
        action="store",
        dest="cascade",
        type="str",
        help="Haar cascade file, default %default",
        default="../data/haarcascades/haarcascade_frontalface_alt.xml")
    (options, args) = parser.parse_args()

    cascade = cv.Load(options.cascade)

    if len(args) != 1:
        parser.print_help()
        sys.exit(1)

    input_name = args[0]
    if input_name.isdigit():
        capture = cv.CreateCameraCapture(int(input_name))
    else:
        capture = None

    cv.NamedWindow("result", 1)

    width = 320  #leave None for auto-detection
    height = 240  #leave None for auto-detection

    if width is None:
        width = int(cv.GetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_WIDTH))
    else:
        cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_WIDTH, width)

    if height is None:
        height = int(
コード例 #19
0
ファイル: faces.py プロジェクト: SantaHub/RaspberryWork
def detect_and_draw(img, cascade):
    # allocate temporary images
    gray = cv.CreateImage((img.width, img.height), 8, 1)
    small_img = cv.CreateImage((cv.Round(
        img.width / image_scale), cv.Round(img.height / image_scale)), 8, 1)

    # convert color input image to grayscale
    cv.CvtColor(img, gray, cv.CV_BGR2GRAY)

    # scale input image for faster processing
    cv.Resize(gray, small_img, cv.CV_INTER_LINEAR)
    cv.EqualizeHist(small_img, small_img)

    if (cascade):
        t = cv.GetTickCount()
        faces = cv.HaarDetectObjects(small_img, cascade,
                                     cv.CreateMemStorage(0), haar_scale,
                                     min_neighbors, haar_flags, min_size)
        t = cv.GetTickCount() - t
        print "time taken for detection = %gms" % (
            t / (cv.GetTickFrequency() * 1000.))
    if faces:
        for ((x, y, w, h), n) in faces:
            # the input to cv.HaarDetectObjects was resized, so scale the
            # bounding box of each face and convert it to two CvPoints
            pt1 = (int(x * image_scale), int(y * image_scale))
            pt2 = (int((x + w) * image_scale), int((y + h) * image_scale))
            cv.Rectangle(img, pt1, pt2, cv.RGB(255, 0, 0), 3, 8, 0)

        cv.ShowImage("video", img)

    if __name__ == '__main__':

        parser = OptionParser(
            usage="usage: %prog [options] [filename|camera_index]")
        parser.add_option(
            "-c",
            "-cascade",
            action="store",
            dest="cascade",
            type="str",
            help="Haar cascade file, default %default",
            default="../data/haarcascades/haarcascade_frontalface_alt.xml")(
                options, args) = parser.parse_args()

    cascade = cv.Load(options.cascade)

    if len(args) != 1:
        parser.print_help()
        sys.exit(1)

    input_name = args[0]
    if input_name.isdigit():
        capture = cv.CreateCameraCapture(int(input_name))
    else:
        capture = None

    cv.NamedWindow("video", 1)

    #size of the video
    width = 160
    height = 120

    if width is None:
        width = int(cv.GetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_WIDTH))
    else:
        cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_WIDTH, width)

    if height is None:
        height = int(
            cv.GetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_HEIGHT))
    else:
        cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_HEIGHT, height)

    if capture:
        frame_copy = None
    while True:

        frame = cv.QueryFrame(capture)
        if not frame:
            cv.WaitKey(0)
            break
        if not frame_copy:
            frame_copy = cv.CreateImage((frame.width, frame.height),
                                        cv.IPL_DEPTH_8U, frame.nChannels)

        if frame.origin == cv.IPL_ORIGIN_TL:
            cv.Copy(frame, frame_copy)
        else:
            cv.Flip(frame, frame_copy, 0)

    detect_and_draw(frame_copy, cascade)

    if cv.WaitKey(10) >= 0:
        break
    else:
        image = cv.LoadImage(input_name, 1)
        detect_and_draw(image, cascade)
        cv.WaitKey(0)

    cv.DestroyWindow("video")
コード例 #20
0
    author = raw_input('Autor del libro: ')
    book = ez_epub.Book()
    book.title = title
    book.authors = [author]
    book.sections = epubCreator.parseBook(r'temp.txt', 1, 100)
    book.make(r'%s' % book.title) 
    

if __name__ == '__main__':
    txtFile = 'temp.txt'
    option = int(raw_input('Elige una opcion (1 o 2):\n\t1. Tomar image desde camara\n\t2. Importar imagen\n'))
    cv.NamedWindow('ocr',1)
    os.system('rm '+txtFile)
    if option == 1:
        try:
            cam = cv.CreateCameraCapture(-1)
            camera_Capture(cam)
            images = open_Images()
            crop_Images(images)
            text = grab_Text(txtFile)
            create_epub()
        except:
            print 'No se detecto camara web'
    if option == 2:
        try:
            ext = raw_input('Que extension son las imagenes? ')
        #images = open_Images(path=folder, extension = '*.'+ext)
        #crop_Images(images)
            grab_Text(txtFile, camera = False)
        #create_Txt(text)
            create_epub()
コード例 #21
0
ファイル: faceModule.py プロジェクト: arasharchor/deepmodel
 def openCam(self):
     self.capture = cv.CreateCameraCapture(0)
     return self.capture
コード例 #22
0
    # Inizializzazione: camera, files, etc

    # Controlla se il simulatore/nao è attivo
    try:
        motion = ALProxy("ALMotion", 'localhost', 9559)
        motion.stiffnessInterpolation("Body", 1, 1)
    except:
        NaoLinked = False
    else:
        NaoLinked = True

    # Creo finestra?
    cv.NamedWindow(WINDOW_NAME, cv.CV_WINDOW_AUTOSIZE)

    # capture = cv.CaptureFromCAM(CAMERA_INDEX)
    capture = cv.CreateCameraCapture(CAMERA_INDEX)
    cv.SetCaptureProperty(capture, 3, 640)
    cv.SetCaptureProperty(capture, 4, 480)

    storage = cv.CreateMemStorage()

    # Carico file per riconoscimento features
    cascade_face = cv.Load(HAAR_FACE_PATH)
    cascade_alt_face = cv.Load(HAAR_FACE_ALT_PATH)
    cascade_alt2_face = cv.Load(HAAR_FACE_ALT2_PATH)
    cascade_tree_face = cv.Load(HAAR_FACE_TREE_PATH)
    cascade_eye = cv.Load(HAAR_EYE_PATH)
    cascade_left_eye = cv.Load(HAAR_LEFT_EYE_PATH)
    cascade_right_eye = cv.Load(HAAR_RIGHT_EYE_PATH)
    cascade_both_eyes = cv.Load(HAAR_BOTH_EYES_PATH)
コード例 #23
0
######################################################

    cv.ShowImage("result", img)

if __name__ == '__main__':

    #cascade = cv.Load("haarcascade_eye_tree_eyeglasses.xml")
    cascade = cv.Load("haarcascade_frontalface_alt.xml")
    #cascade = cv.Load("cars3.xml")
    #cascade = cv.Load("haarcascade_upperbody.xml")
    #cascade = cv.Load("aGest.xml")
    #cascade = cv.Load("haarcascade_fullbody.xml")
    #cascade = cv.Load("closed_frontal_palm.xml")
    #cascade = cv.Load("palm.xml")
    #cascade = cv.Load("smile.xml")
    capture = cv.CreateCameraCapture(2)  # camera   NO. 0, 1, 2
    print cv.GetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_WIDTH)

    cv.NamedWindow("result", 1)
    frame = cv.QueryFrame(capture)

    cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_WIDTH, width)
    cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_HEIGHT, height)

    if capture:
        frame_copy = None
        while True:
            frame = cv.QueryFrame(capture)

            if not frame:
                #print 'hehe'