Convert CvImagePtr* (CvImage) channel to IplImage
Hi,
I have extracted an Image message using cv_bridge as this:
cv_bridge::CvImagePtr cv_ptr;
cv_ptr = cv_bridge::toCvCopy(msg, enc::MONO8);
and i could convert it to an IplImage using:
IplImage *image2 = NULL;
allocateit( &image2, frame_size, IPL_DEPTH_8U, 1 );
image2->imageData = (char *) cv_ptr->image.data;
where allocateit
is a function to allocate space.
My problem comes when I want to read a color image as this:
cv_bridge::CvImagePtr cv_ptr;
cv_ptr = cv_bridge::toCvCopy(msg, enc::BGR8);
IplImage *image2 = NULL;
allocateit( &image2, frame_size, IPL_DEPTH_8U, 1 );
and want to copy one channel of *cv_ptr
to the image to the IplImage *image2
. I have tried:
image2->imageData = (char *) cv_ptr->image.data;
but it crashes,
cv::cvtColor(cv_ptr->image.data,image2->imageData,CV_RGB2GRAY);
but does not compile,
int from_to[] = {0,0};
cv::mixChannels(&(cv_ptr->image.data),1,image2,1, from_to,1);
does not compile either.
What would you recommend me to do? Thanks!