Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to use polygonpointTest function for a polygon

I am trying to run polygonpoint test function for a polygon. My code looks something like below, does it only meant for coutours ?

import ast
import cv2
import numpy as np
point1 = (25, 50)
t = "201.94,191.31;158.20,343.59;520.55,361.55;469.79,175.70" # closed polygon 
pts = [*map(ast.literal_eval, t.split(';'))]
pts = np.array(pts)
cv2.pointPolygonTest(pts, point1, False)

I am getting below error

---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
<ipython-input-454-bfdc7e835e9b> in <module>
----> 1 cv2.pointPolygonTest(pts, point1, False)

error: OpenCV(4.3.0) /io/opencv/modules/imgproc/src/geometry.cpp:103: error: (-215:Assertion failed) total >= 0 && (depth == CV_32S || depth == CV_32F) in function 'pointPolygonTest'
click to hide/show revision 2
None

updated 2020-08-16 02:14:36 -0600

berak gravatar image

How to use polygonpointTest function for a polygon

I am trying to run polygonpoint test function for a polygon. My code looks something like below, does it only meant for coutours ?

import ast
import cv2
import numpy as np
point1 = (25, 50)
t = "201.94,191.31;158.20,343.59;520.55,361.55;469.79,175.70" # closed polygon 
pts = [*map(ast.literal_eval, t.split(';'))]
pts = np.array(pts)
cv2.pointPolygonTest(pts, point1, False)

I am getting below error

---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
<ipython-input-454-bfdc7e835e9b> in <module>
----> 1 cv2.pointPolygonTest(pts, point1, False)

error: OpenCV(4.3.0) /io/opencv/modules/imgproc/src/geometry.cpp:103: error: (-215:Assertion failed) total >= 0 && (depth == CV_32S || depth == CV_32F) in function 'pointPolygonTest'