Hi,
Everything ran smoothly in my app before i decide to flip kinect image.
I read the kinect distance value and update a slider using ofxUI addon.
Before mirroring image, distance and slider value updated ok.
Since i use mirroring, distance and slider value seems to go crazy when blob getting close to frame limit.
a bit hard to explain. here is the update() code.
//--------------------------------------------------------------
void ofApp::update(){
kinect.update();
if(kinect.isFrameNew())
{
// load grayscale depth image from the kinect source
grayImage.setFromPixels(kinect.getDepthPixels(), kinect.width, kinect.height);
//grayImage.mirror(false, true);
//flippedDepthImg = grayImage;
// we do two thresholds - one for the far plane and one for the near plane
grayThreshNear = grayImage;
grayThreshFar = grayImage;
grayThreshNear.threshold(nearThreshold, true);
grayThreshFar.threshold(farThreshold);
// we then do a cvAnd to get the pixels which are a union of the two thresholds
cvAnd(grayThreshNear.getCvImage(), grayThreshFar.getCvImage(), grayImage.getCvImage(), NULL);
// update the cv images
grayImage.flagImageChanged();
// find contours which are between the size of 100 pixels and 1/2 the w*h pixels.
// also, find holes is set to false so we won't get interior contours...
contourFinder.findContours(grayImage, 100, (kinect.width*kinect.height)/2, 5, false);
}
if (contourFinder.nBlobs > 0)
{
pos = contourFinder.blobs.at(0).centroid;
dist = kinect.getDistanceAt(pos);
// update detected and effect state
ofxUILabel *sel = (ofxUILabel *)kinectInfos->getWidget("DETECTION");
sel->setLabel("ETAT : Presence active !");
sel = (ofxUILabel *)effectsPanel->getWidget("FX STATE");
sel->setLabel("ETAT : Actif !");
if (contourFinder.nBlobs > 2 && contourFinder.nBlobs < 3)
{
sendOsc("/vidMap/clip/next", 1);
}
sendOsc("/vidMap/fx/" + ofToString(effectNumber + 1), 1);
}
else
{
dist = 0;
pos = ofPoint(0,0);
// update detected and effect state
ofxUILabel *sel = (ofxUILabel *)kinectInfos->getWidget("DETECTION");
sel->setLabel("ETAT : Inactif");
sel = (ofxUILabel *)effectsPanel->getWidget("FX STATE");
sel->setLabel("ETAT : Inactif");
sendOsc("/vidMap/fx/" + ofToString(effectNumber + 1), 0);
}
cout << pos.x << "/" << pos.y << endl;
// update effect intensity slider value
ofxUISlider* slider = (ofxUISlider *)effectsPanel->getWidget("INTENSITE");
slider->setValue(ofMap(dist, 1100, 500, 1, 0));
// update effect variable 1 slider value with kinect position x
slider = (ofxUISlider *)effectsPanel->getWidget("VAR 1");
slider->setValue(ofMap(pos.x, 250, 500, 0, 1));
// update effect variable 2 slider value with kinect position y
slider = (ofxUISlider *)effectsPanel->getWidget("VAR 2");
slider->setValue(ofMap(pos.y, 285, 380, 0, 1));
if ( ofGetElapsedTimeMillis() - lastTimeCheck > timeOut)
{
if (effectNumber < 6)
{
effectNumber++;
}
else
{
effectNumber = 0;
}
ofxUIRadio *sel = (ofxUIRadio *)effectsPanel->getWidget("TYPE INTERFERENCE");
sel->activateToggle(effects.at(effectNumber));
lastTimeCheck = ofGetElapsedTimeMillis();
}
// Send OSC values
sendOsc("/vidMap/kinect/distance", ofMap(dist, 1100, 500, 1, 0));
sendOsc("/vidMap/kinect/x", ofMap(pos.x, 250, 500, 0, 1));
sendOsc("/vidMap/kinect/y", ofMap(pos.y, 285, 380, 0, 1));
}
//--------------------------------------------------------------
you can see the entire code here if needed :
https://github.com/martialgallorini/ofOscKinect
any clue ?
thanks a lot.