Why do I get a repeated image in a single frame and how do I solve it? [closed]

asked 2014-03-18 15:42:38 -0600

updated 2014-03-18 15:43:10 -0600

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:

Resulting image of the code shown above

Some aspects to remark:

  1. The code executes normally and returns normal images when working with the integrated webcam of my laptop.
  2. The DMK41BU02 camera works normally and returns normal images when working with another application, such as fswebcam or VLC.
  3. The camera datasheet says it is compatible with OpenCV.
  4. 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.
  5. I have had some issues installing the camera drivers, but I think they're all resolved.
  6. 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.

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-10-19 15:44:22.004930

Comments

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.

diegoroman17 gravatar imagediegoroman17 ( 2014-03-18 16:16:17 -0600 )edit

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 :)

agarciamontoro gravatar imageagarciamontoro ( 2014-03-19 17:27:18 -0600 )edit

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.

diegoroman17 gravatar imagediegoroman17 ( 2014-03-21 14:54:59 -0600 )edit

I tried this some days ago, but it doesn't solve the problem :/

agarciamontoro gravatar imageagarciamontoro ( 2014-03-22 10:41:06 -0600 )edit