1.程序中ffmpeg启用硬件加速\n2.修改yolov8rknn以适配main程序
This commit is contained in:
parent
802a6c0d32
commit
2d013cc491
@ -1,5 +1,6 @@
|
|||||||
|
|
||||||
engine_path: 'build_0826/'
|
engine_path: 'build_0826/'
|
||||||
|
rknn_path: '/home/orangepi/Desktop/kangda_robotic_dog/yolov8_20250820.rknn'
|
||||||
|
|
||||||
video_config:
|
video_config:
|
||||||
|
|
||||||
@ -124,7 +125,8 @@ dataConfig:
|
|||||||
# putMessageUrl: 'http://192.168.220.202/api/edge/edgecallmanages/vi-alarm/v1'
|
# putMessageUrl: 'http://192.168.220.202/api/edge/edgecallmanages/vi-alarm/v1'
|
||||||
|
|
||||||
compreface_service:
|
compreface_service:
|
||||||
domain: 'http://localhost'
|
# domain: 'http://localhost'
|
||||||
|
domain: 'http://10.0.0.202'
|
||||||
port: '8000'
|
port: '8000'
|
||||||
api_key: 'ce04b456-88df-4df8-a7a2-69849111916f'
|
api_key: 'ce04b456-88df-4df8-a7a2-69849111916f'
|
||||||
# api_key: 'ab77978a-cc2b-4fa0-8959-6294e856721a'
|
# api_key: 'ab77978a-cc2b-4fa0-8959-6294e856721a'
|
||||||
|
|||||||
42
main.py
42
main.py
@ -89,20 +89,26 @@ m3u8_path = configData['video_config']['m3u8_path']
|
|||||||
save_path = configData['video_config']['save_path']
|
save_path = configData['video_config']['save_path']
|
||||||
vod_path = configData['video_config']['v1_path']
|
vod_path = configData['video_config']['v1_path']
|
||||||
people_save_path = configData['video_config']['people_save_path']
|
people_save_path = configData['video_config']['people_save_path']
|
||||||
vod_channelNo = configData['video_config']['v1_channelNo']
|
vod_channelNo = configData['video_config']['v0_channelNo']
|
||||||
testclasses = configData['video_config']['v1_testclasses']
|
testclasses = configData['video_config']['v0_testclasses']
|
||||||
engine_path = configData['engine_path']
|
engine_path = configData['engine_path']
|
||||||
|
rknn_path = configData['rknn_path']
|
||||||
|
|
||||||
|
|
||||||
# FFmpeg命令
|
# FFmpeg命令
|
||||||
command_mid = [
|
command_mid = [
|
||||||
'ffmpeg',
|
'ffmpeg',
|
||||||
|
'-hwaccel', 'rkmpp', # 启用 RKMPP 硬件加速解码(硬件解码)
|
||||||
'-i', '-', # 从标准输入读取视频帧
|
'-i', '-', # 从标准输入读取视频帧
|
||||||
'-c:v', 'libx264', # 使用 H.264 编码
|
'-vf', 'scale_rkrga=1280:720', # 使用 RGA 硬件加速缩放(零拷贝)
|
||||||
|
'-c:v', 'h264_rkmpp', # 使用 RKMPP 硬件加速 H.264 编码(代替 libx264)
|
||||||
'-b:v', '500k', # 设置视频比特率
|
'-b:v', '500k', # 设置视频比特率
|
||||||
'-preset', 'superfast', # 编码速度
|
'-g', '50', # GOP 大小(可按需要调节), 硬件解码时需要
|
||||||
'-tune', 'zerolatency', # 低延迟
|
'-bf', '0', # 禁用 B 帧以减少延迟, 硬件解码时需要
|
||||||
'-crf', '23', # 使用 CRF 模式来控制视频质量
|
# '-preset', 'superfast', # 编码速度, cpu编码时需要
|
||||||
'-s', '1280x720', # 设置分辨率
|
# '-tune', 'zerolatency', # 低延迟, cpu编码时需要
|
||||||
|
# '-crf', '23', # 使用 CRF 模式来控制视频质量, cpu编码时需要
|
||||||
|
# '-s', '1280x720', # 设置分辨率, cpu编码时需要
|
||||||
'-an', # 禁用音频
|
'-an', # 禁用音频
|
||||||
'-loglevel', 'error',
|
'-loglevel', 'error',
|
||||||
'-hls_time', '4',
|
'-hls_time', '4',
|
||||||
@ -845,7 +851,7 @@ class inferThread(threading.Thread):
|
|||||||
# logger.debug(f"获取token: {token}")
|
# logger.debug(f"获取token: {token}")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
batch_image_raw, r_list, box_list = self.yolov8_wrapper.infer(frame)
|
batch_image_raw, r_list, box_list = self.yolov8_wrapper.infer(frame, CONF_THRESH, IOU_THRESHOLD)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"目标检测时发生异常: {e}")
|
logger.error(f"目标检测时发生异常: {e}")
|
||||||
# 即使检测失败,也要将帧推送到ffmpeg
|
# 即使检测失败,也要将帧推送到ffmpeg
|
||||||
@ -1034,8 +1040,8 @@ if __name__ == "__main__":
|
|||||||
os.makedirs(m3u8_path + ip, exist_ok=True)
|
os.makedirs(m3u8_path + ip, exist_ok=True)
|
||||||
|
|
||||||
# load custom plugin and engine
|
# load custom plugin and engine
|
||||||
PLUGIN_LIBRARY = f"{engine_path}libmyplugins.so"
|
# PLUGIN_LIBRARY = f"{engine_path}libmyplugins.so"
|
||||||
engine_file_path = f"{engine_path}best.engine"
|
# engine_file_path = f"{engine_path}best.engine"
|
||||||
|
|
||||||
# 执行python代码命令行 参数判断操作(不做处理)
|
# 执行python代码命令行 参数判断操作(不做处理)
|
||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
@ -1045,19 +1051,19 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
clear_folder(ip)
|
clear_folder(ip)
|
||||||
|
|
||||||
# 加载动态链接库
|
# # 加载动态链接库
|
||||||
try:
|
# try:
|
||||||
ctypes.CDLL(PLUGIN_LIBRARY)
|
# ctypes.CDLL(PLUGIN_LIBRARY)
|
||||||
except Exception as e:
|
# except Exception as e:
|
||||||
logger.error(f"加载动态链接库失败: {e}")
|
# logger.error(f"加载动态链接库失败: {e}")
|
||||||
sys.exit(1)
|
# sys.exit(1)
|
||||||
|
|
||||||
# 手动输入训练时的类别
|
# 手动输入训练时的类别
|
||||||
categories = ["shoe"]
|
categories = ["class1", "class2"]
|
||||||
|
|
||||||
# 加载模型文件
|
# 加载模型文件
|
||||||
try:
|
try:
|
||||||
yolov8_wrapper1 = YoLov8TRT(engine_file_path)
|
yolov8_wrapper1 = YOLOv8RKNN(rknn_path, categories)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"加载模型文件失败: {e}")
|
logger.error(f"加载模型文件失败: {e}")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|||||||
@ -7,20 +7,14 @@ import time
|
|||||||
|
|
||||||
from rknn.api import RKNN
|
from rknn.api import RKNN
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class YOLOv8RKNN:
|
class YOLOv8RKNN:
|
||||||
def __init__(self, model_path, input_size=(640, 640)):
|
def __init__(self, model_path, input_size=(640, 640), class_names = ['class1', 'class2']):
|
||||||
self.model_path = model_path
|
self.model_path = model_path
|
||||||
self.input_size = input_size
|
self.input_size = input_size
|
||||||
self.rknn = RKNN()
|
self.rknn = RKNN()
|
||||||
|
|
||||||
# 类别名称,根据你的2个类别修改
|
# 类别名称,根据你的2个类别修改
|
||||||
self.class_names = ['class1', 'class2'] # 请替换为你实际的类别名称
|
self.class_names = class_names # 请替换为你实际的类别名称
|
||||||
|
|
||||||
# 初始化模型
|
# 初始化模型
|
||||||
self.load_model()
|
self.load_model()
|
||||||
@ -148,6 +142,21 @@ class YOLOv8RKNN:
|
|||||||
|
|
||||||
return boxes, scores, class_ids, inference_time
|
return boxes, scores, class_ids, inference_time
|
||||||
|
|
||||||
|
def infer(self, frame, conf_threshold=0.5, nms_threshold=0.4, testclasses=None):
|
||||||
|
# 预处理
|
||||||
|
input_image = self.preprocess(frame)
|
||||||
|
outputs = self.rknn.inference(inputs=[input_image])
|
||||||
|
boxes, scores, class_ids = self.postprocess(outputs, conf_threshold, nms_threshold)
|
||||||
|
if None:
|
||||||
|
return True, 0, []
|
||||||
|
result = list()
|
||||||
|
for i in range(class_ids):
|
||||||
|
if class_ids[i] in testclasses:
|
||||||
|
result.append(boxes[i])
|
||||||
|
|
||||||
|
return True, len(result), result
|
||||||
|
|
||||||
|
|
||||||
def draw_detections(self, image, boxes, scores, class_ids):
|
def draw_detections(self, image, boxes, scores, class_ids):
|
||||||
"""在图像上绘制检测结果"""
|
"""在图像上绘制检测结果"""
|
||||||
for i in range(len(boxes)):
|
for i in range(len(boxes)):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user