Converting from ofxCvGrayscaleImage to cv::Mat and back.

Hello,

I’m currently working on a computer vision project with another developer.
He’s been using ofxOpenCv and I’ve been using ofxCv so far.
I’m using a few cv functions so I’m converting to cv::Mat :

  
  
Mat cvimg = grayImage.getCvImage();//cv converts *IplImage to Mat  
  

I’ve managed to convert to an ofImage:

  
  
ofImage oimg;  
toOf(cvimg,oimg);  
oimg.update();  
  

but I haven’t managed to convert back to an ofxCvGrayScaleImage.
I can use cv to convert a cv::Mat to an IplImage and I’ve tried to use ofxCvGrayScaleImage = operator:

  
  
IplImage iplimg = cvimg;//cv::Mat to IplImage  
grayImage = iplimg;  
  

but with no luck so far.

What is the correct way to convert from a cv::Mat to ofxCvGrayScaleImage ?

I’m completely stuck on this.

I’d like to use the openCV (2D) DFT function with my regular images that I load in openframeworks…

I’m using the openCV example project so it is presently: ofxCvGrayscaleImage .

Many Thanks

you can do:

  
  
IplImage iplimg = cvimg;//cv::Mat to IplImage    
grayImage.getCvImage() = &iplimg;   
  

be careful though that you IplImage declaration is in a .h or somewhere where it won’t go out of scope when the function ends

actually thinking it better:

  
  
*grayImage.getCvImage() = cvimg;  
  

should work too without need for an intermediate IplImage