3

I'm trying to use the imwrite() OpenCV function. I want to save the frames with the .TIFF extension. The problem that I have is that the saved images are compressed so I can't use them. Any idea how I can escape this compression?

thanks in advance

sietschie
  • 7,425
  • 3
  • 33
  • 54
Engine
  • 5,360
  • 18
  • 84
  • 162

4 Answers4

3

Do not mind what sietschie says. The TIFF flag is hardcoded in the opencv binaries with a LZW compression. You can just turn this off (comment it out) or change it. In:

3rdparty/libtiff/tiff.h

Remove this line:

#define     COMPRESSION_LZW     5       /* Lempel-Ziv  & Welch */

Then compile. Presto. Tiff options other than that are automatically set (8 bit, 16bit, color, rgb, rgba,etc) depending on your image

TimZaman
  • 2,689
  • 2
  • 26
  • 36
1

According to the documentation OpenCV only exposes a limited set of options for writing image files. Non of which belongs to TIFF-Files.

So unless you want to use your own function or modify the OpenCV source, this is not possible. I would suggest using another uncompressed format for saving the frames like PXM or BMP, unless you have some specific reasons to use TIFF-Files.

sietschie
  • 7,425
  • 3
  • 33
  • 54
1
cv::imwrite("imagen.TIFF", bayer, {cv::IMWRITE_TIFF_COMPRESSION, 1, 
cv::IMWRITE_TIFF_XDPI, 72,cv::IMWRITE_TIFF_YDPI,72}); 
Pranav Choudhary
  • 2,726
  • 3
  • 18
  • 38
0

The simplest way is recompiling OpenCV or direct using libtiff, but I consider as not very good idea changing 3rdparty/libtiff/tiff.h: after this modification you can't save compressed TIFFs at all with OpenCV, and under non-windows systems you usually have separate libtiff (not as a part of OpenCV).

I suggest simpler approach (still OpenCV recompilation, but you save possibility of writing compressed tiff and don't change libtiff directly): saving uncompressed TIFFs with OpenCV

Community
  • 1
  • 1
avtomaton
  • 4,725
  • 1
  • 38
  • 42