0

I'm working with OpenCV within Openframeworks in order to track a certain colour. My question may be difficult if you are not familiar with the colour tracking code but I'll try to explain the best I can.

What the code does now is follow a certain colour with a red circle and I am working to create a line that does basically the same thing but each point will be stored so that a squiggly type of drawing application is created. Right now it's a straight line that you can pull.

I'll post more code if necessary. Any advice would really help. Thanks!

tespApp.cpp

void testApp::draw(){

ofSetColor(255,255,255);
//draw coloured cv image
rgb.draw(0,0);
contours.draw(0,480);

// draw line that follows the blobs

    for (int i=0; i<contours.nBlobs; i++) {
        ofSetColor(0);
       ofLine( contours.blobs[i].pos.x, contours.blobs[i].pos.y, contours.blobs[i].lastpos.x, contours.blobs[i].lastpos.y );

   }


}

ofxCvContourFinder.cpp


for( int i = 0; i < MIN(nConsidered, (int)cvSeqBlobs.size()); i++ ) {
    blobs.push_back( ofxCvBlob() );
    float area = cvContourArea( cvSeqBlobs[i], CV_WHOLE_SEQ, bFindHoles ); // oriented=true for holes
    CvRect rect = cvBoundingRect( cvSeqBlobs[i], 0 );
    cvMoments( cvSeqBlobs[i], myMoments );

    blobs[i].area                     = bFindHoles ? fabs(area) : area; // only return positive areas
    blobs[i].length                   = cvArcLength(cvSeqBlobs[i]);
    blobs[i].boundingRect.x           = rect.x;
    blobs[i].boundingRect.y           = rect.y;
    blobs[i].boundingRect.width       = rect.width;
    blobs[i].boundingRect.height      = rect.height;
    blobs[i].centroid.x               = (myMoments->m10 / myMoments->m00);
    blobs[i].centroid.y               = (myMoments->m01 / myMoments->m00);
             blobs[i].pos.x                    =0;
             blobs[i].pos.y                    =0;
             blobs[i].lastpos.x                = blobs[i].pos.x;
             blobs[i].lastpos.y                = blobs[i].pos.y;
             blobs[i].pos.x                    =(myMoments->m10 / myMoments->m00);
             blobs[i].pos.y                    = (myMoments ->m01 / myMoments->m00);
Joe Mastey
  • 26,809
  • 13
  • 80
  • 104
Andrea F
  • 733
  • 2
  • 9
  • 16
  • I don't see a question here. You should be more specific about what exactly you expect the code to do, and why it isn't doing what you expect. – Aurelius Jul 03 '13 at 15:09
  • I am trying to create a line that will follow the colour that is being tracked. My code is a straight line that will follow the chosen colour so I'm having difficult storing the blob positions properly so that instead of a straight line, you have one that can curve. Hopefully that's clearer. – Andrea F Jul 03 '13 at 15:30
  • Can you show your entire draw() method? It may be as simple as not clearing the canvas every frame... ? – jesses.co.tt Jul 03 '13 at 16:42
  • I'll edit my code. I haven't called a clear method so I'll try. – Andrea F Jul 03 '13 at 20:24
  • I can call contours.reset() which clears the blobs but then the line keeps disappearing and reappearing – Andrea F Jul 04 '13 at 07:02

1 Answers1

1

A complete example of what you are trying to achieve can be found in here:

https://github.com/kylemcdonald/ofxCv/tree/master/example-contours-color

It uses ofxCv, an add-on that let you integrate openframeworks with openCv in a clean way. Moreover you can use native OpenCV calls, without the need of any kind of wrapper. The internet is full of similar examples that uses pure OpenCV code and with this add ons you can use those snippets as it is, without any kind of problem and it gives some easy way to go from OpenCV data structures to Openframeworks ones and vice-versa. It is great!

nkint
  • 11,513
  • 31
  • 103
  • 174