Can I download multi-frame TIFF via OpenCV?

Does anyone know if OpenCV can load a multi-frame TIFF stack? I am using OpenCV 2.2.0 with python 2.6.

+8
source share
4 answers

Unfortunately, OpenCV does not support TIFF directories and can only read the first frame from multi-frame TIFF files.

+8
source

Although OpenCV cannot open multi-frame TIFF files, you can open the image using PIL and then transfer the data to OpenCV. I have not been able to get it working with the new "cv2" namespace yet

tiff = Image.open('sample.tif') try: while 1: # Convert PIL image to OpenCV image = cv.CreateImageHeader(tiff.size, cv.IPL_DEPTH_8U, 1) cv.SetData(image, tiff.tostring()) # It "tostring" and not "toString()"! # Do whatever you're going to do with OpenCV data tiff.seek(tiff.tell()+1) except EOFError: pass 
+10
source

OpenCV is now able to read multi-page TIFFs using the imreadmulti function. See this page from the OpenCV 3.4 documentation:

https://docs.opencv.org/3.4/d4/da8/group__imgcodecs.html#ga4dd47c9ae3d55cc42286cff005825e31

+1
source

You can also load and access the tiff stack in OpenCV after pip installs TiffCapture . It implements all the VideoCapture methods that you expect in OpenCV for tiffs using PIL.

0
source

Source: https://habr.com/ru/post/896792/


All Articles