[SOLVED] cvAdd problem with ofxCvGrayscaleImage

Hello,

i am using a kinect to grab images and play with openCV to detect blobs.

My problem is i can’t make use of cvAdd. It compiles but crashes when attempting to use cvAdd.
It seems there is a problem converting ofxCvGrayscaleImage into iplImage. I thought ofxCvImage::getCvImage() was converting ofxCvGrayscaleImage to iplImage ? is it a bug ?

using oF 0.8.4 in Xcode 6

Maybe there is a workaround but i would prefer to use ofxGrayscaleImage.

or should i write my cvAdd method ?

here is the code :

// load grayscale depth image from the kinect source
depthImage.setFromPixels(kinect.getDepthPixels(), kinect.width, kinect.height);

// ---------- ROI -----------
ofRectangle roiMat = ofRectangle(roi.x, roi.y, roi.width, roi.height);
depthImage.setROI(roiMat);

// threshold
threshNear = depthImage;
threshFar = depthImage;
threshNear.threshold(nearThreshValue, true);
threshFar.threshold(farThreshValue);
cvAnd(threshNear.getCvImage(), threshFar.getCvImage(), depthImage.getCvImage(), NULL); // APP CRASH HERE

// update the cv images
depthImage.flagImageChanged();

//find blob in ROI
contourFinder.findContours(depthImage, minBlobSize, roi.width*roi.height, 1, false);

Hi,

when i disable use of ROI, it works fine.
other hint : when using ROI and when ROI is the size of original kinect image (here = depthImage) everything seems ok. As soon as i try to reduce the ROI size, app crashes.

So it seems i don’t use ROI correctly and that leads cvAnd to use images of different sizes so it makes the app crash.

do you have any advice ?

Ok, i wasn’t applying ROI to thresholded image so both images passed to cvAnd were not the same size.