我正在使用Visual C ++ 2010 Express和OpenCV,我正试图跟踪两只手。到目前为止,我已经有了convexHull和convexityDefects,但是我在获取convexHull的点时遇到了麻烦。我想用它们从每只手的中心画一条线(我已经可以用线画出一条线)到每个凸形点,然后我就可以添加过滤器了,所以它只选择手指的那些。这没问题,我只需要将船体点变成绘图功能的工作格式。我的代码目前看起来像这样:
findContours(temp,Lcontours,hierarchy,CV_RETR_CCOMP,CV_CHAIN_APPROX_SIMPLE );
vector<vector<int> >hullI( Lcontours.size() );
vector<vector<Point> >hullP( Lcontours.size() );
vector<vector<Vec4i>> defects( Lcontours.size() );
std::sort(Lcontours.begin(), Lcontours.end(),compare_contour_areas);
for( int f = 0; f < Lcontours.size(); f++ ){
convexHull( Mat(Lcontours[f]), hullI[f], true );
convexHull( Mat(Lcontours[f]), hullP[f], true );
convexityDefects(Lcontours[f],hullI[f],defects[f]);
drawContours(cameraFeed(lefT), Lcontours, 0, Scalar(0,200,200), 1.5, 8, vector<Vec4i>(), 0, Point() );
drawContours(cameraFeed(lefT), hullP, 0, Scalar(200,200,0), 1.5, 8, vector<Vec4i>(), 0, Point() );
如何转换船体矢量(无论是哪一个,hullI用于int或hullP用于点格式),我可以说“打印船体的x和y [f]”。到目前为止它似乎像船体[?] [?] [?] [?],因为它是矢量中的矢量或什么?这是否与convexHull函数的结尾有关,其中最后一个参数是true还是false?
答案 0 :(得分:0)
for( int f = 0; f < Lcontours.size(); f++ ){
convexHull( Mat(Lcontours[f]), hullI[f], true );
convexHull( Mat(Lcontours[f]), hullP[f], true );
vector <Point> thisHull(hullP[f].size());
thisHull=hullP[f]; //which hull you want to look at
int pointYouWant; //point you want to interrogate
cout<<"for hull #"<< f << ", point #" << pointYouWant << " , x= " << thisHull[pointYouWant].x << " , y= " << thisHull[pointYouWant].y << endl;
}