如何在opencv python中的固定位置显示框架

问题描述 投票:0回答:1

我正在一个项目中,我正在其中读取图像文件并在框架上显示该图像的一些信息。截止到目前,我正在框架上显示所有信息,因此看起来不太好:

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)
python opencv frames
1个回答
0
投票
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

© www.soinside.com 2019 - 2024. All rights reserved.