溫馨提示×

OpenCV怎么對視頻幀進行注釋和標記

小億
129
2024-05-23 11:31:08
欄目: 編程語言

在OpenCV中對視頻幀進行注釋和標記可以使用cv2.putText()和cv2.rectangle()等函數。下面是一個簡單的示例代碼,演示如何在視頻幀中注釋和標記一個矩形框和文字:

import cv2

cap = cv2.VideoCapture('video.mp4')

while cap.isOpened():
    ret, frame = cap.read()
    
    if not ret:
        break
    
    # 在視頻幀中繪制矩形框
    cv2.rectangle(frame, (100, 100), (300, 300), (255, 0, 0), 2)
    
    # 在視頻幀中添加文字
    cv2.putText(frame, 'Example', (100, 80), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 0, 0), 2)
    
    cv2.imshow('Video', frame)
    
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()

在上面的示例中,我們使用cv2.rectangle()函數在視頻幀中繪制了一個矩形框,使用cv2.putText()函數在視頻幀中添加了一個文字。您可以根據需要調整參數來修改文字內容、位置、顏色等。

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女