#!/usr/bin/env python
# encoding: utf-8
"""
@author: simin. Gong
@license: (C) Copyright 2013-2023 Spacemit Corporation Limited.
@contact: simin.gong@spacemit.com
@file: plugin.py
@date: 2024/12/4 19:31
@desc:
"""
import os
import time
from ai_tool.plugins import CameraDetectPlugin
from ai_tool.plugins.camera_detect import libs
import vp_module as vp
from .face_detect_node import FaceDetectNode
from .usb_cam_node import UsbCamNode

lib_path = os.path.dirname(libs.__file__)
yolov5n_face_model = os.path.join(lib_path, 'yolov5n-face.q.onnx')


class CameraFacePlugin(CameraDetectPlugin):

    def __init__(self):
        super().__init__()

    def run_camera_plugin(self):
        facedetnode = FaceDetectNode("face0", yolov5n_face_model, self.data_callback)
        self.usb_cam = UsbCamNode("usbCam0", 1, self.data_callback)
        facedetnode.attach_to([self.usb_cam])
        # board = vp.vp_analysis_board([self.usb_cam])
        # board.display(1, False)
        self.usb_cam.start()
        self.start_time = time.time()
        self.e_Event.wait()
        print(f'开始关闭进程 {os.getpid()}')
        self.usb_cam.stop_cap()
        print('相机关闭成功')
        self.usb_cam.detach_recursively()
        print('进程结束')
