我正在研究一個帶有 april 標簽和計算機視覺系統的專案,以從網路攝像頭中檢測它們。到目前為止,我有一個很好的系統,可以將資料列印到終端,但我想在視頻視窗頂部或另一個視窗中顯示這個數字/文本資料。我已經嘗試過使用cv2.putText(),但這只會在頁面上放置靜態文本,并且無法像我想要的那樣實時更新。這是我的代碼,它嘗試使用網路攝像頭視頻中檢測到的標簽數量實時更新視窗。但它最終只是寫了一個1例子,我想不出一種方法來洗掉那個文本并更新它。
這在 OpenCV 中是否可行?還是有其他方法?
while True:
success, frame = cap.read()
if not success:
break
gray = cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY)
detections, dimg = detector.detect(gray, return_image=True)
print(detections)
num_detections = len(detections)
# print('Detected {} tags.\n'.format(num_detections))
num_detections_string = str(num_detections)
overlay = frame // 2 dimg[:, :, None] // 2
clear_text = ''
text = checkNumDetections(num_detections, num_detections_string)
cv2.putText(whiteBackground, clear_text, (100, 100), cv2.FONT_HERSHEY_PLAIN, 10, (0, 255, 0), 2)
cv2.putText(whiteBackground, text, (100, 100), cv2.FONT_HERSHEY_PLAIN, 10, (0, 255, 0), 2)
cv2.imshow(window, overlay)
k = cv2.waitKey(1)
cv2.imshow(dataWindow, whiteBackground)
if k == 27:
break
uj5u.com熱心網友回復:
您需要在每個回圈中重新初始化“whiteBackground”影像,然后再在其上繪制任何內容。
我知道這會起作用,但它會給你一個黑色的背景:
whiteBackground = np.zeros((columns, rows, channels), dtype = "uint8")
這應該可以為您提供白色背景,但請嘗試并查看:
whiteBackground = np.full((columns, rows, channels), 255, dtype = "uint8")
我通常在 c 中使用 opencv,所以我不能 100% 確定確切的語法,但這應該可以。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/510783.html
下一篇:在螢屏之間傳遞值Kivy
