使用canon_cr3库从.CR3文件获取未压缩的图像数据 [英] Getting uncompressed image data from a .CR3 file using the canon_cr3 library

查看:387
本文介绍了使用canon_cr3库从.CR3文件获取未压缩的图像数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Python将.CR3文件(相机为Canon PowerShot SX70 HS)转换为.PNG文件(另一种无损图像格式也可以).我在GitHub上找到了一个项目,该项目应该有助于完成所需的任务: https://github.com/lclevy/canon_cr3

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). I found a project on GitHub which should help to do the desired task: https://github.com/lclevy/canon_cr3

我能够在Python的 canon_cr3库中将.CR3文件作为Image对象加载.因此,对应于 canon_cr3 的文档,我可以访问小清晰度原始图像(track2)和高清晰度原始图像(track3).代码:

I'm able to load the .CR3 file as an Image object within the canon_cr3 library in Python. Hence, corresponding to the doc of canon_cr3 I can access the small definition raw image (track2) and the high definition raw image (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])

收益

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

该库包含多个功能,例如tiff(...).但是,我无法弄清楚如何应用这些功能来存储未压缩的图像或使用Python获取图像信息(例如代表图像像素的Numpy数组).我尝试使用以下代码生成一个.PNG文件,但是无法将其打开:

The library contains several functions like tiff(...). However, I cannot figure out how to apply these functions to store an uncompressed image or get the image information in Python (e.g. a Numpy array representing the image's pixels). I tried the following code which yields a .PNG file, however, it cannot be opened:

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

有人有主意吗?

推荐答案

一旦从

Once downloaded the canon_cr3-master.zip file from https://github.com/lclevy/canon_cr3 it comes with a file named parse_cr3.py. I realized that the file uses the OptionParser library to provide additional functions when running the script in the command prompt. Hence, entering the line

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

在两个.crx文件(trak2.crx和trak3.crx)中提取.JPG文件以及小型和高清晰度原始图像. 我建议可以以某种方式打开.crx文件.但是,到目前为止,我仍无法弄清楚该如何完成.

extracts the .JPG file and the small as well as high definition raw image in two .crx files (trak2.crx and trak3.crx). I suggest that the .crx files can be opened in some way. However, I couldn't figure out so far how this is done.

这篇关于使用canon_cr3库从.CR3文件获取未压缩的图像数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