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

image

 

// 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);
   }
}
 

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 me1237guy 的頭像
    me1237guy

    天天向上

    me1237guy 發表在 痞客邦 留言(0) 人氣()