OPENCV输出单色TIFF组4压缩
有没有办法在第4组压缩中输出OpenCV中的单色TIFF文件?
这是使用ImageMagick/GraphicsMagick
'gm convert '.$file.' -type bilevel -monochrome -compress group4 '.$output
OpenCV版本4.5.1
Update> Update
# g++ -Wall -O3 -std=c++17 main.cpp -o main `pkg-config opencv4 --cflags --libs` -ltiff
查找
不返回任何
root@x:/usr/include/opencv4/opencv2# find . -name "*tif*"
代码
#include <tiffio.h>
#include <opencv4/opencv2/opencv.hpp>
std::vector<int> params = {cv::IMWRITE_TIFF_COMPRESSION, COMPRESSION_CCITTFAX4};
cv::imwrite(_output, src_bin, params);
错误
的命令[WARN:0] Global ../modules/imgcodecs/src/grfmt_tiff.cpp(914) Writelibtiff Opencv Tiff(第914行):失败的Tiffsetfield(tif, tifftag_predictor,preditiveor)imwrite _('out.tif'):无法写入数据: OPENCV(4.5.1)../modules/imgcodecs/src/grfmt_tiff.cpp:914:错误: (-2:未指定的错误)OpenCV TIFF:失败TiffsetField(Tif, tifftag_predictor,预测指标)在函数'Writelibtiff'
中
Is there a way to output monochrome TIFF files in OpenCV with group 4 compression?
This is the command to do it with imagemagick/graphicsmagick
'gm convert '.$file.' -type bilevel -monochrome -compress group4 '.$output
OpenCV version 4.5.1
update
# g++ -Wall -O3 -std=c++17 main.cpp -o main `pkg-config opencv4 --cflags --libs` -ltiff
find
doesn't return anything
root@x:/usr/include/opencv4/opencv2# find . -name "*tif*"
code
#include <tiffio.h>
#include <opencv4/opencv2/opencv.hpp>
std::vector<int> params = {cv::IMWRITE_TIFF_COMPRESSION, COMPRESSION_CCITTFAX4};
cv::imwrite(_output, src_bin, params);
error
[ WARN:0] global ../modules/imgcodecs/src/grfmt_tiff.cpp (914)
writeLibTiff OpenCV TIFF(line 914): failed TIFFSetField(tif,
TIFFTAG_PREDICTOR, predictor) imwrite_('out.tif'): can't write data:
OpenCV(4.5.1) ../modules/imgcodecs/src/grfmt_tiff.cpp:914: error:
(-2:Unspecified error) OpenCV TIFF: failed TIFFSetField(tif,
TIFFTAG_PREDICTOR, predictor) in function 'writeLibTiff'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
OPENCV使用
libtiff
( link )。如果您调用cv.imwrite
()您可以传递其他参数。对于第4组,压缩文档说您必须通过
imwrite_tiff_compression
flag(link) with valueCOMPRESSION_CCITTFAX4
(示例:
更新
好,这就是应该工作的方式。但是,OpenCV4目前似乎在编写4组TIFF方面存在一个或多个问题。顺便说一句,当您尝试Python-lib时,情况是一样的。 这个已知的问题 处理一个预测标记,该标签被OpenCV错误地添加。我将修复程序应用于我的本地构建,但是在此期间又出现了一个问题,缺少将8位垫子转换为Group4的1bit/示例。因此,我的建议是:
解决方法
相反,您可以使用graphicsMagick api magick ++ 。
OpenCV uses
libtiff
(link). If you callcv.imwrite
(link) you can pass additional parameters.For group 4 compression the docs say that you have to pass the
IMWRITE_TIFF_COMPRESSION
flag (link) with valueCOMPRESSION_CCITTFAX4
(link).Example:
Update
Well, this is how it should work. But it seems that opencv4 currently has one or more issues in writing Group 4 TIFF. Btw it's the same when you try the python-lib. This known issue deals with a predictor tag that is wrongly added by opencv. I applied the fix to my local build but after that one more issue came up missing a conversion of the 8bit Mat to 1bit/sample for group4. So my recommendation is:
Workaround
Instead you can use the GraphicsMagick API Magick++.