I have a .tar
file containing several hundreds of pictures (.png
). I need to process them via opencv.
I am wondering whether - for efficiency reasons - it is possible to process them without passing by the disc. In other, words I want to read the pictures from the memory stream related to the tar file.
Consider for instance
import tarfile
import cv2
tar0 = tarfile.open('mytar.tar')
im = cv2.imread( tar0.extractfile('fname.png').read() )
The last line doesn't work as imread
expects a file name rather than a stream.
Consider that this way of reading directly from the tar
stream can be achieved e.g. for text (see e.g. this SO question).
Any suggestion to open the stream with the correct png
encoding?
Untarring to ramdisk is of course an option, although I was looking for something more cachable.