Note that there are some explanatory texts on larger screens.

plurals
  1. POSquare detection with aberrations in edges and 1 missing corner
    text
    copied!<p>This is a follow up to couple of <a href="https://stackoverflow.com/questions/8667818/opencv-c-obj-c-detecting-a-sheet-of-paper-square-detection">similar</a> <a href="https://stackoverflow.com/questions/10533233/opencv-c-obj-c-advanced-square-detection">questions</a> regarding square detection in which <a href="https://stackoverflow.com/users/176769/karlphillip">karlphillip</a>, <a href="https://stackoverflow.com/users/951860/mevatron">mevatron</a>, and <a href="https://stackoverflow.com/users/1134940/abid-rahman-k">abid-rahman-k</a> came up with some cool approaches.</p> <p>I am trying to design a robust square detection algorithm to help isolate a picture of a receipt from the rest of the image. My code is built off the convex hull approach from the previous questions but it's choking on an image where one of the points isn't in the image and the edges of the receipt have aberrations due to a pen holder on the left side. </p> <p>How can I detect the corners on this receipt?</p> <p>Here is the image:</p> <p><img src="https://i.imgur.com/RrYKJ.jpg" alt="image of receipt"></p> <p>Here is my code:</p> <pre><code>import cv2 import numpy as np img = cv2.imread('taco.jpg') img = cv2.resize(img,(1944,2592)) img = cv2.medianBlur(img,31) img = cv2.GaussianBlur(img,(0,0),3) grayscale = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) thresh = cv2.Canny(grayscale, 10, 20) thresh = cv2.dilate(thresh,None) contours,hier = cv2.findContours(thresh,cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE) for cnt in contours: if cv2.contourArea(cnt)&gt;250: # remove small areas like noise etc hull = cv2.convexHull(cnt) # find the convex hull of contour hull = cv2.approxPolyDP(hull,0.1*cv2.arcLength(hull,True),True) if len(hull)==4: cv2.drawContours(img,[hull],0,(0,255,0),2) cv2.namedWindow('output',cv2.cv.CV_WINDOW_NORMAL) cv2.imshow('output',img) cv2.cv.ResizeWindow('output',960,640) cv2.waitKey() cv2.destroyAllWindows() </code></pre> <p>Any ideas?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload