1

I am using a Basler camera and as wrapper I am using pypylon. I want to measure the time which my camera needs to acquire an image internally. The time for the data transfer is not important for me. What I am doing is that I start the timer and then I am executing the Software Trigger. After the Software Trigger has executed I measure again the time and calculate the time difference. Currently I got the time when the image is grabbed and transferred to the computer. This time is approximately 100 ms which makes absolutely sense because the camera has 20MP and a Rolling Shutter. Moreover the frame rate of the camera is 17 fps so in the best case it needs 60 ms (with data transfer). As mentioned I search the time without data transfer. When I take the time directly after I executed the Software trigger I got times around 3 ms. The problem here is that I have no idea whether the camera has grabbed the image completely or not. The time seems to be too short for me honestly.

Can you please show me how to get the time which the camera needs to grab an image internally?

This is my code I am working with at the moment:

from pypylon import genicam
from pypylon import pylon

from configurationeventprinter import ConfigurationEventPrinter
from imageeventprinter import ImageEventPrinter
import cv2
import time


def getkey():
    return input("Enter \"t\" to trigger the camera or \"e\" to exit and press enter? (t/e) ")


# Example of an image event handler.
class SampleImageEventHandler(pylon.ImageEventHandler):
    def OnImageGrabbed(self, camera, grabResult):
        print("CSampleImageEventHandler::OnImageGrabbed called.")
        print()
        print("Image Acquisition time: ", time.time()-time1)
        print()
        # imageWindow.SetImage(grabResult)
        # imageWindow.Show()



if __name__ == '__main__':
    try:
        converter = pylon.ImageFormatConverter()

        # converting to opencv bgr format
        converter.OutputPixelFormat = pylon.PixelType_BGR8packed
        converter.OutputBitAlignment = pylon.OutputBitAlignment_MsbAligned
        #imageWindow = pylon.PylonImageWindow()
        #imageWindow.Create(1)
        # Create an instant camera object for the camera device found first.
        camera = pylon.InstantCamera(pylon.TlFactory.GetInstance().CreateFirstDevice())

        # Register the standard configuration event handler for enabling software triggering.
        # The software trigger configuration handler replaces the default configuration
        # as all currently registered configuration handlers are removed by setting the registration mode to RegistrationMode_ReplaceAll.
        camera.RegisterConfiguration(pylon.SoftwareTriggerConfiguration(), pylon.RegistrationMode_ReplaceAll,
                                     pylon.Cleanup_Delete)

        # For demonstration purposes only, add a sample configuration event handler to print out information
        # about camera use.t
        camera.RegisterConfiguration(ConfigurationEventPrinter(), pylon.RegistrationMode_Append, pylon.Cleanup_Delete)

        # The image event printer serves as sample image processing.
        # When using the grab loop thread provided by the Instant Camera object, an image event handler processing the grab
        # results must be created and registered.
        camera.RegisterImageEventHandler(ImageEventPrinter(), pylon.RegistrationMode_Append, pylon.Cleanup_Delete)

        # For demonstration purposes only, register another image event handler.
        camera.RegisterImageEventHandler(SampleImageEventHandler(), pylon.RegistrationMode_Append, pylon.Cleanup_Delete)

        # Start the grabbing using the grab loop thread, by setting the grabLoopType parameter
        # to GrabLoop_ProvidedByInstantCamera. The grab results are delivered to the image event handlers.
        # The GrabStrategy_OneByOne default grab strategy is used.
        camera.StartGrabbing(pylon.GrabStrategy_OneByOne, pylon.GrabLoop_ProvidedByInstantCamera)
        
        #camera.GainAuto.SetValue("Once") 
        #camera.Gain =
        #camera.ExposureTime.SetValue(5000)
        #camera.AcquisitionMode.SetValue('SingleFrame')
        
        # def clear_ROI(self):
        #     """ Resets the ROI to the maximum area of the camera"""
        #     self.camera.OffsetX.SetValue(self.camera.OffsetX.Min)
        #     self.camera.OffsetY.SetValue(self.camera.OffsetY.Min)
        #     self.camera.Width.SetValue(self.camera.Width.Max)
        #     self.camera.Height.SetValue(self.camera.Height.Max)
        
        # Wait for user input to trigger the camera or exit the program.
        # The grabbing is stopped, the device is closed and destroyed automatically when the camera object goes out of scope.
        while True:
            time.sleep(0.05)
            key = getkey()
            print(key)
            if (key == 't' or key == 'T'):
                # Execute the software trigger. Wait up to 100 ms for the camera to be ready for trigger.
                time1 = time.time()
                if camera.WaitForFrameTriggerReady(100, pylon.TimeoutHandling_ThrowException):
                    #time1 = time.time()
                    camera.ExecuteSoftwareTrigger();
                    print(time.time() - time1)
            if (key == 'e') or (key == 'E'):
                camera.TriggerMode.SetValue("Off")
                camera.Close()
                break
    except genicam.GenericException as e:
        # Error handling.
        print("An exception occurred.", e.GetDescription())
Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
mzr97
  • 69
  • 7
  • 1
    Do you just seek an answer to the question (https://docs.baslerweb.com/exposure-time) or are you seeking a way to find those times via python? – JonSG Apr 27 '23 at 17:43
  • Do you use this in conjunction with a pylon configuration file (created from pylon's software not python) as well or just this? – Ori Yarden PhD Apr 27 '23 at 17:45
  • @JonSG I just seek an answer to the question – mzr97 Apr 28 '23 at 11:25
  • @OriYarden I calibrate the camera first in pylon – mzr97 Apr 28 '23 at 11:26
  • Based on your comments i think you are going to tell me that the exposure time is the time which the camera needs to grab an image internally. Is this correct? – mzr97 Apr 28 '23 at 11:27
  • you'll have to talk to Basler. acquisition consists of (1) time for exposure (2) time for digitization, i.e. sensor readout (3) time for transfer to host. – Christoph Rackwitz Apr 28 '23 at 12:27
  • @mzr97 IMO your example does not measure anything specific unfortunately, only execution of WaitForFrameTriggerReady amd ExecuteSoftwareTrigger. In order to have it measured correctly, you have to catch **ExposureEnd** event - this event is generated right after image has been exposed and transferred to internal camera's memory. Please see proper documentation and examples how to do camera events at https://docs.baslerweb.com/event-notification – Marcin Kowalski Jul 16 '23 at 09:23

0 Answers0