I am using below code.
It still taking 4 to 5 second to stable image.
I am not understanding what parameters to set to get good quality image instantly.
In depth guide needed. Because, I have to attach 6 cameras to our machine
import depthai as dai
import cv2
import time
import os
# ---------------------------
# STEP 1: CREATE THE PIPELINE
# ---------------------------
pipeline = dai.Pipeline()
# --------------------------------------------------
# STEP 2: CREATE & CONFIGURE THE COLOR CAMERA NODE
# --------------------------------------------------
camRgb = pipeline.createColorCamera()
camRgb.setPreviewSize(640, 480) # Increase preview size (1920, 1080) (640, 480)
camRgb.setResolution(dai.ColorCameraProperties.SensorResolution.THE_12_MP)
camRgb.setInterleaved(False)
camRgb.setBoardSocket(dai.CameraBoardSocket.CAM_A)
# ----------------------------------------------------------------
# STEP 3: CONFIGURE INITIAL CAMERA SETTINGS (EXPOSURE, FOCUS, ISO)
# ----------------------------------------------------------------
camRgb.initialControl.setAutoFocusMode(dai.CameraControl.AutoFocusMode.CONTINUOUS_VIDEO)
camRgb.initialControl.setManualExposure(50000, 300)
# ---------------------------------------------------
# STEP 4: CREATE AN OUTPUT (XLinkOut) TO STREAM FRAMES
# ---------------------------------------------------
xoutPreview = pipeline.createXLinkOut()
xoutPreview.setStreamName("preview")
camRgb.preview.link(xoutPreview.input)
# -------------------------------------
# STEP 5: START THE PIPELINE ON DEVICE
# -------------------------------------
with dai.Device(pipeline) as device:
previewQueue = device.getOutputQueue(name="preview", maxSize=4, blocking=False)
print("Press 's' to save an image larger than 5MB, 'q' to quit the program.")
while True:
inPreview = previewQueue.tryGet()
if inPreview is not None:
frame = inPreview.getCvFrame()
cv2.imshow("preview", frame)
cv2.imwrite("output_images1\\preview.png", frame)
key = cv2.waitKey(1) & 0xFF
if key == ord('s'):
if 'frame' in locals():
timestamp = time.strftime("%Y%m%d_%H%M%S")
filename = f"D:\\oak_kit\\example\\output_imgaes1\\6_feb_25\\capture{timestamp}.bmp" #filename = f"D:\\oak_kit\\example\\output_images1\\6_feb_25\\capture{timestamp}.bmp"
cv2.imwrite(filename, frame)
# Check the file size
file_size = os.path.getsize(filename)
if file_size > 5 * 1024 * 1024: # 5MB in bytes
print(f"Image saved: {filename} (Size: {file_size / (1024 * 1024)} MB)")
else:
os.remove(filename)
print(f"Image discarded: {filename} (Size: {file_size / (1024 * 1024)} MB)")
else:
print("No frame to save yet.")
elif key == ord('q'):
print("Quitting...")
break
cv2.destroyAllWindows()