Converting CVMat or IplImage back to ofxcvImage

Hi there,
I am trying to do some things with native C opencv functions.
In order to use them I understand I have to convert my ofxcvImage to an IplImage with .getCvImage();

like: ` IplImage* grayCVImg = grayImg.getCvImage();

    CvMat *dst = cvCreateMat(grayCVImg->width, grayCVImg->height, grayCVImg->nChannels);
    CvMat *src = cvCreateMat(grayCVImg->width, grayCVImg->height, grayCVImg->nChannels);
    
    cvConvert(grayCVImg, src);
    cvCanny(src, dst, 50, 200, 3);

`

however: first problem: I get an error: (-215) src.size == dst.size && src.channels() == dst.channels() in function cvConvertScale

next question would be: When i successfully did stuff with eg. cvCanny, how can I display the output? how do I convert dst back to a ofxCVImage?

thanks!

I think i got it myself:

IplImage* grayCVImg = grayImg.getCvImage();
IplImage* grayCVImg_out = grayImg.getCvImage();

cvCanny(grayCVImg, grayCVImg_out, 50, 200, 3);
testImg.allocate(grayImg.width, grayImg.height);
testImg = grayCVImg_out;

then calling testImg.draw(0,0);
draws the correct Canny edges. So conversion is as simple as “=”

btw: why isn’t ofxCV using the c++ API instead of the older C-API?

ofxOpenCv was written before the c++ api, so it represents an older way of thinking about opencv, managing memory alignment, storing multiple iplImages in one image object, etc. ofxCv is an alternative addon, which represents a more modern attempt to bidge OF and opencv:

@kylemcdonald and I have been discussing for a while now how to merge them, and it’s part of our roadmap to bring the internal cv addon to use the C++ api.

1 Like

Ah! I was obviously confusing ofxOpenCv with ofxCv. Thanks for the clarification!
And ofxCv is looking good and seems to fit my needs better.