Ask Your Question
0

How do you stop a capture frame getting split ?

asked 2016-01-02 09:58:04 -0600

bungler gravatar image

updated 2016-01-02 11:09:12 -0600

I have a simple program.

#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include "iostream"

using namespace cv;
using namespace std;

int main(int argc, char** argv)
{
Mat frame;
VideoCapture capture;

capture.open(0);
if(!capture.isOpened()){ // check if we succeeded
cout << "Cannot open capture." << endl;
return -1;
}
capture.read(frame);
imwrite("img.jpg", frame);
capture.release();
return 0;
}

It usually works with a good photo image description

but sometimes it doesn't

image description

How does one stop this frame splitting ?

edit retag flag offensive close merge delete

Comments

3

honestly, i've never seen something like that happen before

hardware ? os ? opencv version ?

berak gravatar imageberak ( 2016-01-02 10:21:29 -0600 )edit
1

with your code i get a black image because my webcam need some time to warm up. see my answer here

sturkmen gravatar imagesturkmen ( 2016-01-02 11:16:18 -0600 )edit

O/S is Linux 4.1.7 on a Raspberry Pi B+
OpenCV 2.4.10
USB video class driver is 1.1.1
Camera identified in system logs as...
Jan 1 00:00:04 rfm69cw kern.info kernel: [ 4.698340] usb 1-1.5: New USB device found, idVendor=1908, idProduct=2311
Jan 1 00:00:04 rfm69cw kern.info kernel: [ 4.733121] uvcvideo: Found UVC 1.00 device USB2.0 PC CAMERA (1908:2311)
Jan 1 00:00:04 rfm69cw kern.info kernel: [ 4.737792] input: USB2.0 PC CAMERA as /devices/platform/bcm2708_usb/usb1/1-1/1-1.5/1-1.5:1.0/input/input0

bungler gravatar imagebungler ( 2016-01-02 12:10:27 -0600 )edit

It's strange : there is no visible step between two blocks (x~290).

May be compression killed this step...

LBerger gravatar imageLBerger ( 2016-01-02 15:36:51 -0600 )edit

I've seen this type of image corruption when a USB2 camera is connected to a USB3 port or a USB SS port.

harsha gravatar imageharsha ( 2016-01-03 19:45:45 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-01-04 10:04:52 -0600

bungler gravatar image

It would appear that sturkmen is sort of right.

I modified the code to grab 3 frames (a, b, c) and write those 3 frames to disk. About 90% of the time frame a (the first) is OK. Frames b & c always appear to be OK - even when frame a is bad.

I now read two frames and throw the first away. Seems to have solved my problem.

Thanks all

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-01-02 09:52:28 -0600

Seen: 664 times

Last updated: Jan 04 '16