i'm tried capture a frame based into script exemplo "camera_still_max_res.py" but this method cost a lot for hardware, did exist other method to capture a frame of sensor(not the output node) that doesn't run in loop?
with dai.Pipeline(defaultDevice=device) as pipeline:
device = pipeline.getDefaultDevice()
print('Connected cameras:',device.getConnectedCameras())
# A definição dos nós permanece a mesma
cam_rgb = pipeline.create(dai.node.Camera).build(
boardSocket=dai.CameraBoardSocket.CAM_A,
sensorResolution= [SENSOR_WIDTH,SENSOR_HEIGHT],
sensorFps=FPS,
)
isp_out = cam_rgb.requestOutput((SENSOR_WIDTH, SENSOR_HEIGHT), dai.ImgFrame.Type.YUV420p, fps=FPS)
stream_highest_res = cam_rgb.requestFullResolutionOutput(useHighestResolution=True)
script = pipeline.create(dai.node.Script) script.setScript( """ while True: message = node.inputs["in"].get() trigger = node.inputs["trigger"].tryGet() if trigger is not None: node.warn("Trigger de captura recebido!") node.io["highest_res"].send(message) """)
# 1. Criamos o nó ImageManip. manip = pipeline.create(dai.node.ImageManip)
# 2. Lemos as coordenadas de corte iniciais do nosso estado centralizado. controls = self.camera_state.get_all_controls() is_depth_enabled = controls.get('depth_enabled', False) q_depth = None default_crop_x = (SENSOR_WIDTH - CROP_WIDTH) // 2 default_crop_y = (SENSOR_HEIGHT - CROP_HEIGHT) // 2 crop_x = controls.get('crop_x', default_crop_x) crop_y = controls.get('crop_y', default_crop_y)
print(f"INFO: Adicionando operação de corte em ({crop_x}, {crop_y}) com tamanho {CROP_WIDTH}x{CROP_HEIGHT}") manip.initialConfig.addCrop(crop_x, crop_y, CROP_WIDTH, CROP_HEIGHT) # 4. Garantimos que a saída do ImageManip tenha o formato esperado pelo VideoEncoder. manip.initialConfig.setFrameType(dai.ImgFrame.Type.NV12) video_enc = pipeline.create(dai.node.VideoEncoder) video_enc.setDefaultProfilePreset(fps=FPS, profile=dai.VideoEncoderProperties.Profile.H265_MAIN)
if is_depth_enabled: print("INFO: Profundidade habilitada. Configurando pipeline estéreo...")
mono_left = pipeline.create(dai.node.Camera).build( boardSocket=dai.CameraBoardSocket.CAM_B, sensorFps=2, )
mono_right = pipeline.create(dai.node.Camera).build( boardSocket=dai.CameraBoardSocket.CAM_C, sensorFps=2, )
stereo = pipeline.create(dai.node.StereoDepth) stereo.setDefaultProfilePreset(dai.node.StereoDepth.PresetMode.HIGH_DETAIL) stereo.setDepthAlign(dai.CameraBoardSocket.CAM_A) # LeftRightCheck é MANTIDO ATIVO devido à exigência do alinhamento stereo.setLeftRightCheck(True) stereo.setSubpixel(False) mono_left_out = mono_left.requestOutput(size=(640, 400), type=dai.ImgFrame.Type.GRAY8, fps=2) mono_right_out = mono_right.requestOutput(size=(640, 400), type=dai.ImgFrame.Type.GRAY8, fps=2)
mono_left_out.link(stereo.left) mono_right_out.link(stereo.right)
# A fila só é criada se a profundidade estiver habilitada q_depth = stereo.depth.createOutputQueue(maxSize=4, blocking=False) else: print("INFO: Profundidade desabilitada. Pulando a criação dos nós estéreo.") isp_out.link(manip.inputImage) # Saída ISP vai para o ImageManip
manip.setMaxOutputFrameSize(CROP_WIDTH * CROP_HEIGHT * 3 // 2) # NV12 tem 1.5 bytes por pixel
manip.out.link(video_enc.input) # Saída de vídeo 1080p vai para o Manip
stream_highest_res.link(script.inputs["in"]) print("INFO: Aplicando configurações iniciais da câmera...") self._apply_controls(cam_rgb.initialControl)
q_h265_out = video_enc.out.createOutputQueue(maxSize=30, blocking=False) control_in = cam_rgb.inputControl.createInputQueue() sys_logger = pipeline.create(dai.node.SystemLogger) sys_logger.setRate(1) # Envia dados a cada 1 segundo q_sys_info = sys_logger.out.createOutputQueue(maxSize=4, blocking=False)
highest_res_q = script.outputs["highest_res"].createOutputQueue(maxSize=2, blocking=False) q_trigger = script.inputs["trigger"].createInputQueue() pipeline.start() print("INFO: Pipeline V3 iniciado no dispositivo.")
pts = 0 duration_ns = 10**9 / FPS
while self.is_running and pipeline.isRunning(): self._process_commands(control_in) h265_packet = q_h265_out.tryGet() sys_info = q_sys_info.tryGet()
command = self.camera_state.get_command() if command and command.get('type') == 'capture_still': print("INFO: Trigger de captura recebido. Enviando para o nó Script.") q_trigger.send(dai.Buffer())
if highest_res_q.has(): highres_img = highest_res_q.get() frame = highres_img.getCvFrame() filename = f"captura_{datetime.now().strftime('%Y%m%d_%H%M%S')}.png" cv2.imwrite(filename, frame) print(f"SUCESSO: Imagem salva como '{filename}' ({frame.shape[1]}x{frame.shape[0]})")