我有1000张旧明信片,我想扫描,我认为使用某种自动裁剪/旋转工具优化我的工作流程可能是一个好主意,所以我开始用Python调查openCV.
你可以想象,我的目标是从这张图片中创建3张图片,每张图片包含一张明信片.我尝试了很多opencv选项,到目前为止我能够获得的最佳代码是:
import cv2, sys, imutils
cv2.namedWindow('image', cv2.WINDOW_NORMAL)
image = cv2.imread("sample1600.jpg")
ratio = image.shape[0] / 300.0
image = imutils.resize(image, height = 800)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
gray = cv2.GaussianBlur(gray, (5, 5), 0)
ret, th = cv2.threshold(gray,220,235,1)
edged = cv2.Canny(th, 25, 200)
(cnts, _) = cv2.findContours(edged.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
cnts = sorted(cnts, key = cv2.contourArea, reverse = True)[:5]
for c in cnts:
peri = cv2.arcLength(c, True)
approx = cv2.approxPolyDP(c, 0.05 * peri, True)
if len(approx) == 4:
cv2.drawContours(image, [approx], -1, (0, …Run Code Online (Sandbox Code Playgroud)