Can I load a multi-frame TIFF through OpenCV?

前端 未结 3 727
别那么骄傲
别那么骄傲 2021-02-14 18:44

Anyone know if OpenCV is capable of loading a multi-frame TIFF stack? I\'m using OpenCV 2.2.0 with python 2.6.

3条回答
  •  青春惊慌失措
    2021-02-14 19:10

    While OpenCV can't open multi-frame TIFF files, you can open the image using PIL and then pass the data on to OpenCV. I haven't yet been able to get it working with the new "cv2" namespace

    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's "tostring" and not "toString()"!
            # Do whatever you're going to do with OpenCV data
            tiff.seek(tiff.tell()+1)
    except EOFError:
        pass
    

提交回复
热议问题