Contour + hough Transformation

asked 2019-04-22 13:42:36 -0600

Sky31 gravatar image

updated 2019-04-22 13:48:23 -0600

Hello folks,

currently, I'm working on a project where I have to detect a card let say "visiting card" so I used contour for that, the results are fine so to make the detection robust I was going through this paper This paper combine 2 approaches.

contour + hough transformation for robust results.

In this paper it's written that: used contour to detect closed boundaries of object and then transformed contour lines to hough coordinates to find intersected parallel line

Kindly provide me some solution to solve the problem

I detected the contour but I don't know how to transformed the contour lines to hough coordinates

here is my code:

gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
gray = cv2.bilateralFilter(gray,11, 17, 17)

edges = cv2.Canny(gray,50,110)
_,contours,_ = cv2.findContours(edges,cv2.RETR_CCOMP, cv2.CHAIN_APPROX_SIMPLE)

if len(contours)!=0:
   cv2.drawContours(gray, contours, -1, (255,0,0), 3)
   c = max(contours,key=cv2.contourArea)

   M = cv2.moments(c)

   cx = int(M['m10']/M['m00'])
   cy = int(M['m01']/M['m00']), (cx, cy), 7, (255, 255, 255), -1)

   cv2.putText(image,"centre",(cx - 20, cy - 20),cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 2)
   peri = cv2.arcLength(c, True)
   approx = cv2.approxPolyDP(c, 0.02 * peri, True)

   x,y,w,h = cv2.boundingRect(approx)


edit retag flag offensive close merge delete


I always like to draw the contour in some Mat and use the Hough Line Transform to find lines in that Mat. Then I can use a simple least square function to get the intersection point.

gino0717 gravatar imagegino0717 ( 2019-04-23 22:34:07 -0600 )edit