我正在尝试从一堆图像创建全景图,因此从 github 下载了一个存储库。现在,当我运行程序时,我不知道为什么,但是 python 崩溃了,我的终端出现了分段错误。我目前正在 pycharm 上运行它。我的所有图像都已加载,然后崩溃,然后显示错误。我想从视频文件或长场景的一堆帧创建全景图。在这个程序中。我只是想读取那个文件夹中的文件,然后开始一个一个地拼接它们以获得最终图像。
这是错误
INFO:root:从 /Users/akshayacharya/Desktop/Panorama/Raw Data/Office data/frame030.png 读取图像 信息:root:从 /Users/akshayacharya/Desktop/Panorama/Raw Data/Office data/frame024.png 读取图像
zsh:分段错误 python3 image_stitching.py --display
I have attached a snapshot of my screen as well for reference
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'Will Brennan'
# Built-in Modules
import os
import argparse
import logging
import cv2
import helpers
from combine import combine_images
from helpers import *
from matching import compute_matches
if __name__ == '__main__':
parser = argparse.ArgumentParser(description=__doc__)
#parser.add_argument('image_paths',type=str,nargs='+',help="paths to one or more images or image directories")
parser.add_argument('-b','--debug',dest='debug',action='store_true',help='enable debug logging')
parser.add_argument('-q','--quiet',dest='quiet',help='disable all logging')
parser.add_argument('-d','--display',dest='display',help="display result")
parser.add_argument('-s','--save',dest='save',help="save result to file")
parser.add_argument("--save_path",dest='save_path',default="stitched.png",help="path to save result")
parser.add_argument('-k','--knn',dest='knn',default=2,type=int,help="Knn cluster value")
parser.add_argument('-l','--lowe',dest='lowe',default=0.7,type=float,help='acceptable distance between points')
parser.add_argument('-m','--min',dest='min_correspondence',default=10,help='min correspondences')
args = parser.parse_args()
if args.debug:
logging.basicConfig(level=logging.DEBUG)
else:
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("main")
logging.info("beginning sequential matching")
print(cv2.__version__)
#if helpers.is_cv2():
sift = cv2.SIFT()
#elif helpers.is_cv3():
#sift = cv2.xfeatures2d.SIFT_create()
#else:
#raise RuntimeError("error! unknown version of python!")
result = None
result_gry = None
flann = cv2.flannBasedMatcher({'algorithm': 0,'trees': 5},{'checks': 50})
image_paths = ["/Users/akshayacharya/Desktop/Panorama/Raw Data/Office data/"]
image_index = -1
for image_path in image_paths:
#print(image_path)
if not os.path.exists(image_path):
logging.error('{0} is not a valid path'.format(image_path))
continue
if os.path.isdir(image_path):
extensions = [".jpeg",".jpg",".png"]
for file_path in os.listdir(image_path):
if os.path.splitext(file_path)[1].lower() in extensions:
print(file_path)
image_paths.append(os.path.join(image_path,file_path))
continue
logging.info("reading image from {0}".format(image_path))
image_colour = cv2.imread(image_path)
image_gray = cv2.cvtColor(image_colour,cv2.COLOR_RGB2GRAY)
image_index += 1
if image_index == 0:
result = image_colour
result_gry = image_gray
continue
logger.debug('computing sift features')
features0 = sift.detectAndCompute(result_gry,None)
features1 = sift.detectAndCompute(image_gray,None)
matches_src,matches_dst,n_matches = image_stitching.compute_matches(features0,features1,flann,knn=args.knn)
if n_matches < args.min_correspondence:
logger.error("error! too few correspondences")
continue
logger.debug("computing homography between accumulated and new images")
H,mask = cv2.findHomography(matches_src,cv2.RANSAC,5.0)
result = combine_images(image_colour,result,H)
if args.display and not args.quiet:
helpers.display('result',result)
if cv2.waitKey(25) & 0xFF == ord('q'):
break
result_gry = cv2.cvtColor(result,cv2.COLOR_RGB2GRAY)
logger.info("processing complete!")
if args.display and not args.quiet:
cv2.destroyAllWindows()
if args.save:
logger.info("saving stitched image to {0}".format(args.save_path))
helpers.save_image(args.save_path,result)