有没有人有任何使用 OpenCV/C++ 跟踪多种颜色的例子?我发现了一些 python 但还没有 C++。我设法使用以下方法跟踪黄色:
IplImage *imgHSV= cvCreateImage (cvGetSize(img),8,3);
cvCvtColor(img,imgHSV,CV_BGR2HSV);
IplImage*imgThreshed =cvCreateImage(cvGetSize(img),8,1);
//track yellow
cvInRangeS(imgHSV,cvScalar(20,100,100), cvScalar(30,255,255), imgThreshed);
//saved the points
double area=cvGetCentralMoment(moment, 0, 0);
double moment10=cvGetSpatialMoment(moment, 1, 0);
double moment01=cvGetSpatialMoment(moment, 0, 1);
我正在尝试通过以下方式对蓝色做类似的事情:
cvInRangeS(imgHSV,cvScalar(100,100,100), cvScalar(120,255,255), imgblue);
然后保存积分:
double area1=cvGetCentralMoment(moment1, 0, 0);
double moment05=cvGetSpatialMoment(moment1, 1, 0);
double moment02=cvGetSpatialMoment(moment1, 0, 1);
//画线
static int posF=0;
static int posE=0;
posE=moment05/area1;
posF=moment02/area1;
int lastF=posF;
int lastE=posE
if (lastF>=0 && lastE>=0 && posF>=0 && posE>=0){
cvLine(imgScribble, cvPoint(posF,posE),cvPoint(lastF,lastE), cvScalar(255,0,0),16);
}
蓝色的点是我遇到的麻烦。关于跟踪多种颜色和保存点的任何建议?![黄线跟踪黄色,蓝点代表蓝色,但它们也应该是第1行