简体   繁体   中英

Reading a RAW image (.CR2) using numpy.fromfile

I am trying to read a raw image in .CR2 format ("Canon Raw format"). I wanted to do it with opencv initially but could not get it to work so I tried doing it with a numpy function:

img = np.fromfile('IMG.CR2', "uint16")

The camera is a canon EOS t5 18MP DSLR. If I run img.size it return 10105415 which seems too small for an 18 MP camera.

My first question, is using np.fromfile() a valid approach?

Secondly, would you recommend any other python libraries to do the same process in an easier way/more efficient? I have openCV installed so if it could be done there, that would be great (I still want to store it as a numpy array).

Canon RAW format is not just a blob of data, it has some metadata which you need to parse. Luckily, others have already implemented some python parsers.

RAW Image processing in Python

After using one of the suggested solutions you can load the data into numpy array.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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