# All values are shifted

I have a method where i find blobs and calculate a angle.
In that method i output using:

``````
printf("a: %.3f\t%.3f\t\t%.3f\n", tang.angle, tang.centroid.x, tang.boundingRect.x);

``````

Which gives this:

``````
a: -1.585	689.356		605.000
a: 0.001	446.873		362.000
a: 2.858	1118.321		1036.000
a: -2.417	301.964		221.000
a: 0.778	805.566		729.000
a: -0.790	729.381		657.000
a: -1.571	185.957		111.000
a: -0.781	383.021		309.000
a: 0.097	989.214		915.000
a: 2.288	534.049		466.000

``````

Then directly after that method i excecute:

``````
vector<ofxDTangible> &tan = tangibleFinder->getTangibles();
for(int i = 0; i < tan.size(); i++ ) {
ofxDTangible &t = tan[i];

printf("i: %.3f\t%.3f\t\t%.3f\n", t.angle, t.centroid.x, t.boundingRect.x);

t.draw();
}

``````

which gives me:

``````

i: 0.000	689.356		605.000
i: -1.585	446.873		362.000
i: 0.001	1118.321		1036.000
i: 2.858	301.964		221.000
i: -2.417	805.566		729.000
i: 0.778	729.381		657.000
i: -0.790	185.957		111.000
i: -1.571	383.021		309.000
i: -0.781	989.214		915.000
i: 0.097	534.049		466.000

``````

Note that all angles (the first column) are shifted one row lower!

Here is the method that sets the angle:
(once more, directly after this the code from above is executed).

``````
int ofxDTangibleFinder::findTangibles(ofxCvGrayscaleImage& input) {

if(!checkForSetupCorrect()) {
return 0;
}

_tangibles.clear();

contourFinder.findContours(input, getMinRectArea(), getMaxRectArea(), getMaxTangibles(), false);

// from the blobs we found
// we need to check if the aspect ratio is about to be correct

for(int i = 0; i < contourFinder.nBlobs; i++) {
ofxCvBlob &blob = contourFinder.blobs.at(i);

float aspectRatio = min(blob.boundingRect.getWidth(), blob.boundingRect.getHeight()) / max(blob.boundingRect.getWidth(), blob.boundingRect.getHeight());

//printf("aspectRatio: %f\n", aspectRatio);

if (1 - aspectRatio < getMaxAspectDeviation()) {

ofxDTangible tang = ofxDTangible(blob);
_tangibles.push_back(tang);

// find the angle
if (_detectKnobs) {
ofRectangle &r = tang.boundingRect;
bool knobResult = knobAngleDetector->detect(input, r.getX(), r.getY(), r.getWidth(), r.getHeight());
if(knobResult) {
tang._isKnob = true;
//printf("angle: %f\n", knobAngleDetector->angle());
tang.angle = knobAngleDetector->angle();

printf("a: %.3f\t%.3f\t\t%.3f\n", tang.angle, tang.centroid.x, tang.boundingRect.x);

tang.draw();

}
}

}
}
printf("\n");

//printf("%lu\n", _tangibles.size());
return _tangibles.size();
}

``````

when you insert an object in a vector you are making a copy of it so in your last code you need to push_back after the if(detectKnobs) code or it won’t have any effect

Thanks. That’s different from java so it’s quite a easy mistake for me
I already fixed it by making a new method to figure out the knob. But it’s good that i also know now what was causing the problem.