如何在CV2中的图像上使用orb?

时间:2016-03-15 18:05:58

标签: python opencv opencv3.0 orb opencv3.1

我希望在28 * 28灰度图像(手写数字)上使用ORB(http://docs.opencv.org/3.1.0/d1/d89/tutorial_py_orb.html#gsc.tab=0),其中每个像素的数字从0到255.

这是我使用的代码:

# image = {load the array of 754 numbers}
orb = cv2.ORB_create()
image = image.reshape(28, 28))
kp = orb.detect(image, None)

但我一直收到这个错误:

OpenCV Error: Assertion failed (depth == CV_8U || depth == CV_16U || depth == CV_32F) in cvtColor, file /home/yahya/Documents/_other_downloaded_apps/opencv/modules/imgproc/src/color.cpp, line 7935
Traceback (most recent call last):
  File "/home/yahya/Documents/hello.py", line 118, in <module>
    kp = orb.detect(image, None)
cv2.error: /home/yahya/Documents/_other_downloaded_apps/opencv/modules/imgproc/src/color.cpp:7935: error: (-215) depth == CV_8U || depth == CV_16U || depth == CV_32F in function cvtColor

我该怎么做?我为什么会收到这个错误?

更新

我好像已经解决了这个问题的一部分。事实证明,orb接受float32号码(而不是64号)。

因此我更新了我的代码如下:

orb = cv2.ORB_create()
image = feature_x[0].reshape(28, 28).astype('float32')
kp = orb.detect(image, None)

但现在我有以下错误:

OpenCV Error: Assertion failed (scn == 3 || scn == 4) in ipp_cvtColor, file /home/yahya/Documents/_other_downloaded_apps/opencv/modules/imgproc/src/color.cpp, line 7456
Traceback (most recent call last):
  File "/home/yahya/Documents/hello.py", line 188, in <module>
    kp = orb.detect(image, None)
cv2.error: /home/yahya/Documents/_other_downloaded_apps/opencv/modules/imgproc/src/color.cpp:7456: error: (-215) scn == 3 || scn == 4 in function ipp_cvtColor

1 个答案:

答案 0 :(得分:2)

您尝试加载的图像不是orb的兼容类型。您应该在使用它之前先将其转换。如果你将它加载到numpy数组

,你也不需要reshape
orb = cv2.ORB_create()
image = image.astype(np.uint8, copy=False)
kp = orb.detect(image, None)