我有以下程序在前景對象上繪製邊界框。 這個邊界框將通過測量矩形一邊的長度來幫助按長度分類對象。用於分類的前景對象上的邊界矩形
現在,這隻能在一個對象上繪製一個矩形實例,我想讓它同時繪製它們。但我卡住了。需要指導或協助。請看附圖。
Rect boundingRect(InputArray contours);
// Finds the contour with the largest area
int area = 200;
int idx = 0;
for(int i=0; i<contours.size() ;i++)
{
if(area < contours[i].size())
idx = i;
}
//cout<< contours.size();
// Calculates the bounding rect of the largest area contour
Rect rect = boundingRect(contours[idx]);
Point pt1, pt2;
pt1.x = rect.x;
pt1.y = rect.y;
pt2.x = rect.x + rect.width;
pt2.y = rect.y + rect.height;
cout<< idx<< "\t \t";
// Draws the rect in the original image and show it
rectangle(frame_Original, pt1, pt2, CV_RGB(0,0,255), 2);
//cout << pt1; cout << pt2;
你的意思是你想繪製圖像中所有汽車的邊界框? –
如果你有所有的斑點,我認爲它會繪製所有的斑點。也許你已經以條件拒絕了其他人。 – Mzk
試試這個:http://docs.opencv.org/doc/tutorials/imgproc/shapedescriptors/bounding_rects_circles/bounding_rects_circles.html#bounding-rects-circles –