So, mirroring this topic
I believe to be encountering a similar issue with my program. Essentially I am mapping the x coordinate of the ofRectangle
object to the series of frames. My problem is this jerky, jittering between different elements in the array. What I mean is as I scroll along the x axis to cycle through array, different elements(images) are loaded than whats printed out. so, the result would be a consistent scroll with occasional random elements throughout the entire cycle.
i’ve made sure the datatypes are the same, but I am a bit unsure what I am overseeing here.
cpp below:
#include "testApp.h"
#include "ObjectFinder.h"
using namespace ofxCv;
using namespace cv;
void testApp::setup() {
ofDirectory dir;
int nFiles = dir.listDir("miko");
if(nFiles) {
for(int i=0; i<dir.numFiles(); i++) {
// add the image to the vector
string filePath = dir.getPath(i);
ofImage img;
images.push_back(ofImage(img));
images.back().loadImage(filePath);
}
}
else printf("Could not find folder\n");
ofSetVerticalSync(true);
//faces.load("haarcascade_frontalface_default.xml");
finder.setup("haarcascade_frontalface_default.xml");
finder.setPreset(ObjectFinder::Fast);
//we can now get back a list of devices.
vector<ofVideoDevice> devices = cam.listDevices();
for(int i = 0; i < devices.size(); i++){
cout << devices[i].id << ": " << devices[i].deviceName;
if( devices[i].bAvailable ){
cout << endl;
}else{
cout << " - unavailable " << endl;
}
}
//cam.setDeviceID(0);
cam.setDesiredFrameRate(60);
cam.initGrabber(320, 240);
}
void testApp::update() {
cam.update();
if(cam.isFrameNew()) {
finder.update(cam);
}
}
void testApp::draw() {
for(int i = 0; i < finder.size(); i++) {
ofRectangle object = finder.getObjectSmoothed(i);
// newX = object.x;
newX = object.getPositionRef().x;
}
newX = ofClamp(newX, 0, 150);
scaledX = ofMap(newX, 0,150, 0, 155);
float targetX = scaledX;
float dx = scaledX - x;
if(abs(dx) > 1) {
x += dx * easing;
}
cout << "x coordinate = " << x <<endl;
images[x].draw(0,0);
cam.draw(0, 0);
finder.draw();
ofDrawBitmapStringHighlight(ofToString(finder.size()), 10, 20);
//cout << "x coordinate" << cur.x;
}
and header:
#pragma once
#include "ofMain.h"
#include "ofxCv.h"
class testApp : public ofBaseApp {
public:
void setup();
void update();
void draw();
ofVideoGrabber cam;
ofxCv::ObjectFinder finder;
vector <ofImage> images;
float xPicVal;
float easing = 0.06;
int x;
int newX;
int scaledX;
};