Why do I get a repeated image in a single frame and how do I solve it? [closed]
I am trying to build an application to simply get, save and show some frames from my camera, a DMK 41BU02 (you can consult the specifications of the device in the following link: datasheet)
My code is as simple as that:
#include "opencv2/opencv.hpp"
using namespace std;
using namespace cv;
int main(int, char**)
{
String path="~/proof.jpg";
VideoCapture cap(1); // /dev/video0 is the integrated webcam of my laptop, while /dev/video1 is the DMK41BU02 camera
cvNamedWindow( "Video", CV_WINDOW_AUTOSIZE );
if(!cap.isOpened()) // check if we succeeded
return -1;
Mat frame;
cap >> frame;
imwrite(path, frame);
imshow("Video", frame);
waitkey(0);
return 0;
}
The code compiles and executes whithout any problem, but the error arrives when the image is shown on the window or saved in the jpg file, because I get something like the following jpg, where the image is triplicated in the frame:
Some aspects to remark:
- The code executes normally and returns normal images when working with the integrated webcam of my laptop.
- The DMK41BU02 camera works normally and returns normal images when working with another application, such as fswebcam or VLC.
- The camera datasheet says it is compatible with OpenCV.
- I have also tried the code with an infinite loop, as I know the first frame grabbed can be blank or with some type of error, but the problem is still there.
- I have had some issues installing the camera drivers, but I think they're all resolved.
- The laptop is a 32-bit machine with Ubuntu installed on it. Here you can see the output of
uname -a
:Linux AsusPC 3.11.0-18-generic #32~precise1-Ubuntu SMP Thu Feb 20 17:54:21 UTC 2014 i686 i686 i386 GNU/Linux
I have no idea of how to debug this problem and, of course, I don't know where the error could be. Could you give me any hint, please?
Thank you very much.
I had the same problem. When your camera capture in Monochrome and you configure the Mat that receive the Frame in RGB mode the other two channels are copied with the same data of the first. You could post the routine of frame acquisicion.
That makes a lot of sense, @diegoroman17!! I will look for more info about the three versus one channel, but what do you mean by the routine of frame acquisition? I'm not sure if I understood you. Thank you very much :)
You need add the next line after adquire the frame: cvtColor(frame, frameGray, CV_BGR2GRAY); where frameGray is other Mat. it convert the RGB image to GrayScale image.
I tried this some days ago, but it doesn't solve the problem :/