pythonopencvmultiprocessingpyexiv2

Pyexiv2 with Multiprocessing


I am performing a batch of distortion corrections on images using OpenCV. Unfortunately the output loses the exif metadata. So I am bringing it back using 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()

However when running the whole code using multiprocessing pyexiv2 constantly crashes while copying over metadata. It is possible that pyexiv2 starts operating on the file cloning metadata while OpenCV is still outputting it. What will be the best procedure to get around pyexiv2/OpenCV concurrent access issues ? The parallel function is as below:

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)

Solution

  • Upgrading to latest pyexiv2 fixed the issue.