How to detect Scanned Document Edges and Cropping it in Python?

I have hard, messy Scanned Images with a noisy background as below

I tried this code, but didn’t get the contours.

image = cv2.imread(r'Images\2.png')
orig = image.copy()
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
gray = cv2.GaussianBlur(gray, (5, 5), 0)
edged = cv2.Canny(gray, 75, 200)
cnts, hierarchy = cv2.findContours(
    edged.copy(), cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
contour_img = image.copy()
cv2.drawContours(contour_img, cnts, -1, (0, 255, 0), 2)

also posted on

https://stackoverflow.com/questions/79676878/how-to-detect-scanned-document-edges-and-cropping-it-in-python

Yeah I did, I’m trying to get faster answer :smiley: