问题
I can't figure out how to open a dng file in opencv. The file was created when using the pro options of the Samsung Galaxy S7. The images that are created when using those options are a dng file as well as a jpg of size 3024 x 4032 (I believe that is the dimensions of the dng file as well).
I tried using the answer from here (except with 3 colors instead of grayscale) like so:
import numpy as np
fd = open("image.dng", 'rb')
rows = 4032
cols = 3024
colors = 3
f = np.fromfile(fd, dtype=np.uint8,count=rows*cols*colors)
im = f.reshape((rows, cols,colors)) #notice row, column format
fd.close()
However, i got the following error:
cannot reshape array of size 24411648 into shape (4032,3024,3)
Any help would be appreciated
回答1:
As far as i know it is possible that DNG files can be compressed (even though it is lossless format), so you will need to decode your dng image first. https://www.libraw.org/ is capable of doing that.
There is python wrapper for that library (https://pypi.python.org/pypi/rawpy)
import rawpy
import imageio
path = 'image.dng'
with rawpy.imread(path) as raw:
rgb = raw.postprocess()
来源:https://stackoverflow.com/questions/47969587/opencv-python-open-dng-format