在做图片提取的时候发生了报错,查了好多说是图片读取路径有中文,看了一下发现我的路径也确实有中文,(图片为了方便就放在桌面上)。但是改了路径之后依然报错,仔细检查才发现是二点图片格式不对,保存到电脑格式是jpg.但原程序读取的是png.改了之后就可以正确运行。
# import the necessary packages
import matplotlib.pyplot as plt
import imutils
from imutils import perspective
import numpy as np
import cv2
# load the notecard code image, clone it, and initialize the 4 points
# that correspond to the 4 corners of the notecard
notecard = cv2.imread("../image/notecard.png")
clone = notecard.copy()
pts = np.array([(73, 239), (356, 117), (475, 265), (187, 443)])
# loop over the points and draw them on the cloned image
for (x, y) in pts:
cv2.circle(clone, (x, y), 5, (0, 255, 0), -1)
# apply the four point tranform to obtain a "birds eye view" of
# the notecard
warped = perspective.four_point_transform(notecard, pts)
# show the original and warped images
cv2.imshow("Original", clone)
cv2.imshow("Warped", warped)
plt.figure("Original opencv2matplotlib")
plt.imshow(imutils.opencv2matplotlib(clone))
plt.show()
cv2.waitKey(0)