Hi,

instead of the magic "3" in your setImage, try "GL_RGB".

E.g. we have some code like this:

->setImage(ImageFormat_.getWidth(), ImageFormat_.getHeight(), 1,
GL_RGB, GL_RGB, GL_UNSIGNED_BYTE,
&(im->Data_[0]),
osg::Image::NO_DELETE)

jp

Ugras Erdogan wrote:
Dear All,

I am using openCV and OSG together in my project. What the problem is as follows:

1) When I try to convert the IplImage to osg::Image the following command line trace occurs. Except the last three lines, the trace shows the openCV and osg image properties.

Pixel Bits: 32, Image Size (Byte): 307200
Video Depth: 1
cv Channels = 3
Convert_OpenCV_to_OSG_IMAGE()::Origin Passed 2...
Mutex w/r : 0
error pixelFormat = error pixelFormat = 33

Warning: detected OpenGL error 'invalid operation' after RenderBin::draw(,)
Warning: detected OpenGL error 'invalid operation' after RenderBin::draw(,)

2) I lock the mutex in order to prevent simultaneous writes to osg::Image data and as you can see at 5th line above it returns the correct value 0. Then use the following code:

void Convert_OpenCV_to_OSG_IMAGE(IplImage* cvImg, osg::Image* osgImg)

{

//.....

osgImg->setImage(cvImg->width,

                                  cvImg->height,

                                   1,

                                   3,

                                   GL_RGB,

                                  GL_UNSIGNED_BYTE,

                                   (unsigned char*)(cvImg->imageData),

                                    osg::Image::AllocationMode::NO_DELETE,

                                    1);

//.....

}

The above code segment is similar to the one in a post I encountered in this forum (*John Steinbis* jsteinbis at gmail.com <mailto:osg-users%40lists.openscenegraph.org?Subject=%5Bosg-users%5D%20Convertion%20to%20osg%3A%3AImage%20from%20IplImage%20%28OpenCV%29%20for%0A%09useas%20texture&In-Reply-To=E4D07AB09F5F044299333C8D0FEB45E9042314AE%40nrccenexb1.nrc.ca> /Mon Sep 17 11:04:04 PDT 2007/) but there are modifications for my needs. I can be sure that cvImg->imageData contains the actual processed video data because I can see the results in a seperate window. But the above problem occurs when I try to render the processed video as a texture onto a surface.

3) The above function Convert_OpenCV_to_OSG_IMAGE() is called in the main loop as follows:

while(!viewer.done())

{

 //.....

getPixelBufferObject()->setImage(Convert_OpenCV_to_OSG_IMAGE(pImage,

((osg::Image*)(video.get()))));

 //.....

}

What might be the problem? When I disable the code segment
osgImg->setImage(cvImg->width,

                                  cvImg->height,

                                   1,

                                   3,

                                   GL_RGB,

                                  GL_UNSIGNED_BYTE,

                                   (unsigned char*)(cvImg->imageData),

                                    osg::Image::AllocationMode::NO_DELETE,

                                    1);

everything is OK but as you can guess I cannot use the processed frame as a texture in 3D environment.

Thanks for your helps...
Best Regards
Ugras Erdogan


------------------------------------------------------------------------

_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

--
This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard. The full disclaimer details can be found at http://www.csir.co.za/disclaimer.html.

This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. MailScanner thanks Transtec Computers for their support.

_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to