Input: I have some 50000 points in a xy plane as shown in the below picture.
Now, I need to get all the possible points in a triangular ROI. How to get it. It can can be opencv or Matlab.
The below is the sample where I need to get the possible points of the triangular areas.
MATLAB has an
inpolygon
command: inpolygon.For example, this code
generates a picture like this:
Something like this, in c++?
for more info: http://docs.opencv.org/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html?highlight=pointpolygontest#pointpolygontest
here is OpenCV's example: http://docs.opencv.org/trunk/doc/tutorials/imgproc/shapedescriptors/point_polygon_test/point_polygon_test.html
In OpenCV, you can quickly filter out the points that are not in the minimal bounding rectangle for each triangle. This rectangle can be previously computed by hand or with cv::boundingRect(). The hit test is done with Rect::contains(). This is a fast operation (at least much faster than cv::pointPolygonTest)and this will filter out the points that are obviously not in any triangle. Afterward, you test the points that pass the filter with cv::pointPolygonTest().
That is: