2017-09-25 53 views
0

我想寫一個循環來處理我已經存儲在nd數組列表中的圖像。當我在磁盤上爲圖像寫入輸出時,我想從列表中獲取相應數組的索引以獲得唯一這是我想要做的:這是我想要做的:如何在Python中對數組列表中的位置進行索引?

orb = cv2.ORB() 
for i in feat_list: 
     x=cv2.imread(i) 
     kp1, des1 = orb.detectAndCompute(x,None) 
     y = cv2.drawKeypoints(x,kp1) 
     cv2.imwrite('D:\\diabetic\\feature\\output_orb\\featuredetect_%s.jpg'%feat_list.index(i),y) 
     print("Processing done for "),str(i) 
print("All pocessing done") 

這給了我一個錯誤,說數組的真值不明確。

+0

試試這個:print(「正在處理完成」,str(i))' – JJAACCEeEKK

+0

@ mihir-deshpande如果您覺得答案可以解決問題,請點擊綠色複選標記將其標記爲「接受」。這有助於將重點放在尚未有答案的舊版SO問題上。 –

回答

0

你可以做的是枚舉您的列表,以便有可用的索引和值(圖片):這裏

orb = cv2.ORB() 
for index, image in enumerate(feat_list): 
     x=cv2.imread(image) 
     kp1, des1 = orb.detectAndCompute(x,None) 
     y = cv2.drawKeypoints(x,kp1) 
     cv2.imwrite('D:\\diabetic\\feature\\output_orb\\featuredetect_{0}.jpg'.format(index),y) 
     print("Processing done for {0}".format(index)) 
print("All pocessing done") 

請注意,我用的字符串格式比使用C風格的字符串更Python格式。

+0

工作順利,謝謝@ Kent Sommer !!! –

相關問題