【问题标题】:ORB Demo code errors out with cv2.error: Unknown C++ exception from OpenCV codeORB 演示代码错误并出现 cv2.error: Unknown C++ exception from OpenCV code
【发布时间】:2021-05-13 21:36:16
【问题描述】:

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

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()

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

有人知道吗?

【问题讨论】:

  • 当我使用 ORB 时,我使用 cv2.ORB_create() 启动它

标签: python opencv visual-studio-code orb


【解决方案1】:

那个教程已经过时了。

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

正如 cmets 中提到的,它指出应该使用 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()

【讨论】:

    猜你喜欢
    • 2022-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-27
    • 1970-01-01
    • 1970-01-01
    • 2022-10-17
    相关资源
    最近更新 更多