Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Contour + hough Transformation

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 http://vision.cs.uiuc.edu/~ddtran2/pubs/tlhdu_isimp04.pdf. 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'])
cv2.circle(image, (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)
print("approx",approx)

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

cv2.rectangle(image,(x,y),(x+w,y+h),(0,255,0),2)

cv2.imshow("moment",image)

cv2.waitKey(1)

cv2.destroyAllWindows()

Contour + hough Transformation

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 http://vision.cs.uiuc.edu/~ddtran2/pubs/tlhdu_isimp04.pdf. 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)

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

17) edges = cv2.Canny(gray,50,110)

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

cv2.CHAIN_APPROX_SIMPLE) if len(contours)!=0:

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'])
 cv2.circle(image, (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)
 print("approx",approx)

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

 cv2.rectangle(image,(x,y),(x+w,y+h),(0,255,0),2)


cv2.imshow("moment",image)
cv2.waitKey(1)
cv2.destroyAllWindows()

cv2.imshow("moment",image)

cv2.waitKey(1)

cv2.destroyAllWindows()

Contour + hough Transformation

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 http://vision.cs.uiuc.edu/~ddtran2/pubs/tlhdu_isimp04.pdf. 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'])
   cv2.circle(image, (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)
   print("approx",approx)

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

   cv2.rectangle(image,(x,y),(x+w,y+h),(0,255,0),2)


cv2.imshow("moment",image)
cv2.waitKey(1)
cv2.destroyAllWindows()