opencvpythonny

opencvpythonny,opencv,Opencv,我正试着画纸上的轮廓。就像-> 但每次我运行这段代码时,都会显示“NameError:name'screenCnt'未定义”错误。 我发现我的照片有一点差距。这使透镜的长度约为3。就像底部的图片一样。我怎样才能缩小大纲的差距。 为什么不只是对图像进行阈值处理,应用一些形态学来清理它呢。获得最大的轮廓。如何使用形态学填充间隙?你能给我一个示例代码吗?我建议你不要使用精明的边缘。为什么不只是对图像进行阈值处理,应用一些形态学来清理它呢。然后得到最大的轮廓线。 image = cv2.imread(

我正试着画纸上的轮廓。就像->

但每次我运行这段代码时,都会显示“NameError:name'screenCnt'未定义”错误。 我发现我的照片有一点差距。这使透镜的长度约为3。就像底部的图片一样。我怎样才能缩小大纲的差距。


为什么不只是对图像进行阈值处理,应用一些形态学来清理它呢。获得最大的轮廓。如何使用形态学填充间隙?你能给我一个示例代码吗?我建议你不要使用精明的边缘。为什么不只是对图像进行阈值处理,应用一些形态学来清理它呢。然后得到最大的轮廓线。
image = cv2.imread('example.jpg')
ratio = image.shape[0] / 500.0
orig = image.copy()
image = imutils.resize(image, height = 500)

gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
gray = cv2.GaussianBlur(gray, (3,3), 0)
edged = cv2.Canny(gray, 100, 200)
edge=  auto_canny(gray)

cnts = cv2.findContours(edged.copy(), cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
cnts = imutils.grab_contours(cnts)
cnts = sorted(cnts, key = cv2.contourArea, reverse = True)[0]

cnts = cv2.findContours(edged.copy(), cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
cnts = imutils.grab_contours(cnts)
cnts = sorted(cnts, key = cv2.contourArea, reverse = True)[:5]
# loop over the contours
for c in cnts:
    # approximate the contour
    peri = cv2.arcLength(c, True)
    approx = cv2.approxPolyDP(c, 0.02 * peri, True)
    # if our approximated contour has four points, then we
    # can assume that we have found our screen
    if len(approx) == 4:
        screenCnt = approx
        break
# show the contour (outline) of the piece of paper
print("STEP 2: Find contours of paper")
cv2.drawContours(image, [screenCnt], -1, (0, 255, 0), 2)
cv2.imshow("Outline", image)
cv2.waitKey(0)