You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
XZNSH-Code-AI/tool/video_label.py

34 lines
1.1 KiB
Python

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import cv2
def video_label(video_path,labels,start_frame,end_frame):
"""
给指定帧的图像,添加标注信息
video_path:视频输入文件
labels动作标签
start_frame:动作起始帧
end_frame动作结束帧
"""
cap = cv2.VideoCapture(video_path)
while cap.isOpened():
ret, frame = cap.read()
if not ret:
break
frame_idx = cap.get(cv2.CAP_PROP_POS_FRAMES)
if start_frame <= frame_idx and frame_idx <= end_frame:
cv2.putText(frame, labels, (0, 10), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 255, 0), 2)
cv2.namedWindow("Detection_results", cv2.WINDOW_AUTOSIZE)
cv2.imshow("Detection_results", frame)
if cv2.waitKey(10) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
if __name__ == "__main__":
video_path = "D:/download/PaddleVideo1/output/output/after_1/0711-1_0_0.avi"
label = "playing phone!"
start_frame = 100
end_frame = 600
video_label(video_path,label,start_frame,end_frame)