0

I wish to use ORB (http://docs.opencv.org/3.1.0/d1/d89/tutorial_py_orb.html#gsc.tab=0) on a 28*28 grayscale image (handwritten digits), where each pixel has a number from 0 to 255.

This is the code I used:

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

But I keep getting this error:

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

How can I do this and why am I getting this error?

UPDATE

I seemed to have solved part of this problem. It turns out that orb accepts float32 numbers (not 64).

Therefore I updated my code as follows:

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

But now I have the following error:

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
Yahya Uddin
  • 26,997
  • 35
  • 140
  • 231
  • how are you creating the image? – Thesane Mar 15 '16 at 19:17
  • It's an image from the mnist data set: http://yann.lecun.com/exdb/mnist/index.html. I have not created it my self. It is simply an array of 784 (28*28) numbers between 0-255. Therefore when I reshape it, it makes a 28*28 matrix. – Yahya Uddin Mar 15 '16 at 19:26
  • I added an example image from my data set – Yahya Uddin Mar 15 '16 at 19:30
  • as far as I know ORB only accepts 8-bit grayscale image. I am not sure about the float32 (float32 is a valid opencv image type but I don't think it will work for orb). The error you are getting is because of number of channels in the image isn't 3 or 4. I think opencv check for this if the image is float32f – Thesane Mar 16 '16 at 18:59

1 Answers1

3

The image you are trying to load isn't compatible type for the orb. You should convert it first before using it. Also you don't need reshape if you are loading it into numpy array

orb = cv2.ORB_create()
image = image.astype(np.uint8, copy=False)
kp = orb.detect(image, None)
Thesane
  • 1,358
  • 10
  • 18