天天看點

OpenCV算子,pointPolygonTest檢測點是否在輪廓内

opencv函數

pointPolygonTest:

C++: double pointPolygonTest(InputArray contour, Point2f pt, bool measureDist)

用于測試一個點是否在多邊形中

當measureDist設定為true時,傳回實際距離值。若傳回值為正,表示點在多邊形内部,傳回值為負,表示在多邊形外部,傳回值為0,表示在多邊形上。

當measureDist設定為false時,傳回 -1、0、1三個固定值。若傳回值為+1,表示點在多邊形内部,傳回值為-1,表示在多邊形外部,傳回值為0,表示在多邊形上。

// 視窗坐标轉換圖檔坐标
Point2f srcPt;
srcPt.x = pt.x()*srcSize.width()*1.0 / lbSize.width();
srcPt.y = pt.y()*srcSize.height()*1.0 / lbSize.height();
for (int i = 0; i < pointsresult5.size(); i++)
{
    if (pointPolygonTest(pointsresult5[i], srcPt, false) == 1)
    {
    strRate = QString::number(contourRate[i] * 100)+"%";
    break;
    }   
}      

繼續閱讀