pibooth icon indicating copy to clipboard operation
pibooth copied to clipboard

Use gPhoto2 event to know when capture is ready

Open Cruiser79 opened this issue 3 years ago • 4 comments

I already posted a comment under the isuue https://github.com/pibooth/pibooth/issues/356 but open now a new issue for a bigger scope. If the autofocus of my dslr camera failed, pibooth stucks on the "Take a capture" and will not reach another state till then. I read al lot of times, that the switch to manual for the autofocus can help with this problem. Autofocus is very useful and i will not miss it, if it is not a must. Is there not the possibility, that pibooth runs in an timeout after some time, if it stucks on the "Take a capture" mode and restarts himself , like it did for the "Ups! And error occured" message? That will be a more convenience way as one can keep the autofocus to on?

Cruiser79 avatar Jul 04 '22 14:07 Cruiser79

Ok, i just analyzed the source code a little bit and found a solution, which worked for me. I used the trigger_capture() method to capture a photo from my dslr. So i changed the following two last lines in camera/gphoto.py file

    def capture(self, effect=None):
        """Capture a new picture.
        """
        if self._preview_viewfinder:
            self.set_config_value('actions', 'viewfinder', 0)

        effect = str(effect).lower()
        if effect not in self.IMAGE_EFFECTS:
            raise ValueError("Invalid capture effect '{}' (choose among {})".format(effect, self.IMAGE_EFFECTS))

        if self.capture_iso != self.preview_iso:
            self.set_config_value('imgsettings', 'iso', self.capture_iso)

        self._captures.append((self._cam.capture(gp.GP_CAPTURE_IMAGE), effect))
        time.sleep(0.3)  # Necessary to let the time for the camera to save the image

to the following code (Errorcode is certainly not the right one)

    def capture(self, effect=None):
        """Capture a new picture.
        """
        if self._preview_viewfinder:
            self.set_config_value('actions', 'viewfinder', 0)

        effect = str(effect).lower()
        if effect not in self.IMAGE_EFFECTS:
            raise ValueError("Invalid capture effect '{}' (choose among {})".format(effect, self.IMAGE_EFFECTS))

        if self.capture_iso != self.preview_iso:
            self.set_config_value('imgsettings', 'iso', self.capture_iso)

#        self._captures.append((self._cam.capture(gp.GP_CAPTURE_IMAGE), effect))
#        time.sleep(0.3)  # Necessary to let the time for the camera to save the image
#        Added new lines here
        self._cam.trigger_capture()
        timeoutInSec = 5
        waitForEventTime = 100
        startTime = time.time()
        while True:
          currentTime = time.time()
          if ((currentTime - startTime ) > timeoutInSec):
            raise ValueError("Waiting to long, abort")
          event_type, event_data = self._cam.wait_for_event(waitForEventTime)
          if event_type == gp.GP_EVENT_FILE_ADDED:
            self._captures.append((event_data, effect))
            time.sleep(0.3)
            break

When now the camera gets no autofocus, it will print the "Ops! Something went wrong" message and switch back to WAITING state. Maybe it could help someone else, or will be integrated in master branch.

Cruiser79 avatar Jul 06 '22 06:07 Cruiser79

Hi @Cruiser79

Thanks for the tricks, it could be appended to the master to avoid deadlock. but I don' know if we can rely on the wait_for_event for a kind of DSLR, so it may introduce regression for some camera model.

anxuae avatar Aug 04 '22 07:08 anxuae

@anxuae what do you mean with your text "but I don' know if we can rely on the wait_for_event for a kind of DSLR,"? Do you thing, that not all DSLRs will support this function? Or do you think, because you wrote also "it may indroduce regression for some camera model"?, that the 100ms is a way back for some models, because it is such a long time?

Cruiser79 avatar Aug 04 '22 09:08 Cruiser79

Events are not well implemented on DSLR depending on the model. In such a case, your code will not work.

anxuae avatar Aug 04 '22 11:08 anxuae

Implemented in v3.0.0 coming soon

anxuae avatar Apr 01 '23 12:04 anxuae