jim-easterbrook / python-gphoto2

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

capture image, no image on the memory card canon eos40D #99

Closed pdeman closed 3 years ago

pdeman commented 4 years ago

I am trying to capture images on the memory card:


capturetarget=gphoto2.check_result(gphoto2.gp_widget_get_child_by_name(self.cameraConfig,"capturetarget"))
gphoto2.check_result(gphoto2.gp_widget_set_value(capturetarget, "Memory Card"))
retval=gphoto2.gp_camera_trigger_capture(self.camera,self.context)
eventtype=0
   while eventtype != gphoto2.GP_EVENT_FILE_ADDED: 
           error,eventtype,file_path_cr2 = gphoto2.gp_camera_wait_for_event(self.camera,20,self.context)

but when I do that, there is no file on the memory card of the camera. is that normal ? there was the event gp_event_file_added, the file_path number increment (capt00001.raw, then capt00002.raw etc ...) and I can hear the shutter noise.

same if I use file_path = self.camera.capture(gp.GP_CAPTURE_IMAGE) I have no file on the memory card after. which is strange is that if I use the example capture-image.py. it opens the image, but I still have no image on the memory card after. does


camera_file = camera.file_get(
        file_path.folder, file_path.name, gp.GP_FILE_TYPE_NORMAL)
camera_file.save(target)

remove the file on the memory card after ?

I am using: gphoto2 2.5.23.1 libgphoto2 2.5.23.1 libgphoto2_port 0.12.0

and python gphoto from git (updated last week)

using gphoto2 --capture-image, it saves an image on the memory card.

jim-easterbrook commented 4 years ago

After setting the widget value you need to copy the modified configuration back to the camera. This is the case with any configuration change. See the set-capture-target.py example program.

jim-easterbrook commented 4 years ago

To answer your other questions: capt00001.raw is a typical name for an image in the camera's RAM, i.e. not saved to memory card. Therefore it won't be on the memory card. The capture-image.py example doesn't set the capture target, so if your camera is configured to save to RAM then it won't save to memory card. I don't know about gphoto2 --capture-image.

pdeman commented 4 years ago

ok thanks it works now

pdeman commented 3 years ago

sorry but it doesn't work anymore ... here is my code :

self.cameraConfig = gphoto2.check_result(gphoto2.gp_camera_get_config(self.camera))           
expoMode=gphoto2.check_result(gphoto2.gp_widget_get_child_by_name(self.cameraConfig,"autoexposuremode"))            
gphoto2.check_result(gphoto2.gp_widget_set_value(expoMode,"Landscape"))       
capturetarget=gphoto2.check_result(gphoto2.gp_widget_get_child_by_name(self.cameraConfig,"capturetarget"))

gphoto2.check_result(gphoto2.gp_widget_set_value(capturetarget, "Memory Card"))

imageFormatMode=gphoto2.check_result(gphoto2.gp_widget_get_child_by_name(self.cameraConfig,"imageformat"))

imageFormatList =[]
choice_count = imageFormatMode.count_choices()
for n in range(choice_count):
   imageFormatList.append(imageFormatMode.get_choice(n))
   indexLargeFineJPEG = imageFormatList.index("Large Fine JPEG")

imageFormatWanted=gphoto2.check_result(gphoto2.gp_widget_get_choice(imageFormatMode,indexLargeFineJPEG))

gphoto2.check_result(gphoto2.gp_widget_set_value(imageFormatMode,imageFormatWanted))             
gphoto2.check_result(gphoto2.gp_camera_set_config(self.camera,self.cameraConfig))

capturetarget=gphoto2.check_result(gphoto2.gp_widget_get_child_by_name(self.cameraConfig,"capturetarget"))
self.logger.info(gphoto2.gp_widget_get_value(capturetarget))
for iterPic in range(30):
    self.logger.info("trigger capture")        
    file_path_cr2=gphoto2.check_result(gphoto2.gp_camera_capture(self.camera,gphoto2.GP_CAPTURE_IMAGE))
    self.logger.info(file_path_cr2.name)

and what the logger says:

but I have nothing on the memory card. 23885 - 2020-09-09 14:25:01,489 - controlCanon - INFO - [0, 'Memory Card'] 23885 - 2020-09-09 14:25:01,489 - controlCanon - INFO - trigger capture 24625 - 2020-09-09 14:25:02,229 - controlCanon - INFO - capt0001.jpg

jim-easterbrook commented 3 years ago

The capt0001.jpg file name shows it's saving to RAM rather than card. After you've called gp_camera_set_config you could use gp_camera_get_config to read back the values and make sure the camera has done what you wanted. Beyond that I have no suggestions. You could try the gphoto2 mailing list as this doesn't appear to be a problem with the Python interface.

pdeman commented 3 years ago

effectively self.cameraConfig = gphoto2.check_result(gphoto2.gp_camera_get_config(self.camera))
expoMode=gphoto2.check_result(gphoto2.gp_widget_get_child_by_name(self.cameraConfig,"autoexposuremode"))
gphoto2.check_result(gphoto2.gp_widget_set_value(expoMode,"Landscape")) capturetarget=gphoto2.check_result(gphoto2.gp_widget_get_child_by_name(self.cameraConfig,"capturetarget"))

gphoto2.check_result(gphoto2.gp_widget_set_value(capturetarget, "Memory Card")) self.logger.info(gphoto2.gp_widget_get_value(capturetarget))
imageFormatMode=gphoto2.check_result(gphoto2.gp_widget_get_child_by_name(self.cameraConfig,"imageformat")) imageFormatList =[] choice_count = imageFormatMode.count_choices() for n in range(choice_count): imageFormatList.append(imageFormatMode.get_choice(n)) indexLargeFineJPEG = imageFormatList.index("Large Fine JPEG")

imageFormatWanted=gphoto2.check_result(gphoto2.gp_widget_get_choice(imageFormatMode,indexLargeFineJPEG))

gphoto2.check_result(gphoto2.gp_widget_set_value(imageFormatMode,imageFormatWanted)) gphoto2.check_result(gphoto2.gp_camera_set_config(self.camera,self.cameraConfig))

self.cameraConfig =gphoto2.check_result(gphoto2.gp_camera_get_config(self.camera))
capturetarget=gphoto2.check_result(gphoto2.gp_widget_get_child_by_name(self.cameraConfig,"capturetarget")) self.logger.info(gphoto2.gp_widget_get_value(capturetarget))

8592 - 2020-09-09 15:20:52,395 - controlCanon - INFO - [0, 'Memory Card'] 8608 - 2020-09-09 15:20:52,411 - controlCanon - INFO - [0, 'Internal RAM']

it kind of doesn't accept memory card for any reason

pdeman commented 3 years ago

ok found it was a typo. somehow " "Memory Card" worked before and now it is "Memory card" with a lower case c

jim-easterbrook commented 3 years ago

Might be safer to use gp_widget_get_choice to convert a numerical value to a string, as in the set-capture-target.py example.

pdeman commented 3 years ago

yes I'll do that. but I would have expect an error being generated. but I'll do like that now.