Ask Your Question

Revision history [back]

OpenCV Video Capture corrupted color

I am trying to use VideoCapture in OpenCV to open a video stream from IDS uEye Ethernet Cameras on Windows. This is in fact known to be supported out of the box (only on Windows). My initial attempt succeeded with the video running flawlessly (for the first time). But when I modified the code to attempt to grab the time-stamp, the video started behaving weirdly and gave corrupted colors.

The pictures can be found on StackOverflow under the same question name since I am not allowed to post pictures or links here yet. (which by the way is absurd since this is a computer vision forum)

The portion of the code responsible for the video capture

int keyIn = -1;
cv::Mat frame;

cv::VideoCapture cap(1); // 0 is my webcam
// set the proper size of the image since OpenCV defaults to 640x480
cap.set(CV_CAP_PROP_FRAME_WIDTH, 1600);
cap.set(CV_CAP_PROP_FRAME_HEIGHT, 1200);
while (true)
{
    cap >> frame;
    cv::flip(frame, frame, 0); // the frame if captured flipped (for some reason)
    cv::imshow("Feed", frame);
    keyIn = cv::waitKey(60); // 60 should be enough since I am running 15 fps
    if (keyIn == 27) // esc is pressed
        break;
}

I also tried playing around with the the format by setting different values for CV_CAP_PROP_FORMAT but still nothing changed.

Note that running the code outputs the following in the console:

SETUP: Setting up device 1
SETUP: **Camera Info**
SETUP: Couldn't find preview pin using SmartTee
SETUP: Default Format is set to 1600x1200
SETUP: trying specified format RGB24 @ 640x480
SETUP: Capture callback set
SETUP: Device is setup and ready to capture.


SETUP: Disconnecting device 1
SETUP: freeing Grabber Callback
SETUP: freeing Grabber
SETUP: freeing Control
SETUP: freeing Media Type
SETUP: removing filter NullRenderer...
SETUP: filter removed NullRenderer
SETUP: removing filter Sample Grabber...
SETUP: filter removed Sample Grabber
SETUP: removing filter Smart Tee...
SETUP: filter removed Smart Tee
SETUP: removing filter **Camera Info**...
SETUP: filter removed **Camera Info**
SETUP: freeing Capture Graph
SETUP: freeing Main Graph
SETUP: Device 1 disconnected and freed

SETUP: Setting up device 1
SETUP: **Camera Info**
SETUP: Couldn't find preview pin using SmartTee
SETUP: Default Format is set to 640x480
SETUP: trying specified format RGB24 @ 1600x1200
SETUP: Capture callback set
SETUP: Device is setup and ready to capture.

I do not understand why OpenCV defaults to 640x480 knowing that the original size is correct at 1600x1200 (this is forcing me to set the size manually). I also can't understand why the format is RGB24 knowing that I am setting the color mode to RGB32 (camera default).

Any input as to where might be the problem?

OpenCV Video Capture corrupted color

I am trying to use VideoCapture in OpenCV to open a video stream from IDS uEye Ethernet Cameras on Windows. This is in fact known to be supported out of the box (only on Windows). My initial attempt succeeded with the video running flawlessly (for the first time). But when I modified the code to attempt to grab the time-stamp, the video started behaving weirdly and gave corrupted colors.

The pictures can be found on StackOverflow under the same question name since I am not allowed to post pictures or links here yet. (which by the way is absurd since this is a computer vision forum)

The portion of the code responsible for the video capture

int keyIn = -1;
cv::Mat frame;

cv::VideoCapture cap(1); // 0 is my webcam
// set the proper size of the image since OpenCV defaults to 640x480
cap.set(CV_CAP_PROP_FRAME_WIDTH, 1600);
cap.set(CV_CAP_PROP_FRAME_HEIGHT, 1200);
while (true)
{
    cap >> frame;
    cv::flip(frame, frame, 0); // the frame if captured flipped (for some reason)
    cv::imshow("Feed", frame);
    keyIn = cv::waitKey(60); // 60 should be enough since I am running 15 fps
    if (keyIn == 27) // esc is pressed
        break;
}

I also tried playing around with the the format by setting different values for CV_CAP_PROP_FORMAT but still nothing changed.

Note that running the code outputs the following in the console:

