如何检测点是否位于一系列点内

时间:2015-04-30 12:45:00

标签: opencv image-processing

我有一个主要的灰度图像,我把它分成了内部 - Activeregion和outside-ActiveRegion

outSide-ActiveRegion距离顶部,底部,右侧,左侧3个像素。其余的是内部 - 活动区域。让我们假设我有下面的图像,我想根据我对outSideActiveRegion的定义来检测31.00001 x = 2,y = 0是否在活动区域​​内

25.999985, 26.999994, 31.00001, 39.000046, 53.000084, 71.000038, 80.999962, 
78.999931, 71.999954;
23.999996, 26.000015, 32.000023, 45.000038, 64.000046, 76.000031, 76.000023, 
70.000015, 65.000023;
21.000031, 29.000027, 39.000027, 61.000008, 85.999985, 88.999992, 75.000023, 
64.000031, 63.000023;
26.000048, 39.000027, 53, 78.999962, 104.99993, 100.99995, 79, 67.000015,   
68.000023;
44.000015, 56.000004, 67.999992, 86.999969, 105.99995, 100.99998, 82.000023, 
74.000038, 77.000031;
66.999962, 73.999969, 78.999985, 86, 96.000023, 96.000038, 90.000053,   
90.000046, 94.000046;
79.999969, 83.999969, 85.999992, 87.000015, 92.000031, 102.00002, 112.00001,   
117.99999, 122.99999;
82.999985, 86.999985, 90.999992, 92.000008, 97.000031, 115.00001, 134.99995, 
142.99997, 148.99995;
82.000015, 85.000008, 93.999969, 100.99993, 109.9999, 128.99989, 148.99989,  
159.99988, 161.99989

更新

内部 - 活动区域从3,3到((宽度-1)-3),((高度-1)-3)。其余的是outSide-ActiveRegion

opencv中是否有任何函数可以检测某个点是否在一系列点内?

1 个答案:

答案 0 :(得分:3)

测试点是否在轴对齐矩形中的最简单方法是首先测试它是否

bool PointInRect(int left, int top, int right, int bottom, int x, int y)
{
    if (x < left || x > right || y < top || y > bottom)
        return false;
    else
        return true;
}

或者,当您使用OpenCV时,您可以创建合适的cv::Rect并使用contains方法:

cv::Rect pRect(left, top, width, height);

cv::Point pPoint(x, y);

if (pRect.contains(pPoint))
{
    // do whatever ....
}