简体   繁体   English

如何在C ++中从.cr2读取图像数据?

[英]How to read image data from .cr2 in C++?

How to read image data from .cr2 (raw image format by Canon) in C++? 如何在C ++中从.cr2 (佳能的原始图像格式)读取图像数据?

The only one operation I need to perform is to read pixel data of .cr2 file directly if it is possible, otherwise I would like to convert it to any loss-less image and read its pixels' data. 我需要执行的唯一一项操作是,如果可能的话,直接读取.cr2文件的像素数据,否则,我想将其转换为任何无损图像并读取其像素的数据。

Any suggestions? 有什么建议么?

I would go with ImageMagick too. 我也会选择ImageMagick。 You don't have to convert all your files up front, you can do them one at a time as you need them. 您不必预先转换所有文件,可以根据需要一次完成一个文件。

In your program, rather than opening the CR2 file, just open a pipe ( popen() call) that is executing an ImageMagick command like 在您的程序中, CR2打开CR2文件,只需打开执行ImageMagick命令的管道( popen()调用),例如

convert file.cr2 ppm:-

then you can read the extremely simple PPM format which is described here - basically just a line of ASCII text that tells you the file type, then another line of ASCII text that tells you the image dimensions, followed by a max value and then the data in binary. 那么您可以阅读此处描述的极其简单的PPM格式-基本上只有一行ASCII文本告诉您文件类型,然后一行ASCII文本告诉您图像尺寸,然后是最大值,然后是数据以二进制形式。

Later on you can actually use the ImageMagick library and API if you need to. 稍后,您可以根据需要实际使用ImageMagick库和API。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM