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

Discussão em 'Python' iniciado por Stack, Junho 23, 2025.

  1. Stack

    Stack Membro Participativo

    I have hard, messy Scanned Images with a noisy background as below [​IMG]

    I should figure the centered square and remove above noise. I mean cropping it as below. [​IMG]

    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)

    Continue reading...

Compartilhe esta Página