Resized ofImage for faceTracking? (FBO -> ofImage -> FaceTracking)

for faceTracking, high resolution video is low performance. so usually using low resolution image. right?
but I want to display high resolution image, with fast facetracking.

so I tried this way…

  1. get pixels from cam
  2. drawing in FBO in half size
  3. readPixels from FBO to half size ofImage,
  4. facetracning with resized ofImage.

but I got runtime error…
OpenCV Error:Assertion failed (size.area()>0) in resize

OpenCV Error: Assertion failed (ssize.area() > 0) in resize, file /Users/danielrosser/Documents/openFrameworks/scripts/apothecary/build/opencv/modules/imgproc/src/imgwarp.cpp, line 1834
libc++abi.dylib: terminating with uncaught exception of type cv::Exception: /Users/danielrosser/Documents/openFrameworks/scripts/apothecary/build/opencv/modules/imgproc/src/imgwarp.cpp:1834: error: (-215) ssize.area() > 0 in function resize

I thought it’s because use ofImage. so I tried another ofImage camImg… and get pixels from cam(ofVideoGrabber).
and it works…

I’m wondering what is the problem? as error let me know it related with cv.resize… but I didn’t get it.

cv::resize(gray,small_img_,cv::Size(w,h),0,0,CV_INTER_LINEAR);        <-Thread 1 : signal SIGABRT

anyone help? or other solution for that?

here’s my code… and you can get my Xcode project from here.
before you need to download ofxFaceTracker addon.

#include "ofApp.h"

using namespace ofxCv;

void ofApp::setup() {
	
	camWidth = 1280;
	camHeight = 800;
	cam.initGrabber(camWidth, camHeight);
	tracker.setup();
	
	camImg.allocate(camWidth, camHeight, OF_IMAGE_COLOR);			// ofImage camImg    - full size (for testing)
	copiedImg.allocate(camWidth/2, camHeight/2, OF_IMAGE_COLOR);	// ofImage copiedImg - half size
	fbo.allocate(camWidth/2, camHeight/2);							// ofFbo fbo         - half size
}

void ofApp::update() {
	ofSetWindowTitle(ofToString(ofGetFrameRate()));
	cam.update();
	if(cam.isFrameNew()) {
		camImg = cam.getPixels();					// dump cam -> camImg
		
		// fill FBO
		fbo.begin();
		cam.draw(0,	0, camWidth/2, camHeight/2);	// draw half size 
		fbo.end();
		
		fbo.readToPixels(pix);
		copiedImg.setFromPixels(pix);
		copiedImg.update();					// need to this ??
		
//		tracker.update(toCv(cam));			// tracking with ofVideoGrabber.. work.
//		tracker.update(toCv(camImg));		// tracking with ofImage..  work.
		tracker.update(toCv(copiedImg));	// OpenCV Error: Assertion failed (ssize.area() > 0) in resize,
	}
}

void ofApp::draw() {
    ofSetColor(255);
	cam.draw(0, 0);
	ofSetLineWidth(2);
	tracker.draw();
    ofPolyline noseBase = tracker.getImageFeature(ofxFaceTracker::NOSE_BASE);
    ofSetColor(ofColor::red);
    noseBase.draw();
    ofDrawCircle(noseBase.getCentroid2D(), 8 * tracker.getScale());
	ofDrawBitmapString(ofToString((int) ofGetFrameRate()), 10, 20);
}

void ofApp::keyPressed(int key) {
	if(key == 'r') {
		tracker.reset();
	}
}

a friend of mine check this example and it worked with his machine.
so I think something problem with CV related library in my mac…

not worked.

BBABBAM~ I came here.

CV was not weird.

Problem was “ofImageType” of “pix” on your code.
Fbo imageType is “ofImageType::OF_IMAGE_COLOR_ALPHA”.

But CV’s detector not want this type.

You can find why it is :

// part of "ofxFaceTracker.cpp" //
bool ofxFaceTracker::update(Mat image) {	
...
	
	if(im.type() == CV_8UC3) {
		cvtColor(im, gray, CV_RGB2GRAY);
	} else if(im.type() == CV_8UC1) {
		gray = im;
	}
...

So, try to change “ofImageType” before “tracker.update(…)”.

// part of your code //

		fbo.begin();
		cam.draw(0,	0, camWidth/2, camHeight/2);	// draw half size 
		fbo.end();
		
		fbo.readToPixels(pix);
//		copiedImg.setFromPixels(pix);  // this line is needless. may be.
//		copiedImg.update();					// need to this ?? -> don't need this.

//This is exactly what I say.
		pix.setImageType(ofImageType::OF_IMAGE_GRAYSCALE); // or OF_IMAGE_COLOR
// But GRAYSCALE help for performance, I think.


		tracker.update(toCv(pix));	// OpenCV Error: Assertion failed (ssize.area() > 0) in resize,
// you can use ofPixels directly.

It will be working clearly.

1 Like

thanks!!! now it works.