繁体   English   中英

OpenCV python 错误 (-215) 照片找到 50% 的时间

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM