close
cv::Mat img(cv::Size(800, 800), CV_8UC3);
// big region of interest (ROI)
Rect roi(100, 100, 400, 400);
rectangle(img, roi, Scalar(255, 0, 0), 1);
// some rectangles
vector<Rect> lpROIs;
lpROIs.push_back(Rect(30, 50, 100, 100));
lpROIs.push_back(Rect(420, 250, 100, 100));
lpROIs.push_back(Rect(150, 140, 100, 100));
lpROIs.push_back(Rect(300, 100, 100, 100));
lpROIs.push_back(Rect(250, 250, 100, 100));
lpROIs.push_back(Rect(300, 450, 100, 100));
// check out if the rectangle inside the ROI
for(int i=0; i<lpROIs.size(); i++)
{
// inside the ROI
if( (roi&lpROIs[i])==lpROIs[i] )
rectangle(img, lpROIs[i], Scalar(0,0,255), -1);
else
rectangle(img, lpROIs[i], Scalar(0,255,0), 1);
}
imshow("img", img);
waitKey();
Qt Demo: CheckRectangles
// check out if the rectangle inside the ROI
for(int i=0; i<lpROIs.size(); i++)
{
// inside the ROI
if( (roi&lpROIs[i])==lpROIs[i] )
{
rectangle(img, lpROIs[i], Scalar(0,0,255), -1);
}
else
{
auto a1 = (roi&lpROIs[i]).area();
auto a2 = lpROIs[i].area();
double ratio = (double)a1/(double)a2;
QString r = QString::number(ratio);
rectangle(img, lpROIs[i], Scalar(0,255,0), 1);
putText(img, r.toStdString(), lpROIs[i].tl(), FONT_HERSHEY_PLAIN, 1, Scalar(0,255,0), 1);
}
}
全站熱搜
留言列表