Home > other >  Python -- how to checkpoint is placed within the outline?
Python -- how to checkpoint is placed within the outline?

Time:12-11

I drew the outline of an extreme point around. Figure I have other point inside the polygon. How to check whether they are within the outline?

CodePudding user response:

You can use OpenCV provided in cv2. PointPolygonTest () function.
For example:
Dist=cv2. PointPolygonTest (CNT, (50, 50), True)
In this case, we check with contour coordinates (50, 50) CNT appear together
Dist to return one of the following three:
If this point is located in the contour, the positive & gt; If the outside contour, the point at which the negative & gt; If the point on the contour, zero
In the function cv2. PointPolygonTest (), the third parameter to decide whether to need to be one of the following two:
If it is True, then the dist return point or negative distance is distance, if it is located in the outline of the internal or external respectively. & gt; On the other hand, if set to False, it returns 1, 1 or 0, depending on is located in the internal, external or the points on the contour
For more information, please see THE DOCS
Inset:
I added an example to illustrate how it works. I consider the following outline image:

I assume the following for details:
(50; seven), (170152), (152) 13


Dist1=cv2. PointPolygonTest (contours [0], (50, 70), True)
Dist2=cv2. PointPolygonTest (contours [0], (170, 152), True)
Dist3=cv2. PointPolygonTest (contours [0], (152, 48), True)

Print (' dist1: 'dist1)
Print (' dist2: 'dist2)
Print (' dist3: 'dist3)

Output:

(' dist1: '45.17742799230607)
(49.9799959983992) 'dist2:'
(' dist3: '0.0)

CodePudding user response:

reference 1st floor response:
you can use OpenCV provided in cv2. PointPolygonTest () function.


The baby is a good answer!
  • Related