Ask Your Question

demon's profile - activity

2019-03-22 08:11:56 -0600 received badge  Notable Question (source)
2017-10-25 12:52:27 -0600 received badge  Popular Question (source)
2012-08-16 07:27:17 -0600 received badge  Supporter (source)
2012-08-16 07:25:21 -0600 received badge  Scholar (source)
2012-08-16 07:25:04 -0600 commented answer pointPolygonTest is not working properly

yeees, thank you very much. because the numpy horizontal and vertical index are reversed, i incorrectly calculated the distance in pointPolygonTest. Correct code: dist[ind_y,ind_x] = cv2.pointPolygonTest(contours[0],(ind_x,ind_y),True) and cv2.circle(image,maxLoc,int(maxVal),cv.CV_RGB(0, 255, 0),1, cv.CV_AA,0)

2012-08-16 06:38:24 -0600 commented answer pointPolygonTest is not working properly

i tested on opencv 2.3.1, 2.4 and now tested on 2.4.2 - the result did not change. and i painted what contour i tested. maybe it's a bug.

2012-08-16 04:07:57 -0600 received badge  Student (source)
2012-08-16 03:40:17 -0600 commented answer pointPolygonTest is not working properly

in python with your flag and padding image the same result are not obtained

2012-08-16 03:14:22 -0600 commented answer pointPolygonTest is not working properly

thanks for the answer, i am not yet try your code on c++.

before post a question, i tried to add padding to the image (in the image editor) - nothing changed.

i also tried different flags in findContours (i was looking for holes, but here i posted a simplified code), and external contour was in index 0.

i will try to do on C + + your example, but on Python I did it and it not help

2012-08-16 01:12:42 -0600 received badge  Editor (source)
2012-08-16 01:06:26 -0600 commented question pointPolygonTest is not working properly

code is not too big, but i use python

2012-08-16 00:48:08 -0600 commented answer pointPolygonTest is not working properly

Yes, i test all pixels of the image and check inside or outside of contour, then choose maximum distance.

2012-08-15 20:19:14 -0600 asked a question pointPolygonTest is not working properly

I used pointPolygonTest for finding the maximum radius of the inscribed circle in the shape. For the same figure, depending on the turn to 90-180-270 degrees obtained different results. Have any ideas? image description image description


# -*- coding: utf-8 -*-
import cv2
import cv2.cv as cv
import numpy as np

image=cv2.imread('1.png')
image_bin=cv2.cvtColor(image,cv2.COLOR_RGB2GRAY)
retval,image_bin=cv2.threshold(image_bin,254,255,cv2.THRESH_BINARY_INV)
contours, hierarchy = cv2.findContours(image_bin.copy(),cv2.RETR_CCOMP , cv2.CHAIN_APPROX_SIMPLE)
image_with_contour=np.zeros(image.shape, np.uint8)
dist=np.zeros((image.shape[0],image.shape[1]))
cv2.drawContours(image_with_contour,contours,-1,(255,255,255),1, cv2.CV_AA)

for ind_y in range(image.shape[0]):
    for ind_x in range(image.shape[1]):
        dist[ind_y,ind_x] = cv2.pointPolygonTest(contours[0],(ind_y,ind_x),True)

minVal, maxVal, minLoc, maxLoc = cv2.minMaxLoc(dist)
cv2.circle(image,(maxLoc[1],maxLoc[0]),int(maxVal),cv.CV_RGB(0, 255, 0),1, cv.CV_AA,0)

cv2.imshow('original', image)
cv2.imshow('contour', image_with_contour)

cv2.waitKey(0)
cv2.destroyAllWindows()