[英]OpenCV python error (-215) photo found 50% of time
使用 Opencv 3.1.0-dev,通過 OS X 終端運行的 python 2.7.3
我正在通過我制作的拼接程序運行圖像,並且效果很好。 我使用 argparse 來制作它,所以我只需要傳遞一個文件夾位置,它將使用該文件夾中的所有照片進行拼接。 我有兩個測試圖像,它工作得很好,並在不同的文件夾和不同數量的圖像中制作了一些其他示例並工作,但我現在遇到了一個問題,我收到了這個錯誤:
img1 = cv2.resize(cv2.imread(os.path.join(path,imagesToStitch[0]),1),imageSize)
cv2.error: /Users/chrisradford/opencv/modules/imgproc/src/imgwarp.cpp:3490: error: (-215) ssize.width > 0 && ssize.height > 0 in function resize.
這是我的代碼:
import os
import cv2
import argparse
from StitchingMaster import Stitcher
#initalize objects
stitcher = Stitcher()
ap = argparse.ArgumentParser()
ap.add_argument("-1", "--first", required=True)
args = vars(ap.parse_args())
#Define variables
imageSize = (1800,1200) #size of image to be passed to stitcher
showMatches = False #True if wish to see matches; False otherwise
keypoints = []
descriptors = []
resultImageSize = (1200,900) #Size of final image to be displated and saved
imagesToStitch = os.listdir(args["first"]) #list of images in folder
path = os.path.abspath(args["first"]) #Folder path
#----Base Case[0-1]----#
if len(imagesToStitch) < 2:
print "Not enough images to stitch"
quit()
#----Base Case[2]----#
else:
img1 = cv2.resize(cv2.imread(os.path.join(path,imagesToStitch[0]),1),imageSize)
img2 = cv2.resize(cv2.imread(os.path.join(path,imagesToStitch[1]),1),imageSize)
#result = stitched image
(result,keypoints,descriptors) = stitcher.stitch([img1,img2],showMatches,keypoints,descriptors)
錯誤出現在
else:
img1 = cv2.resize....
我制作了另一個程序,該程序在該位置打開圖像並調整其大小,並且運行良好。 當我使用os.path.abspath()
和os.listdir()
時,會os.path.abspath()
是文件夾的命名約定搞砸了?
非常感謝任何幫助。
經過進一步分析,我能夠確定問題在於:
os.listdir(args["first"])
此功能還可以提取隱藏文件。 由於我在 OS X 上運行,它也獲取了名為的隱藏文件:
.DS_Store
為了解決這個問題,我創建了一個簡單的 for 循環檢查器,它刪除任何以“.”開頭的文件。 從我的名單。
for files in fileList:
if not files.startswith('.'):
imagesToStitch.append(files)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.