Hough lines and Convex Hull methods give jagged lines 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)&gt;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.
Let's go step by step.


First of all you can remove perspective distortion without camera calibration. e.g. 


  Robust Radial Distortion from a Single Image, Faisal Bukhari and Matthew N. Dailey
  
  Robust Line Based Calibration of Radial Distortion from a Single View, Thorsten Thormahlen, Hellward Broszio, Ingolf Wassermann

For any given image, Hough transform might find multiple lines, many of those would be an indicator of the same edge. But luckily you could easily merge the lines which overlap. To detect the overlap you could well use the angle between the lines and the distance of lines. This way, you obtain a clustering of the lines. In any case, finding a short line on each edge would be sufficient for you to recover the projective quad.
If you are always sure that the orientation of this quad is more or less fronto parallel, then you could as well use directed gradients (X or Y) to emphasize the vertical or horizontal lines, during the edge detection step. 


I agree with the other comments on Gaussian smoothing and anti aliasing. I would not recommend the use of convex hulls though, as they are very noise sensitive.