簡體   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