我正在研究一个残缺的文档重建项目。首先,我尝试检测包含撕裂的文档碎片的图像边缘,然后尝试使用示例代码
通过检测到的边缘将图像裁剪为碎片import cv2
import numpy as np
img = cv2.imread("test.png")
img = cv2.imread("d:/test.jpeg")
cv2.imshow('Original Image',img)
new_img = cv2.Canny(img, 0, 505)
cv2.imshow('new image', new_img)
blurred = cv2.blur(new_img, (3,3))
canny = cv2.Canny(blurred, 50, 200)
## find the non-zero min-max coords of canny
pts = np.argwhere(canny>0)
y1,x1 = pts.min(axis=0)
y2,x2 = pts.max(axis=0)
## crop the region
cropped = new_img[y1:y2, x1:x2]
cv2.imwrite("cropped.png", cropped)
tagged = cv2.rectangle(new_img.copy(), (x1,y1), (x2,y2), (0,255,0), 3, cv2.LINE_AA)
cv2.imshow("tagged", tagged)
cv2.waitKey()
有人可以帮我裁剪破损的文档碎片并将它们分配给变量