我正在使用 OpenCV 对图像执行一批失真校正。不幸的是,输出丢失了 exif 元数据。所以我用 Pyexiv2 把它带回来。
def propagate_exif(infile,outfile):
import pyexiv2
msrc = pyexiv2.ImageMetadata(infile)
msrc.read()
print msrc.exif_keys
mdst = pyexiv2.ImageMetadata(outfile)
mdst.read()
msrc.copy(mdst,comment=False)
mdst.write()
但是,当使用多处理 pyexiv2 运行整个代码时,在复制元数据时会不断崩溃。pyexiv2 可能在 OpenCV 仍在输出文件克隆元数据时开始对文件克隆元数据进行操作。解决 pyexiv2/OpenCV 并发访问问题的最佳程序是什么?并行函数如下:
def distortgrid_file(infile,out_dir,mapx,mapy,idealise_matrix=False):
outfile = os.path.join(out_dir,os.path.basename(infile))
#read calibration parameters
apply_distortion(infile, outfile, mapx,mapy)
#preserve exif parameters
propagate_exif(infile,outfile)