Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ORB Demo code errors out with cv2.error: Unknown C++ exception from OpenCV code

ORB Demo code at 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()

at kp = orb.detect(img,None)

  • in Python3.6 errors out with [WinError 10054] An existing connection was forcibly closed by the remote host
  • in Python3.8 errors out with cv2.error: Unknown C++ exception from OpenCV code

Note:

  • In Python 3.6, running in the terminal, or running in the debugger, simply exits the script with no error. Only when stopping at kp = orb.detect(img,None) in the debugger and running that line in the debugger does the error appear [WinError 10054] An existing connection was forcibly closed by the remote host
  • In Python 3.8, running in terminal or the debugger gives the error cv2.error: Unknown C++ exception from OpenCV code

Environment: Windows 10, Python 3.6, VSCode

Does anyone have a clue?

like image 955
WurmD Avatar asked Oct 26 '25 18:10

WurmD


1 Answers

That tutorial is outdated.

The updated version is now in OpenCV site itself: https://docs.opencv.org/master/d1/d89/tutorial_py_orb.html

which, as mentioned in comments, states that initialization should be done with 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()
like image 171
WurmD Avatar answered Oct 28 '25 06:10

WurmD