Quantcast

opencv conversion

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

opencv conversion

valerio.sperati
Hi all,
Please, I need to put a cv::Mat A (it is a CV_8UC3) into a  ImageOf<PixelRgb>&B,
in order to send it through a yarp::os::BufferedPort<ImageOf<PixelRgb> > C;

My code is:

1) ImageOf<PixelRgb>&B = C.prepare();
2) IplImage D = A ;
3) B.wrapIplImage(&D);
4) C.write();

The code works, (I can see the sent image on yarpview), but I have this
message on the shell:

"your specific IPL format (BGR depth 8 -> bgr) does not match your YARP format (rgb)
Making a copy instead of just wrapping..."

I was wondering if this is the correct way to do it....
thanks
 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: opencv conversion

paulfitz
Administrator
Hi Valerio,

That warning means that the B.wrapIplImage(&D) call isn't able to do its
job, because B has color order RGB and D has color order BGR.  So it
makes a copy instead, and shuffles the color channels.  Unless you
yourself care about the order, you can probably fix this by just
replacing PixelRgb everywhere with PixelBgr.

Here's some alternative code that avoids the intermediate IplImage.

   yarp::os::Port C;
   ...
   // A is a cv::Mat
   ImageOf<PixelBgr> B;
   B.setExternal(image.data,image.size[1],image.size[0]);
   C.write(B);

I used a Port instead of a BufferedPort because I don't know the
lifetime of the A object.  With a buffered port, you'd need to be
careful that A isn't destroyed or modified while the port is writing
(which happens in the background).

Cheers,
Paul

On 06/25/2014 12:06 PM, valerio.sperati wrote:

> Hi all,
> Please, I need to put a cv::Mat A (it is a CV_8UC3) into a
> ImageOf<PixelRgb>&B,
> in order to send it through a yarp::os::BufferedPort<ImageOf&lt;PixelRgb> >
> C;
>
> My code is:
>
> 1) ImageOf<PixelRgb>&B = C.prepare();
> 2) IplImage D = A ;
> 3) B.wrapIplImage(&D);
> 4) C.write();
>
> The code works, (I can see the sent image on yarpview), but I have this
> message on the shell:
>
> "your specific IPL format (BGR depth 8 -> bgr) does not match your YARP
> format (rgb)
> Making a copy instead of just wrapping..."
>
> I was wondering if this is the correct way to do it....
> thanks
>  
>
>
>
> --
> View this message in context: http://robotcub-hackers.2198711.n2.nabble.com/opencv-conversion-tp7578906.html
> Sent from the RobotCub Hackers mailing list archive at Nabble.com.
>
> ------------------------------------------------------------------------------
> Open source business process management suite built on Java and Eclipse
> Turn processes into business applications with Bonita BPM Community Edition
> Quickly connect people, data, and systems into organized workflows
> Winner of BOSSIE, CODIE, OW2 and Gartner awards
> http://p.sf.net/sfu/Bonitasoft
> _______________________________________________
> Robotcub-hackers mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/robotcub-hackers


------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
Robotcub-hackers mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/robotcub-hackers
Loading...