如何在opencv python中固定位置显示帧

2024-10-03 13:17:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在做一个项目,在这个项目中,我正在读取图像文件,并在框架上显示该图像的一些信息。到目前为止,我正在显示框架本身的所有信息,由于这些信息,框架看起来不太好:

enter image description here

我曾想过将信息的背景设置为黑色,以便更具可读性,但由于背景为黑色,它覆盖了图像中一些有用的部分。所以我想为什么不让我们把框架分成两部分。在左侧,我们将以黑色背景显示所有信息,在右侧,我们将显示全帧图像。如下所示:

enter image description here

我不确定是否可以显示上面的帧,因为将来我可能会显示视频/摄像机提要中的帧。如果有人已经这样做了,那么请让我知道。请帮忙。谢谢

下面是我正在使用的代码:

import cv2
import imutils

frame = cv2.imread('image.jpg')
frame = imutils.resize(frame, width=800, height=480)

cv2.putText(frame, "Some information", (5, 30), cv2.FONT_HERSHEY_COMPLEX_SMALL, 1, (0, 0, 255), 1)
cv2.putText(frame, "More information", (5, 60), cv2.FONT_HERSHEY_COMPLEX_SMALL, 1, (0, 0, 255), 1)
cv2.putText(frame, "Some more information", (5, 90), cv2.FONT_HERSHEY_COMPLEX_SMALL, 1, (0, 0, 255), 1)

cv2.imshow('Application', frame)
key = cv2.waitKey(0)

Tags: 项目图像import框架信息informationcv2frame
1条回答
网友
1楼 · 发布于 2024-10-03 13:17:26
import cv2
import numpy as np

frame = cv2.imread('image.jpg')
left = np.zeros((frame.shape[0], 400, frame.shape[2]), dtype=frame.dtype)

cv2.putText(left, "Some information", (5, 30), cv2.FONT_HERSHEY_COMPLEX_SMALL, 1, (0, 0, 255), 1)
cv2.putText(left, "More information", (5, 60), cv2.FONT_HERSHEY_COMPLEX_SMALL, 1, (0, 0, 255), 1)
cv2.putText(left, "Some more information", (5, 90), cv2.FONT_HERSHEY_COMPLEX_SMALL, 1, (0, 0, 255), 1)

img = np.hstack((left,frame))

cv2.imshow('Application', img)

enter image description here

相关问题 更多 >