From Wiki for iCub and Friends
Jump to: navigation, search

Inverted orientation and color space

When getting an OpenCV image from yarp and then displaying it you get an upside down picture and the red and blue channels are inverted. The point is that OpenCV does a lot of (badly documented) assumptions : actually the cvShowImage function expects an image in 8 bit depth BGR coding !

So here a way to deal with that :

// A new image is acquired and converted into a BGR
// IplImage stored into p_ipl_image_in 

//  Reading from YARP
yarp_rgb_image_t* tmp_yarp_img =;
// "Converting" into an IplImage (actually just getting the pointer)
IplImage* tmp_ipl_image = (IplImage*) tmp_yarp_img->getIplImage();
// Creating a new image of the same size and depth (may be depth should be force to IPL_DEPTH_8U ?)
p_ipl_image_in = cvCreateImage( cvSize(tmp_ipl_image->width,  tmp_ipl_image->height), 
									tmp_ipl_image->depth, 3 );
// Doing the color conversion which also copies the image in the ne just created
cvCvtColor(tmp_ipl_image, p_ipl_image_in, CV_RGB2BGR);
// Adjusting origin 

There is an other very usefull function in OpenCV cvConveertImage which (tries to) do the right conversion between 2 images on the base f the information contained in the headers...

IplImage *tmp_img;
tmp_img = cvCreateImage(img_size,  IPL_DEPTH_8U, 1 );
//cvCvtColor(p_ipl_image_in, tmp_img, CV_BGR2GRAY);
cvConvertImage(p_ipl_image_in, tmp_img);

Other libraries

Any way OpenCV is a real nightmare of badly or un- documented assumptions (try to do some optical flow stuff just to see ;-) ) and here are some other libraries :

  • VXL [1]
    •  :-( Not so complete as OpenCV
    •  :-( Replace the standard hearders and function of the C++ for th sake of compatibility !!!
    •  :-) Better documentation
    •  :-) Linked to Kitware [2] the team developping VTK [3], ITK and CMake which seems to produce good stuff...
  • LTIlib [4]
    • Real C++ and not decorated C
    • Well documented and (seemingly) simple to use
    • Almost as many algorithms as in OpenCV
  • CImg used in Renaud yayarpview [5]
  • Torch [6] is a very nice learning library, which as recently gained a vision module : don't know anything more about it...