Engine
Engine

Reputation: 5432

Saving frames in opencv without compression

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

Upvotes: 3

Views: 13642

Answers (4)

Sergio Arranz Lorenz
Sergio Arranz Lorenz

Reputation: 21

cv::imwrite("imagen.TIFF", bayer, {cv::IMWRITE_TIFF_COMPRESSION, 1, 
cv::IMWRITE_TIFF_XDPI, 72,cv::IMWRITE_TIFF_YDPI,72}); 

Upvotes: 2

sietschie
sietschie

Reputation: 7553

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.

Upvotes: 0

avtomaton
avtomaton

Reputation: 4894

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

Upvotes: 0

TimZaman
TimZaman

Reputation: 2707

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

Upvotes: 2

Related Questions