我有代码屏幕记录和每一帧我有一套边界框,我想显示在每一帧。我可以使用matplotlib
或其他方法来完成这项工作,但是我mss
的工作速度大约为每秒30帧,我需要能够快速显示边界框。在
我在docsthis example中注意到了,但我尝试运行它,却无法让它显示任何内容。我甚至不确定这是否适用于我的例子。在
import cv2
import time
import numpy as np
from mss import mss
with mss() as sct:
# Part of the screen to capture
monitor = {"top": 79, "left": 265, "width": 905, "height": 586}
while "Screen capturing":
last_time = time.time()
# Get raw pixels from the screen, save it to a Numpy array
screen = np.array(sct.grab(monitor))
# print("fps: {}".format(1 / (time.time() - last_time)))
print('loop took {} seconds'.format(time.time()-last_time))
last_time = time.time()
screen = cv2.cvtColor(screen, cv2.COLOR_BGR2RGB)
screen = cv2.resize(screen, (224,224)).astype(np.float32)/255
# Display the picture
cv2.imshow("OpenCV/Numpy normal", screen)
# Press "q" to quit
if cv2.waitKey(25) & 0xFF == ord("q"):
cv2.destroyAllWindows()
break
现在假设我有一组边界框要显示在每一帧上,例如
^{pr2}$我可以改变像素以显示这个吗。我想我也可以通过opencv
来完成,因为这是最终显示屏幕的地方。在
{cd5>中的{cd4>框的大小都在{cd5>中
有一些遗漏的细节:
[x1, y1, x2, y2]
或[x1, y1, width, height]
或其他什么?在224, 224
)还是原始范围?在无论如何,您可以使用下面的函数绘制矩形(需要根据格式选择):
假设您定义了
bboxes
,那么可以调用函数:- 如果要在原始帧上绘制:
^{pr2}$经过一些更改,完整代码如下所示:
输出如下:
相关问题 更多 >
编程相关推荐