Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

cv2.VideoCapture not blocking duplicate frames

Hi' I'm using a Raspbery Pi and Pi Camera module with OpenCV though the V4L2 driver and have noticed I'm getting sequences of identical frames returned from cv2.VideoCapture in groups of 4. It seems like the function is not waiting until a new image is captured and the duplicate frames are not being blocked. Anyone had this problem? Here is some sample code:

 def open_camera(cam_id = 0):
     cap = cv2.VideoCapture(cam_id)
     cap.set(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT, 240);
     cap.set(cv2.cv.CV_CAP_PROP_FRAME_WIDTH, 320);


     return cap

def get_frame(device):
     ret, img = device.read()
     if (ret == False): #failed to capture
         print >> sys.stderr, "Error capturing from vid dev"
         return None
     return img



def run(wh,sh,wh2,sh2): 
    find_colour(wh,sh,wh2,sh2)

    dev = open_camera(0)    

    while True:

        img = get_frame(dev) # get frame from cam
        if img is not None:# if possible to get image
       #program code
        else: 
        print 'failed to capture'
            controller.forward(128)#stop
            break


return()

cv2.VideoCapture not blocking duplicate frames

Hi' I'm using a Raspbery Pi and Pi Camera module with OpenCV though the V4L2 driver and have noticed I'm getting sequences of identical frames returned from cv2.VideoCapture in groups of 4. It seems like the function is not waiting until a new image is captured and the duplicate frames are not being blocked. Anyone had this problem? Here is some sample code:Even with simple code from opencv tutorial, same result. I also tried updating Pi, new SD card still no joy

import numpy as np import cv2

cap = cv2.VideoCapture(0)

while(True): # Capture frame-by-frame ret, frame = cap.read()

 def open_camera(cam_id = 0):
     cap = cv2.VideoCapture(cam_id)
     cap.set(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT, 240);
     cap.set(cv2.cv.CV_CAP_PROP_FRAME_WIDTH, 320);
print frame[160,100]
 
     return cap

def get_frame(device):
     ret, img = device.read()
     # Display the resulting frame
cv2.imshow('frame',frame)
if (ret cv2.waitKey(1) & 0xFF == False): #failed to capture
         print >> sys.stderr, "Error capturing from vid dev"
         return None
     return img



def run(wh,sh,wh2,sh2): 
    find_colour(wh,sh,wh2,sh2)

    dev = open_camera(0)    

    while True:

        img = get_frame(dev) # get frame from cam
        if img is not None:# if possible to get image
       #program code
        else: 
        print 'failed to capture'
            controller.forward(128)#stop
        ord('q'):
    break


return()

When everything done, release the capture

cap.release() cv2.destroyAllWindows()

cv2.VideoCapture not blocking duplicate frames

Hi' I'm using a Raspbery Pi and Pi Camera module with OpenCV though the V4L2 driver and have noticed I'm getting sequences of identical frames returned from cv2.VideoCapture in groups of 4. It seems like the function is not waiting until a new image is captured and the duplicate frames are not being blocked. Anyone had this problem? Even with simple code from opencv tutorial, same result. I also tried updating Pi, new SD card still no joyjoy:

import numpy as np
import cv2

cv2

cap = cv2.VideoCapture(0)

cv2.VideoCapture(0)

while(True): # Capture frame-by-frame ret, frame = cap.read()

cap.read()
 print frame[160,100]

 # Display the resulting frame
 cv2.imshow('frame',frame)
 if cv2.waitKey(1) & 0xFF == ord('q'):
     break

# When everything done, release the capture

capture cap.release() cv2.destroyAllWindows()

cv2.destroyAllWindows()