rectangle, Contour detection with python3, opencv3
rectangle, Contour detection with python3, opencv3 I want to detect paper sheet from image. i applied medianBlur, Canny , dilate, threshold, etc. algorithms to find.i am able to find sheet but don't know how to crop rectangle and apply transformation answer sheet This my code import numpy as np import cv2 image = cv2.imread('im_1.jpg') image = cv2.resize(image, (800, 600)) draw = np.zeros_like(image) gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) ret, thresh = cv2.threshold(gray, 127, 255, cv2.THRESH_BINARY) kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (3, 3)) thresh = cv2.erode(thresh, kernel, iterations=4) thresh = cv2.dilate(thresh, kernel, iterations=4) im, cnts, hier = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) max_area = -1 max_c = 0 for i in range(len(cnts)): contour = cnts[i] area = cv2.contourArea(contour) if (area > max_area): max_area = area max_c = i contour = cnts[max_c] rect = cv2.minAreaRect(contour) ...