I need to do a perspective transformation on an image section from newspaper, here the girl's image. The section's coordinates are given as rough estimates. I need to find the boundary of the section and do a perspective transformation. I had been referring the following link.
http://opencv-code.com/tutorials/automatic-perspective-correction-for-quadrilateral-objects/
However, Hough Transform and Convex Hull method on contour finding give jagged lines. This is how the edge detection on the section looks like.
edges = cv2.Canny(gray, 50, 150)
How can I improve the Canny Edge lines to make them straighter so jagged lines are removed? The Convex Hull finds the boundary but not with a number of smaller lines and the boundary is not complete. Here is how the Convex Hull method's boundary looks like.
contours, hierarchy = cv2.findContours(edges, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
for i, cnt in enumerate(contours):
if hierarchy[0,i,3] == -1 and cv2.contourArea(cnt)>5000:
hull = cv2.convexHull(cnt, returnPoints = True)
print "hull", hull
for tempodd, itemodd in enumerate(hull):
if tempodd % 2 == 0:
tempeven = tempodd
itemeven = itemodd
continue
cv2.line(img, (itemeven[0][0], itemeven[0][1]), (itemodd[0][0], itemodd[0][1]), (255,0,0), 4)
print "itemodd", itemodd, "itemeven", itemeven
Here since the Canny is getting jagged lines, the convex hull method gives multiple lines too. Point me where I am going wrong. Thank you.