jim-easterbrook / python-gphoto2

Python interface to libgphoto2
GNU Lesser General Public License v3.0
359 stars 59 forks source link

can't get raw data #72

Closed pdeman closed 5 years ago

pdeman commented 5 years ago

Hi,

I am trying to take a photo using a canon 50D and get the raw (.cr2).

using shell I do: gphoto2 --capture-image-and-download --filename xxx.%C and it gives me the .jpg and the .cr2

using python I did:


error,camera=gphoto2.gp_camera_new()
error = gphoto2.gp_camera_init(camera,context) 
error,ImageFormat=gphoto2.gp_widget_get_child_by_name(config,"imageformat")
print(ImageFormat.get_value())```

> 'RAW + Large Fine JPEG'

```error,ImageFormat=gphoto2.gp_widget_get_child_by_name(config,"imageformatexthd")
print(ImageFormat.get_value())```

> 'RAW + Large Fine JPEG'

```error,ImageFormat=gphoto2.gp_widget_get_child_by_name(config,"imageformatcf")
print(ImageFormat.get_value())```

> 'RAW + Large Fine JPEG' 

I haven't understood yet the difference between imageformat, imageformatcf and imageformatexthd

```error,file_path=gphoto2.gp_camera_capture(camera,gphoto2.GP_CAPTURE_IMAGE)
print(file_path.name)```

> 'capt0000.jpg'

```error,camera_file=gphoto2.gp_camera_file_get(camera,file_path.folder,file_path.name,gphoto2.GP_FILE_TYPE_NORMAL)
timestamp=datetime.now().strftime("%Y-%m-%d_%H%M%S%f")[:-3]
filename,fileextension = os.path.splitext(file_path.name)
target = "/home/pi/Desktop/camera_CANON/"+filename+timestamp+fileextension
gphoto2.gp_file_save(camera_file,target) ```

I have the .jpg

to get the raw I tried:
```error,camera_file=gphoto2.gp_camera_file_get(camera,file_path.folder,file_path.name,gphoto2.GP_FILE_TYPE_RAW)```
but it doesn't work.
error -1

I tried:
```file_path_cr2=file_path.name.replace(".jpg",".cr2")
cam_file_cr2=gphoto2.gp_camera_file_get(camera,file_path.folder,file_path_cr2,gphoto2.GP_FILE_TYPE_RAW)```
i gave me this:

> [-108, <Swig Object of type 'CameraFile *' at 0x763ed2a0>]

same with
`cam_file_cr2=gphoto2.gp_camera_file_get(camera,file_path.folder,file_path_cr2,gphoto2.GP_FILE_TYPE_NORMAL)`
it gave me this:

> [-108, <Swig Object of type 'CameraFile *' at 0x76407300>]

How can I do to get the raw data ?
jim-easterbrook commented 5 years ago

After getting the .jpg file you need to call gp_camera_wait_for_event until you get a GP_EVENT_FILE_ADDED event. The event data is the path of the .cr2 file which you can then fetch with gp_camera_file_get.

pdeman commented 5 years ago

ok thanks. I added error,eventype,file_path_cr2=gphoto2.gp_wait_for_event(camera,gphoto2.GP_EVENT_FILE_ADDED,context) and it seems to work. if for any reason the gp_event_file_added never arrived, is their a way to add a timeout ?

and about the difference between: imageformat imageformatexthd imageformatcf

any idea where I can find this info ?

jim-easterbrook commented 5 years ago

That's not how gp_camera_wait_for_event works. The second parameter is a timeout value (which is why the documentation calls it timeout). You don't specify what event type to wait for, the function returns the event type and data it has received. You have to call it repeatedly until you get the event you want. See the log_events.py and time_lapse.py examples for typical uses. This was also discussed in #65.

I don't know anything about imageformat, imageformatexthd and imageformatcf.

pdeman commented 5 years ago

ok thanks. I found this used of gp_camera_wait_for_event on an example on the web but it was a bad example apparently. thanks for the info.