Newer
Older
lynxi-casic-demo / detect_utils.py
zhangyingjie on 24 Jan 1 KB 增加后台接口调用
import ctypes
from ctypes import *
import math

from callback_data_struct import cb_data

class bbox(ctypes.Structure):
    _fields_ = [
        ("xmin", ctypes.c_uint32),
        ("ymin", ctypes.c_uint32),
        ("xmax", ctypes.c_uint32),
        ("ymax", ctypes.c_uint32),
        ("score", ctypes.c_float),
        ("id", ctypes.c_uint32),
        ("label", ctypes.c_wchar * 64),
        ("alarm", ctypes.c_uint8),
        ("model_code", ctypes.c_wchar * 64),
    ]

class Box(ctypes.Structure):
    _fields_ = [
        ("boxesnum", ctypes.c_uint32), 
        ("boxes", ctypes.ARRAY(bbox, 256))
    ]

class SubClass(ctypes.Structure):
    _fields_ = [
        ("model_code", ctypes.c_wchar * 64),
        ("object_id",ctypes.c_uint32),
        ("object_name", ctypes.c_wchar * 64),
        ("conf_threshold", ctypes.c_float),
        ("alarm_threshold", ctypes.c_uint32),
        ("range", ctypes.ARRAY(ctypes.c_float, 8))
    ]

class SubObject(ctypes.Structure):
    _fields_ = [
        ("objectsnum", ctypes.c_uint32), 
        ("objects", ctypes.ARRAY(SubClass, 80))
    ]

def recv_frame_cb(cb_data: cb_data):
    # 放到ipe的处理队列中
    cb_data.block_queue.put(cb_data)
    return 0


def free_to_pool_callback(params):
    vdec_out_pool = params[0]
    data = params[1]
    vdec_out_pool.push(data)
    return 0


def set_even(num):
    num = math.floor(num)
    if num % 2 != 0:
        res = num - 1
    else:
        res = num
    return res

def set_padding_data(vidoe_width, video_height, model_width, model_height):
    if vidoe_width > video_height:
        resize_width = model_width
        pad_x = 0
        resize_height = set_even(int(video_height * model_width / vidoe_width))
        pad_y = (model_height - resize_height) / 2
    else:
        resize_height = model_height
        pad_y = 0
        resize_width = set_even(int(vidoe_width * model_width / video_height))
        pad_x = (model_width - resize_width) / 2

    return int(resize_width), int(resize_height), int(pad_x), int(pad_y)