0
votes

I was reading online and I found it's possible to tell if an image is pixelated or not based on the number of lines detected using an edge detector and then applying Hough transform.
I tried that method and the Hough transform doesn't seem to be detecting the lines properly I can't figure out why isn't it working properly.
Here are some result images for reference: The canny edge detection result

and the Hough Transform result


What can I do to improve the line detection?
The code I'm using to do this based on some online tutorials:

img = cv2.imread(image_path)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

high_thresh, thresh_im = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
lowThresh = 0.5*high_thresh
edges = cv2.Canny(img, lowThresh, high_thresh)

minLineLength = 200
maxLineGap = 10
lines = cv2.HoughLinesP(edges,1,np.pi/180,100,minLineLength,maxLineGap)
for x1,y1,x2,y2 in lines[0]:
    cv2.line(img,(x1,y1),(x2,y2),(0,255,0),2)

cv2.imshow('img',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
1
Instead of looking for edges, it can be very effective to detect squares with a perfectly constant color.Yves Daoust

1 Answers

1
votes
edges = cv2.Canny(gray,50,150,apertureSize = 3)
minLineLength = 200
maxLineGap = 10
lines = cv2.HoughLinesP(edges,1,np.pi/180,100,minLineLength,maxLineGap)
# edited this line
for line in lines:
    x1,y1,x2,y2 = line[0]
    cv2.line(image,(x1,y1),(x2,y2),(0,255,0),2)