简体   繁体   English

使用canon_cr3库从.CR3文件获取未压缩的图像数据

[英]Getting uncompressed image data from a .CR3 file using the canon_cr3 library

I want to convert a .CR3 file (camera is a Canon PowerShot SX70 HS) to a .PNG file using Python (another losless image format would be fine as well). 我想使用Python将.CR3文件(相机为Canon PowerShot SX70 HS)转换为.PNG文件(另一种无损图像格式也可以)。 I found a project on GitHub which should help to do the desired task: https://github.com/lclevy/canon_cr3 我在GitHub上找到了一个项目,该项目应有助于完成所需的任务: https : //github.com/lclevy/canon_cr3

I'm able to load the .CR3 file as an Image object within the canon_cr3 library in Python. 我可以将.CR3文件作为Image对象加载到Python的canon_cr3库中。 Hence, corresponding to the doc of canon_cr3 I can access the small definition raw image (track2) and the high definition raw image (track3). 因此,对应于canon_cr3的文档,我可以访问小分辨率原始图像(track2)和高清晰度原始图像(track3)。 The code: 编码:

image = 'D:\pic\test.CR3'
image = image.replace("\\", "/") #working on Windows
img = Image(image)
sd_img = img.sd_crx_image
print(type(sd_img))
print(len(sd_img))
print(sd_img[0:100])

yields 产量

<class 'bytes'>
1536824
b'\xff\x01\x00\x08\x00\x17r\xc8\x00\x00'

The library contains several functions like tiff(...) . 该库包含几个函数,例如tiff(...) However, I cannot figure out how to apply these functions to store an uncompressed image or get the image information in Python (eg a Numpy array representing the image's pixels). 但是,我无法弄清楚如何应用这些函数来存储未压缩的图像或使用Python获取图像信息(例如,代表图像像素的Numpy数组)。 I tried the following code which yields a .PNG file, however, it cannot be opened: 我尝试了以下代码,生成了.PNG文件,但是无法打开:

with open('D:/pic/test1.PNG', 'wb') as f:
    f.write(img.sd_crx_image)

Does anyone have an idea? 有人有主意吗?

Once downloaded the canon_cr3-master.zip file from https://github.com/lclevy/canon_cr3 it comes with a file named parse_cr3.py . https://github.com/lclevy/canon_cr3下载canon_cr3-master.zip文件后,它将附带一个名为parse_cr3.py的文件。 I realized that the file uses the OptionParser library to provide additional functions when running the script in the command prompt. 我意识到在命令提示符下运行脚本时,该文件使用OptionParser库提供其他功能。 Hence, entering the line 因此,进入生产线

Python parse_cr3.py image.cr3 -v 1 -x

extracts the .JPG file and the small as well as high definition raw image in two .crx files (trak2.crx and trak3.crx). 提取两个两个.crx文件(trak2.crx和trak3.crx)中的.JPG文件和小尺寸以及高清晰度的原始图像。 I suggest that the .crx files can be opened in some way. 我建议可以以某种方式打开.crx文件。 However, I couldn't figure out so far how this is done. 但是,到目前为止,我仍无法弄清楚该如何完成。

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

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