【发布时间】:2022-09-28 17:18:28
【问题描述】:
我正在开发一个带有 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
-
你真的不能“擦除”任何东西。最好为循环中的任何帧创建一个新的
whiteBackground