Test whether pixel is inside the blobs for ofxOpenCV
Posted
by
mia
on Stack Overflow
See other posts from Stack Overflow
or by mia
Published on 2011-03-19T08:03:10Z
Indexed on
2011/03/19
8:09 UTC
Read the original article
Hit count: 272
openframeworks
I am doing an application of the concept of the dodgeball and need to test of the pixel of the ball is in the blobs capture(which is the image of the player) I am stucked and ran out of idea of how to implement it. I manage to do a little progress which have the blobs but I not sure how to test it. Please help. I am a newbie who in a desperate condition. Thank you.
This is some of my code.
void testApp::setup(){
#ifdef _USE_LIVE_VIDEO
vidGrabber.setVerbose(true);
vidGrabber.initGrabber(widthS,heightS);
#else
vidPlayer.loadMovie("fingers.mov");
vidPlayer.play();
#endif
widthS = 320;
heightS = 240;
colorImg.allocate(widthS,heightS);
grayImage.allocate(widthS,heightS);
grayBg.allocate(widthS,heightS);
grayDiff.allocate(widthS,heightS); ////<---what I want
bLearnBakground = true;
threshold = 80;
//////////circle//////////////
counter = 0;
radius = 0;
circlePosX = 100;
circlePosY=200;
}
void testApp::update(){
ofBackground(100,100,100);
bool bNewFrame = false;
#ifdef _USE_LIVE_VIDEO
vidGrabber.grabFrame();
bNewFrame = vidGrabber.isFrameNew();
#else
vidPlayer.idleMovie();
bNewFrame = vidPlayer.isFrameNew();
#endif
if (bNewFrame){
if (bLearnBakground == true){
grayBg = grayImage; // the = sign copys the pixels from grayImage into grayBg (operator overloading)
bLearnBakground = false;
}
#ifdef _USE_LIVE_VIDEO
colorImg.setFromPixels(vidGrabber.getPixels(),widthS,heightS);
#else
colorImg.setFromPixels(vidPlayer.getPixels(),widthS,heightS);
#endif
grayImage = colorImg;
grayDiff.absDiff(grayBg, grayImage);
grayDiff.threshold(threshold);
contourFinder.findContours(grayDiff, 20, (340*240)/3, 10, true); // find holes
}
////////////circle////////////////////
counter = counter + 0.05f;
if(radius>=50){
circlePosX = ofRandom(10,300);
circlePosY = ofRandom(10,230);
}
radius = 5 + 3*(counter);
}
void testApp::draw(){
// draw the incoming, the grayscale, the bg and the thresholded difference
ofSetColor(0xffffff); //white colour
grayDiff.draw(10,10);// draw start from point (0,0);
// we could draw the whole contour finder
// or, instead we can draw each blob individually,
// this is how to get access to them:
for (int i = 0; i < contourFinder.nBlobs; i++){
contourFinder.blobs[i].draw(10,10);
}
///////////////circle//////////////////////////
//let's draw a circle:
ofSetColor(0,0,255);
char buffer[255];
float a = radius;
sprintf(buffer,"radius = %i",a);
ofDrawBitmapString(buffer, 120, 300);
if(radius>=50)
{
ofSetColor(255,255,255);
counter = 0;
}
else{
ofSetColor(255,0,0);
}
ofFill();
ofCircle(circlePosX,circlePosY,radius);
}
© Stack Overflow or respective owner