61 lines
1.8 KiB
Python
61 lines
1.8 KiB
Python
# -*- coding: utf-8 -*-
|
||
import cv2
|
||
import numpy as np
|
||
|
||
def draw_detection_results(frame, results):
|
||
"""
|
||
在图像上绘制检测结果
|
||
|
||
Args:
|
||
frame: BGR格式的图像
|
||
results: 检测结果列表,每个元素为(cx, cy, w, h, area, circularity)
|
||
|
||
Returns:
|
||
frame: 绘制后的图像
|
||
"""
|
||
for result in results:
|
||
cx, cy, w, h, area, circularity = result
|
||
|
||
# 计算矩形框坐标
|
||
x = cx - w // 2
|
||
y = cy - h // 2
|
||
|
||
# 绘制绿色矩形框
|
||
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
|
||
|
||
# 绘制十字准星
|
||
cv2.line(frame, (cx - 10, cy), (cx + 10, cy), (0, 255, 0), 2)
|
||
cv2.line(frame, (cx, cy - 10), (cx, cy + 10), (0, 255, 0), 2)
|
||
|
||
# 绘制坐标文字
|
||
text = f"({cx}, {cy})"
|
||
cv2.putText(frame, text, (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
|
||
|
||
return frame
|
||
|
||
def draw_status_bar(frame, exposure_time, gain, detected_count, fps):
|
||
"""
|
||
在图像上绘制状态栏信息
|
||
|
||
Args:
|
||
frame: BGR格式的图像
|
||
exposure_time: 当前曝光时间(微秒)
|
||
gain: 当前增益(dB)
|
||
detected_count: 检测到的目标数
|
||
fps: 当前帧率
|
||
|
||
Returns:
|
||
frame: 绘制后的图像
|
||
"""
|
||
# 在图像顶部添加状态栏
|
||
status_bar = np.zeros((30, frame.shape[1], 3), dtype=np.uint8)
|
||
|
||
# 绘制信息文字
|
||
text = f"Exposure: {exposure_time:.0f}μs | Gain: {gain:.1f}dB | Detected: {detected_count} | FPS: {fps:.1f}"
|
||
cv2.putText(status_bar, text, (10, 20), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 1)
|
||
|
||
# 将状态栏添加到图像顶部
|
||
frame_with_status = np.vstack((status_bar, frame))
|
||
|
||
return frame_with_status
|