本方法适用于扫描文件,或者是形状规则(四个角上的点)的物体图片的校正。
0.导入必要的包
import numpy as np
import argparse
import cv2
import imutils
1.边缘检测
首先对图像进行处理。
# 设置读取图片的路径
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", default="scan.jpg",
help = "Path to the image to be scanned") ## 这里修改为要扫描的图片的位置
args = vars(ap.parse_args())
# 加载原图 并对原图进行Resize
image = cv2.imread(args["image"])
ratio = image.shape[0] / 500.0
orig = image.copy()
image = imutils.resize(image, height = 500) #根据长宽比自动计算另外一边的尺寸进行resize
#根据处理找到边缘
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
gray = cv2.GaussianBlur(gray, (5, 5), 0)
edged = cv2.Canny(gray, 75, 200)
# show the original image and the edge detected image
print("STEP 1: Edge Detection")
cv2.imshow("Image", image)
cv2.imshow("Edged", edged)
cv2.waitKey(0)
cv2.destroyAllWindows()

2. 找到轮廓
# find the contours in the edged im
876



被折叠的 条评论
为什么被折叠?



