2017-10-01 11 views
0

ORB를 사용하여 이전에 생성 된 스펙트로 그램의 키포인트와 설명자를 찾으려고합니다. I 오류 얻고있다, 그러나opencv (파이썬)를 사용할 때 "orb.detectAndCompute"오류가 발생했습니다.

start = time.time() 
x = 1 
img = range(101) 
imgname = range(101) 

# Directory Images 
os.chdir("/home/undead/Documents/TempSongSpectro/") #1,2,3 
for file in glob.glob("*.png"): 
    img[x] = cv2.imread(file, 0) # trainImage 
    imgname[x] = os.path.splitext(file)[0] 
# print "%s: %d " % (os.path.splitext(file)[0],(x)) 
x = x + 1 

# Initiate ORB detector 
orb = cv2.ORB_create(3000) 

# find the keypoints and descriptors with ORB 
a = 1 
des = range(101) 
kp = range(101) 

for a in range(1, 101): 
    kp[a], des[a] = orb.detectAndCompute(img[a], None) 

end = time.time() 
print("Initialize time: %f seconds" % (end - start)) 

: 나는이 코드를 가지고 내가, 오류가 KP, DES 또는 IMG의 데이터 유형과 관련이있을 수 있습니다 수집 한 바로는

OpenCV Error: Assertion failed (depth == CV_8U || depth == CV_16U || depth == CV_32F) in cvtColor, file /home/undead/opencv/opencv-3.2.0/modules/imgproc/src/color.cpp, line 9710 

Traceback (most recent call last): 
    File "/home/undead/PycharmProjects/KavTest/Test3.py", line 37, in <module> 
    kp[a], des[a] = orb.detectAndCompute(img[a], None) 

cv2.error: /home/undead/opencv/opencv-3.2.0/modules/imgproc/src/color.cpp:9710: error: (-215) depth == CV_8U || depth == CV_16U || depth == CV_32F in function cvtColor 

을,하지만 난 ' 그것을 해결하는 방법에 대한 확신이 없습니다. 누군가 도움을 줄 수 있습니까?

답변

0

코드에 문제가 있다고 생각합니다.

이 코드는 거의 동일합니다.

start = time.time() 

imgnames = glob.glob("/home/undead/Documents/TempSongSpectro/*.png") 
#imgnames = imgnames[:100] 

sz = len(imgnames) 
imgs = list(range(sz)) 

for i, name in enumerate(imgnames, start=0): 
    imgs[i] = cv2.imread(name, 0) 

orb = cv2.ORB_create(3000) 

# find the keypoints and descriptors with ORB 
des = list(range(sz)) 
kp = list(range(sz)) 

for i in range(sz): 
    kp[i], des[i] = orb.detectAndCompute(img[i], None) 

end = time.time() 
print("Initialize time: {:.4f} seconds".format(end - start)) 
+0

이것은 문제를 해결 한 것으로 보입니다. 고맙습니다 :) – Undead