SETUP: Setting up device 1
SETUP: **Camera Info**
SETUP: Couldn't find preview pin using SmartTee
SETUP: Default Format is set to 1600x1200
SETUP: trying specified format RGB24 @ 640x480
SETUP: Capture callback set
SETUP: Device is setup and ready to capture.


SETUP: Disconnecting device 1
SETUP: freeing Grabber Callback
SETUP: freeing Grabber
SETUP: freeing Control
SETUP: freeing Media Type
SETUP: removing filter NullRenderer...
SETUP: filter removed NullRenderer
SETUP: removing filter Sample Grabber...
SETUP: filter removed Sample Grabber
SETUP: removing filter Smart Tee...
SETUP: filter removed Smart Tee
SETUP: removing filter **Camera Info**...
SETUP: filter removed **Camera Info**
SETUP: freeing Capture Graph
SETUP: freeing Main Graph
SETUP: Device 1 disconnected and freed

SETUP: Setting up device 1
SETUP: **Camera Info**
SETUP: Couldn't find preview pin using SmartTee
SETUP: Default Format is set to 640x480
SETUP: trying specified format RGB24 @ 1600x1200
SETUP: Capture callback set
SETUP: Device is setup and ready to capture.

I do not understand why OpenCV defaults to 640x480 knowing that the original size is correct at 1600x1200 (this is forcing me to set the size manually). I also can't understand why the format is RGB24 knowing that I am setting the color mode to RGB32 (camera default).manually).

Any input as to where might be the problem?

OpenCV Video Capture corrupted color

I am trying to use VideoCapture in OpenCV to open a video stream from IDS uEye Ethernet Cameras on Windows. This is in fact known to be supported out of the box (only on Windows). My initial attempt succeeded with the video running flawlessly (for the first time). But when I modified the code to attempt to grab the time-stamp, the video started behaving weirdly and gave corrupted colors.

The pictures can be found on StackOverflow under the same question name since I am not allowed to post pictures or links here yet. (which How the image should look like (taken using the provided software by the way is absurd since this is a computer vision forum)IDS)

image description

How the image looks like when using OpenCV VideoCapture and saving the frame

image description

The portion of the code responsible for the video capture

int keyIn = -1;
cv::Mat frame;

cv::VideoCapture cap(1); // 0 is my webcam
// set the proper size of the image since OpenCV defaults to 640x480
cap.set(CV_CAP_PROP_FRAME_WIDTH, 1600);
cap.set(CV_CAP_PROP_FRAME_HEIGHT, 1200);
while (true)
{
    cap >> frame;
    cv::flip(frame, frame, 0); // the frame if captured flipped (for some reason)
    cv::imshow("Feed", frame);
    keyIn = cv::waitKey(60); // 60 should be enough since I am running 15 fps
    if (keyIn == 27) // esc is pressed
        break;
}

I also tried playing around with the the format by setting different values for CV_CAP_PROP_FORMAT but still nothing changed.

Note that running the code outputs the following in the console:

SETUP: Setting up device 1
SETUP: **Camera Info**
SETUP: Couldn't find preview pin using SmartTee
SETUP: Default Format is set to 1600x1200
SETUP: trying specified format RGB24 @ 640x480
SETUP: Capture callback set
SETUP: Device is setup and ready to capture.


SETUP: Disconnecting device 1
SETUP: freeing Grabber Callback
SETUP: freeing Grabber
SETUP: freeing Control
SETUP: freeing Media Type
SETUP: removing filter NullRenderer...
SETUP: filter removed NullRenderer
SETUP: removing filter Sample Grabber...
SETUP: filter removed Sample Grabber
SETUP: removing filter Smart Tee...
SETUP: filter removed Smart Tee
SETUP: removing filter **Camera Info**...
SETUP: filter removed **Camera Info**
SETUP: freeing Capture Graph
SETUP: freeing Main Graph
SETUP: Device 1 disconnected and freed

SETUP: Setting up device 1
SETUP: **Camera Info**
SETUP: Couldn't find preview pin using SmartTee
SETUP: Default Format is set to 640x480
SETUP: trying specified format RGB24 @ 1600x1200
SETUP: Capture callback set
SETUP: Device is setup and ready to capture.

I do not understand why OpenCV defaults to 640x480 knowing that the original size is correct at 1600x1200 (this is forcing me to set the size manually).

Any input as to where might be the problem?