Ask Your Question

Revision history [back]

Awful artifacts when capturing from web cam

I am running OpenCV 3.1.0 on my Raspberry Pi 3 (with Raspbian Jessie). I'm using the Python 2.7 bindings.

As I request frames from a VideoCapture, occasionally (apparently at random) the frame will have an awful blocky artifact as seen below.

image description

This never occurs when I use the webcam on my PC, nor does it occur when I view the webcam with a program like Cheese on the Raspberry Pi, so I have to conclude that it's either an OpenCV problem, or I'm using openCV incorrectly.

Further, the bad frames happen MUCH more often when the Pi is doing other things as well (for example, if I open a web browser while it's capturing).

Below is a sample script where I encounter the problem.

import cv2
cap = cv2.VideoCapture(0)
while(True):
    res, im = cap.read()
    cv2.imshow("foo", im)
    cv2.waitKey(1)

My suspicion is that it has something to do with trying to retrieve the image buffer while the buffer is in the process of being updated, or something like that.

Am I doing something wrong here?

Again, I've only seen this issue occur with OpenCV on the Pi (to be clear, I have not yet tried it on my desktop or laptop with OpenCV... I'm downloading it now to my laptop. I will update with an indication of whether or not it works there)

Awful artifacts when capturing from web cam

I am running OpenCV 3.1.0 on my Raspberry Pi 3 (with Raspbian Jessie). I'm using the Python 2.7 bindings.

As I request frames from a VideoCapture, occasionally (apparently at random) the frame will have an awful blocky artifact as seen below.

image description

This never occurs when I use the webcam on my PC, nor does it occur when I view the webcam with a program like Cheese on the Raspberry Pi, so I have to conclude that it's either an OpenCV problem, or I'm using openCV incorrectly.

Further, the bad frames happen MUCH more often when the Pi is doing other things as well (for example, if I open a web browser while it's capturing).

Below is a sample script where I encounter the problem.

import cv2
cap = cv2.VideoCapture(0)
while(True):
    res, im = cap.read()
    cv2.imshow("foo", im)
    cv2.waitKey(1)

My suspicion is that it has something to do with trying to retrieve the image buffer while the buffer is in the process of being updated, or something like that.

Am I doing something wrong here?

Again, I've only seen this issue occur with OpenCV on the Pi (to be clear, I have not yet Pi.

I've also tried it with OpenCV on my desktop or laptop with OpenCV... and I don't see the artifacts. So, the problem might not be OpenCV specifically, but I'm downloading hoping I'm not the only person here that's had this issue. (and again, I haven't seen it now to my laptop. I will update with an indication of whether or not it works there)with any other image capture programs on the PI either... though they all run at much slower frame rates)