Ask Your Question
0

How to change BGR to RGB of a video frame using C /C++

asked Feb 23 '16

inckka gravatar image

updated Feb 23 '16

Webcam feed reads as a inverted RGB and so the rendered colors are incorrect. I need to change BGR to RGB. Below shows incomplete code of trying to achieve the end result. Can someone guide me through this to complete? Currently using OoenCV 2.xx

GdkPixbuf* pix;
IplImage* frame;
CvCapture* capture;

frame = cvQueryFrame( capture );

// Converting BGR to RGB
for (int i = 0; i<frame->height; i++)
{
    for (int x=0; x<frame->width; x++)
    {
        // LOST
    }
}

pix = gdk_pixbuf_new_from_data((guchar*) frame->imageData,
       GDK_COLORSPACE_RGB, FALSE, frame->depth, frame->width,
       frame->height, (frame->widthStep), NULL, NULL);

Edit: Its OK the same requirement is coded in C++

Preview: (hide)

Comments

please do not try to use opencv's discontinued c-api for anything.

they moved away from that half a decade ago, and so should you.

berak gravatar imageberak (Feb 23 '16)edit

please do not try to use opencv's discontinued c-api for anything.

they moved away from that half a decade ago, and so should you.

berak gravatar imageberak (Feb 23 '16)edit

@berak Then can I know how to perform the same task with C++ please? I edited the question.

inckka gravatar imageinckka (Feb 23 '16)edit

2 answers

Sort by » oldest newest most voted
4

answered Feb 23 '16

zshn25 gravatar image

You can just use

cv::VideoCapture cap(0);
cv::Mat frame;
while(cap.read (frame)){
  cv::cvtColor(frame, frame, BGR2RGB);
  cv::imshow("RGB", frame);
  cv::waitKey(1);
}
Preview: (hide)

Comments

2

@zshn25 It worked thanks.

inckka gravatar imageinckka (Feb 23 '16)edit
0

answered Feb 24 '16

GANESH PRASAATH L gravatar image
Preview: (hide)

Question Tools

2 followers

Stats

Asked: Feb 23 '16

Seen: 39,782 times

Last updated: Feb 24 '16