64mp - What is the quickest way to grab an image in python?

Hello, I am building a machine that needs to take an image from the 64mp hawkeye camera.

I am happy to initialize the camera once before the machine needs to take a picture, but I need to get a picture/frame as quickly as possible once the user presses the start button. I am currently using the libcamera library. With this code it takes around 5 seconds to get a picture. Does anybody know of a wat to get an image much quicker ? Thanks.

Here is a sample of the code I am following:

import os,time
import libcamera

def init_cameras(cv2):

width = 4626 #9152     had to lower the resolution due to insufficient buffer errors !
height = 3472 #6944 

# Instantiate the libcamera class
cam = libcamera.libcamera()

ret = cam.initCamera(width, height, libcamera.PixelFormat.RGB888, buffercount=1 , rotation=0)

# Turn on the camera
ret = cam.startCamera()
cam.set(libcamera.Brightness,0.2)

def take_picture(cv2,ret,cam,save):
#print(“starting”)
print(“in take_picture”)
# Capture frame-by-frame

while True:

        """
        Read image information
        
        :returns ret: Whether the image is successfully read
        :returns data: Image data information
        """
        
        ret, data = cam.readFrame()

        if not ret:
            continue

        # Get image data
        # At present, only RGB888, BGR888, XRGB8888 can be displayed directly, no conversion
        #print("reading="+str(fflag))
        frame = data.imageData

        if (save):
            cv2.imwrite('/mnt/ramdisk/Camera_output.jpg',frame)
            print("Picture taken")


        """
        Return image buffer

        :param data: Send image data back
        """
        cam.returnFrameBuffer(data)
        break

@Ross6699

you can use picamera2.
But it takes time for the camera to start up.

Hello,

Many thanks for the reply.

Could you show me what is in line 1 to 27 of your code please.

I have tried copying your code but I am getting an error.

Thanks.

@Ross6699

The previous code is other processing I did, it doesn’t affect the code itself, can you show me the error report?

Hello,

Many thanks for your quick reply.

I have now got the code working. It seems to work very well and I think it will be acceptable for my project.

Many thanks.