繁体   English   中英

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

[英]How to use orb on a image in CV2?

我希望在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

您尝试加载的图片与Orb不兼容。 您应该先将其转换后再使用。 另外,如果您将其加载到numpy数组中,也不需要reshape

orb = cv2.ORB_create()
image = image.astype(np.uint8, copy=False)
kp = orb.detect(image, None)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM