From: Jamuraa <ja...@ba...> - 2007-01-06 22:50:07
|
On 1/5/07, chandan datta <cha...@ho...> wrote: > Hi, > I'm using OpenCv to do all my Image processing operations and Player for > navigation.I'm calling OpenCv functions from Player.Here is a very basic > client side code to make sure that I get live images from the camera through > Player. > > > #include <iostream> > #include <cstdlib> > #include <libplayerc++/playerc++.h> > #include <libplayerc++/playerclient.h> > #include <stdlib.h> > > #include <opencv/highgui.h> > > int main(int argc, char *argv[]) > { > PlayerCc::PlayerClient robot("localhost"); > PlayerCc::CameraProxy cp(&robot, 0); > > IplImage* img = cvCreateImage(cvSize(320, 240), IPL_DEPTH_8U, 3); > cvNamedWindow("camerav4l", 1); > > > uint8_t* myImage; > for (;;) > { > robot.Read(); > // cp.Print(); > > > { > // copy Player's frame buffer to OpenCV image, converting from RGB > to BGR > for (uint x = 0; x < cp.GetDepth(); x++) > { > for (uint y = 0; y < cp.GetHeight(); y++) > { > cp.GetImage(myImage); > (img->imageData + 320 * 3 * y)[x * 3]=(char)myImage; > > // ((img->imageData + 320 * 3 * y))[x * 3] = Image(320 * 3 * > y + x * 3 + 2); > // ((uchar*)(img->imageData + 320 * 3 * y))[x * 3 + 1] = > Image(320 * 3 * y + x * 3 + 1); > // ((uchar*)(img->imageData + 320 * 3 * y))[x * 3 + 2] = > Image(320 * 3 * y + x * 3); > } > } > cvShowImage("camerav4l", img); > cvWaitKey(10); > > } > } > > > cvDestroyWindow("camerav4l"); > cvReleaseImage(&img); > > return EXIT_SUCCESS; > } > > But getting the following errors because OpenCv's image capturing > datastructure is different from Player's. > the error is : > > [root@localhost libplayerc++]# make > > opencv_camera.cc: In function 'int main(int, char**)': > opencv_camera.cc:37: error: cast from 'uint8_t*' to > 'char' loses precision > make: *** [opencv_camera.o] Error 1 > > Also the commented out code should work under the previous Player versions(i > have checked the docs for presence of Image datastructure). > So how should the datastructure of both libraris made to work together ? > > Also my Machine Vision code is very CPU intensive- someone please suggest > a coding model to be used so that vision and navigation code can be > multithreaded and run concurrently under Player. > > > Thanks for suggestions, > Chandan. First thing that I noticed was that you're calling the GetImage on every iteration of that loop, which copies the image every time you copy one pixel. That could be a cause of your high CPU usage as well. Also, the myImage is not a character, it's an array of bytes. Normally, I would write the loop as: // copy Player's frame buffer to OpenCV image, converting from RGB to BGR cp.GetImage(myImage); for (uint x = 0; x < cp.GetWidth(); x++) { for (uint y = 0; y < cp.GetHeight(); y++) { (img->imageData + 320 * 3 * y)[x * 3]=(char)myImage[cp.GetWidth() * 3 * y + x * 3 + 2]; (img->imageData + 320 * 3 * y)[x * 3 + 1]=(char)myImage[cp.GetWidth() * 3 * y + x * 3 + 1]; (img->imageData + 320 * 3 * y)[x * 3 + 2]=(char)myImage[cp.GetWidth() * 3 * y + x * 3]; } } cvShowImage("camerav4l", img); cvWaitKey(10); Hope this helps! -- Michael Janssen --- Jamuraa --- ja...@ba... --- ja...@de... |