我正在 Openframeworks 中使用 OpenCV 来跟踪某种颜色。如果您不熟悉颜色跟踪代码,我的问题可能很困难,但我会尽力解释。
代码现在所做的是遵循带有红色圆圈的某种颜色,我正在努力创建一条基本相同的线,但每个点都将被存储,以便创建一种波浪形的绘图应用程序。现在它是一条可以拉的直线。
如有必要,我会发布更多代码。任何建议都会有帮助。谢谢!
测试应用程序.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);