OpenCV capture forward to V4L2 loopback
Hy!
I'm trying to implement the V4L2 loopback and its working, but the image what i forwards from the opencv capture it has some problems. If i know it right, opencv captures RGB image. In my settings I set the format like this->
header:
# define FRAME_FORMAT V4L2_PIX_FMT_RGB24
# define FRAME_WIDTH 640
# define FRAME_HEIGHT 480
struct v4l2_capability vid_caps;
struct v4l2_format vid_format;
const char*video_device=VIDEO_DEVICE;
int fdwr;
size_t framesize= FRAME_WIDTH * FRAME_HEIGHT * 3;
size_t linewidth= FRAME_WIDTH * 3;
Video format settings:
vid_format.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
vid_format.fmt.pix.width = FRAME_WIDTH;
vid_format.fmt.pix.height = FRAME_HEIGHT;
vid_format.fmt.pix.pixelformat = FRAME_FORMAT;
vid_format.fmt.pix.sizeimage = framesize;
vid_format.fmt.pix.field = V4L2_FIELD_NONE;
vid_format.fmt.pix.bytesperline = linewidth;
vid_format.fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
Writing:
IplImage *frame= NULL; //Preparing frame pointer
CvCapture *input_camera= cvCaptureFromCAM(1);
cvSetCaptureProperty(input_camera, CV_CAP_PROP_FRAME_WIDTH, FRAME_WIDTH);
cvSetCaptureProperty(input_camera, CV_CAP_PROP_FRAME_HEIGHT, FRAME_HEIGHT);
frame = cvQueryFrame(input_camera);
write(fdwr, &frame->imageData, framesize);
The problem is my image colors aren't right. Sometimes its green or cyan overlayed. The original yellow color is displayed like purple. Did anyone meet this kind of problem of does somebody know the solution? Thank you for any kind of help!
OpenCV is using BGR instead of RGB.
@roothema could you share your full code listing? I'm trying to do the same thing and encounter some obstacles as well