【发布时间】:2020-05-18 23:27:23
【问题描述】:
我是 python 新手,我创建了 anaconda 环境并运行给定的代码,但它显示错误
for c in cnts:
# approximate the contour
peri = cv2.arcLength(c, True)
approx = cv2.approxPolyDP(c, 0.02 * peri, True)
# our approximated contour should have four points
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(orig, [screenCnt], -1, (0, 255, 0), 2)
# apply the four point transform to obtain a top-down
# view of the original image
warped = four_point_transform(orig, screenCnt.reshape(4, 2) * ratio)
错误是
NameError Traceback(最近调用 最后)在 122#显示一张纸的轮廓(轮廓) 123 #print("第 2 步:查找纸的轮廓") --> 124 cv2.drawContours(orig, [screenCnt], -1, (0, 255, 0), 2) 125 126 # 应用四点变换以获得自顶向下
NameError:名称“screenCnt”未定义
但在代码中我已经定义了 screenCnt。最初,此代码运行正常,但现在无法正常工作或在每次交替执行后显示错误。 (它第一次运行正常,重新启动内核时出现同样的错误)。
或者如果我设置 screenCnt = 0 或 screenCnt = None 它给出错误
错误回溯(最近的调用 最后)在 123#显示一张纸的轮廓(轮廓) 124 #print("第 2 步:查找纸的轮廓") --> 125 cv2.drawContours(orig, [screenCnt], -1, (0, 255, 0), 2) 126 127 # 应用四点变换以获得自顶向下
错误:OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\imgproc\src\drawing.cpp:2509: 错误:(-215:断言失败)npoints > 0 in function 'cv::drawContours'
【问题讨论】:
标签: python python-3.x opencv jupyter-notebook anaconda