Ask Your Question
0

YUV422 image appears only gray

asked 2013-09-09 09:11:54 -0600

syberarall gravatar image

updated 2013-09-09 09:15:05 -0600

Hello,

I Need to preview camera Images gathering YUV422 Format data into a buffer. The following code works fine, but only as gray image:

  IplImage *pYuvImage;
  pYuvImage = cvCreateImage(cvSize(SizeX, SizeY), IPL_DEPTH_16U, 1);
  pYuvImage->imageData = (char*)buffer;

  cvNamedWindow("MyImage");
  cvShowImage("MyImage", pYuvImage);
  cvWaitKey();
  cvDestroyWindow("MyImage");
  cvReleaseImage(&pYuvImage);

Now actually I need to have a color Image window, so I tried following:

  IplImage *pBgrImage;
  pBgrImage = cvCreateImage(cvSize(SizeX, SizeY), IPL_DEPTH_8U, 3);

  IplImage *pYuvImage;
  pYuvImage = cvCreateImage(cvSize(SizeX, SizeY), IPL_DEPTH_16U, 1);
  pYuvImage->imageData = (char*)buffer;

  cvCvtColor(pYuvImage, pBgrImage, CV_YUV2RGB);

  cvNamedWindow("MyImage");
  cvShowImage("MyImage", pYuvImage);
  cvWaitKey();
  cvDestroyWindow("MyImage");
  cvReleaseImage(&pYuvImage);

Now cvCvtColor fails with an exception accessing wrong Memory. What goes wrong ? Remember, gray works fine - any help is appreciated.

Regards, Jürgen

edit retag flag offensive close merge delete

3 answers

Sort by » oldest newest most voted
0

answered 2013-10-08 05:56:35 -0600

bird12358 gravatar image

Hello,

I had the same trouble with my webcam. I use unicap library which me information about my webcam:

Formats[1]:
    YUV 4:2:2 (YUYV) ( YUYV )
        FOURCC: YUYV
        size: 1280x1024x16
        size_count: 7
            640x480
            352x288
            320x240
            176x144
            160x120
            1280x800
            1280x1024

But the only result I can get, it is a gray scale images.

Do you achieve to get rgb images from your camera?

edit flag offensive delete link more
0

answered 2013-09-12 13:00:46 -0600

syberarall gravatar image

Now I got the solution - the following code works fine:

 IplImage *pRgbImage;
  pRgbImage = cvCreateImage(cvSize(SizeX, SizeY), IPL_DEPTH_8U, 3);

  IplImage *pYuvImage;
  pYuvImage = cvCreateImage(cvSize(SizeX, SizeY), IPL_DEPTH_8U, 2);
  pYuvImage->imageData = (char*)buffer;

  cvCvtColor(pYuvImage, pRgbImage, CV_YUV2RGB);

  cvNamedWindow("MyImage");
  cvShowImage("MyImage", pRgbImage);
  cvWaitKey();
  cvDestroyWindow("MyImage");
  cvReleaseImage(&pRgbImage);

But I still have Problems converting BayerBG12:

 IplImage *pRgbImage;
  pRgbImage = cvCreateImage(cvSize(SizeX, SizeY), IPL_DEPTH_8U, 3);

  IplImage *pYuvImage;
  pBg12Image = cvCreateImage(cvSize(SizeX, SizeY), IPL_DEPTH_8U, 2);
  pBg12Image->imageData = (char*)buffer;

  cvCvtColor(pBg12Image, pRgbImage, CV_BayerBG2RGB);

  cvNamedWindow("MyImage");
  cvShowImage("MyImage", pRgbImage);
  cvWaitKey();
  cvDestroyWindow("MyImage");
  cvReleaseImage(&pRgbImage);

Any suggestions ?

edit flag offensive delete link more
0

answered 2013-09-09 09:58:57 -0600

berak gravatar image

i might be wrong, but i guess that CV_YUV2RGB expects 24bit input data, ie a whole byte per channel.

try COLOR_YUV2RGB_Y422 instead

edit flag offensive delete link more

Comments

Thanks for the quick Response. But also COLOR_YUV2RGB_Y422 (CV_YUV2RGB_Y422) makes no difference. I have really no idea any more how to solve this Problem, so any help is welcome.

syberarall gravatar imagesyberarall ( 2013-09-10 03:45:36 -0600 )edit

Question Tools

Stats

Asked: 2013-09-09 09:11:54 -0600

Seen: 6,317 times

Last updated: Oct 08 '13