3

I am trying to convert a directory of photos from ORF to jpg using python. The image library I am using is

https://github.com/letmaik/rawpy

An error is occuring when I try to read an image from the path. The error is below

  with rawpy.imread(fullPath) as raw:
  File "/Library/Python/2.7/site-packages/rawpy/__init__.py", line 20, in imread
    d.open_file(pathOrFile)
  File "rawpy/_rawpy.pyx", line 266, in rawpy._rawpy.RawPy.open_file
  File "rawpy/_rawpy.pyx", line 668, in rawpy._rawpy.RawPy.handle_error
rawpy._rawpy.LibRawFatalError: Input/output error

imageConversion.py

path = '/Users/Account/Desktop/ORFImages'
for (dirpath, dirnames, filenames) in walk(path):
    for l in filenames:
         fullPath = str(join(dirpath,l))
         with rawpy.imread(fullPath) as raw: #ERROR OCCURS HERE
             rgb = raw.postprocess()
             imageio.imwrite('test.jpg', rgb)

There is most definitely an ORF image at the fullpath variable.

What am I doing wrong?

RyeGuy
  • 4,213
  • 10
  • 33
  • 57

1 Answers1

2

This code works for me.

Please note that the path should be relative to the .py file you have.

import glob
import rawpy
import imageio

path = "ORFImages/*orf"
for infile in glob.glob(path):
    with rawpy.imread(infile) as raw:
        rgb = raw.postprocess()
        imageio.imwrite('test.jpg', rgb)
mzage
  • 278
  • 1
  • 3
  • 12
  • I appreciate the response. Unfortunately I get the same behavior. Could you provide the version of python, rawpy and imageio you are using? – RyeGuy Oct 31 '18 at 23:05
  • 1
    @RyeGuy. python 3.6.3, rawpy 0.13.0 and numpy 1.14.1 – mzage Nov 01 '18 at 06:18
  • 1
    I think the problem is the path you're giving to imread() function, try: import os print(os.path.isdir("DirectoryPath")) print(os.path.exists("DirectoryPath/filename.orf")) – mzage Nov 01 '18 at 06:21
  • 1
    the boolean's to check if the path existed helped. Im not quite sure what the problem was but it is working now. Thanks @mzage – RyeGuy Nov 02 '18 at 02:38
  • @RyeGuy I'm glad you got it solved. you're very welcome. – mzage Nov 03 '18 at 16:47
  • @mzage It solved the issue but do not understand why relative path has to be used. For me works with Absolute path also. – Mohit Lamba Jun 20 '20 at 06:47