Ask Your Question
0

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

asked 2016-02-23 02:31:23 -0500

inckka gravatar image

updated 2016-02-23 03:51:51 -0500

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++

edit retag flag offensive close merge delete

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 ( 2016-02-23 03:48:18 -0500 )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 ( 2016-02-23 03:48:37 -0500 )edit

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

inckka gravatar imageinckka ( 2016-02-23 03:50:37 -0500 )edit

2 answers

Sort by ยป oldest newest most voted
4

answered 2016-02-23 04:14:21 -0500

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);
}
edit flag offensive delete link more

Comments

2

@zshn25 It worked thanks.

inckka gravatar imageinckka ( 2016-02-23 05:06:18 -0500 )edit
0

answered 2016-02-24 03:04:58 -0500

GANESH PRASAATH L gravatar image
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

2 followers

Stats

Asked: 2016-02-23 02:31:23 -0500

Seen: 20,050 times

Last updated: Feb 24 '16