horizontal line/break/image shift in video from webcam

asked 2018-02-05 02:21:39 -0600

Peter12 gravatar image

updated 2018-02-05 05:32:07 -0600

Hello, when I move with my webcam quickly, I see these artefacts/image breaks/shifts. I am using vlc v4l2 with /dev/video0 via vlc command line to preview live webcam video. Please, What should I set please to prevent these artefacts?

image description

image description

image description

image description

My sample code:

import cv2

def show_webcam(mirror=False):
    cam = cv2.VideoCapture(0)
    while True:
            ret_val, img = cam.read()
        img = cv2.flip(img, 0)
            cv2.imshow('my webcam', img)
        del(img)
        cv2.waitKey(1)
    cv2.destroyAllWindows()

def main():
    show_webcam(mirror=False)

if __name__ == '__main__':
    main()
edit retag flag offensive close merge delete

Comments

...and the connection with OpenCV is???

kbarni gravatar imagekbarni ( 2018-02-05 04:01:16 -0600 )edit

I added code example. No idea if it is specifically opencv related only

Peter12 gravatar imagePeter12 ( 2018-02-05 05:31:24 -0600 )edit

Ok. You have a frame syncronization problem, which probably isn't OpenCV related. As you tried it with VLC and you got the same problem.

You can try to change the frame rate of the camera: cam.set(CV_CAP_PROP_FPS,[some value]). Maybe it will help.

One last comment: don't delete the frame after displaying it. img will be simply reused for the next frame.

kbarni gravatar imagekbarni ( 2018-02-05 09:48:47 -0600 )edit

thank you, it really seems to be frame rate problem. I will experiment with it.

Peter12 gravatar imagePeter12 ( 2018-02-07 08:03:14 -0600 )edit