ORB 演示代码出现 cv2.error 错误:来自 OpenCV 代码的未知 C++ 异常

Wur*_*rmD 4 python opencv orb visual-studio-code

ORB 演示代码位于https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_feature2d/py_orb/py_orb.html

import numpy as np
import cv2
from matplotlib import pyplot as plt

img = cv2.imread('simple.jpg',0)

# Initiate STAR detector
orb = cv2.ORB()

# find the keypoints with ORB
kp = orb.detect(img,None)

# compute the descriptors with ORB
kp, des = orb.compute(img, kp)

# draw only keypoints location,not size and orientation
img2 = cv2.drawKeypoints(img,kp,color=(0,255,0), flags=0)
plt.imshow(img2),plt.show()
Run Code Online (Sandbox Code Playgroud)

kp = orb.detect(img,None)

  • 在Python3.6中出现错误[WinError 10054] An existing connection was forcibly closed by the remote host
  • 在Python3.8中出现错误cv2.error: Unknown C++ exception from OpenCV code

笔记:

  • 在 Python 3.6 中,在终端中运行或在调试器中运行,只需退出脚本而不会出现错误。仅当在调试器中停止kp = orb.detect(img,None)并在调试器中运行该行时,才会出现错误[WinError 10054] An existing connection was forcibly closed by the remote host
  • 在Python 3.8中,在终端或调试器中运行会出现错误cv2.error: Unknown C++ exception from OpenCV code

环境: Windows 10、Python 3.6、VSCode

有人有线索吗?

Wur*_*rmD 5

该教程已经过时了。

更新版本现在位于 OpenCV 网站本身:https ://docs.opencv.org/master/d1/d89/tutorial_py_orb.html

正如评论中提到的,其中指出初始化应该通过以下方式完成orb = cv.ORB_create()

import numpy as np
import cv2 as cv
from matplotlib import pyplot as plt
img = cv.imread('simple.jpg',0)
# Initiate ORB detector
orb = cv.ORB_create()
# find the keypoints with ORB
kp = orb.detect(img,None)
# compute the descriptors with ORB
kp, des = orb.compute(img, kp)
# draw only keypoints location,not size and orientation
img2 = cv.drawKeypoints(img, kp, None, color=(0,255,0), flags=0)
plt.imshow(img2), plt.show()
Run Code Online (Sandbox Code Playgroud)