使用 Opencv 3.1.0-dev,python 2.7.3 通过 OS X 终端运行
我正在通过自己制作的拼接程序运行图像,效果很好。我使用 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.listdir(args["first"])
此功能还可以提取隐藏文件。由于我在 OS X 上运行,它还提取了名为的隐藏文件:
.DS_Store
为了解决这个问题,我创建了一个简单的 for 循环检查器,用于删除任何以“.”开头的此类文件。从我的列表中。
for files in fileList:
if not files.startswith('.'):
imagesToStitch.append(files)
关于python - OpenCV python 错误 (-215) 照片找到 50% 的时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41666634/