Can't convert an ofTexture to CV compatible Mat with OpenGL ES


#1

Curious what the solution might be to this, or if there is just another route I should go.

I am starting to experiment with ARKit (ofxARKit) and OpenCV (ofxCv), and immediately I came to an issue. To pass the camera input to OpenCV, I need to get a Mat from it. I immediately attempted this:

ofTexture tex = processor->getCameraTexture();
tex.readToPixels(pix);
img.setFromPixels(pix); 
Mat cam = toCv(img);
contourFinder.findContours(cam);

This doesn’t work, which seems to be because ofTexture::readToPixels() isn’t compatible with OpenGL ES, as stated in the documentation.

So what is the best way to make a texture usable with OpenCV on iOS?


#2

not sure how this works on ios but can’t you call video.getPixels() instead of getTexture()


#3

I am now able to access the texture with:

ofFbo fbo = processor->getFBO();
        
ofImage img;
img.allocate(ofGetWidth(), ofGetHeight(), OF_IMAGE_COLOR);
        
fbo.readToPixels(pix);
img.setFromPixels(pix);

It doesn’t appear to me that there is any method I can use to just get ofPixels from ofxARKit, but it does actually appear that ofFBO::readToPixels() works with OpenGL ES. I’d imagine if I was using ofVideoGrabber, I could have used getPixels(), but for now this should work.