Ask Your Question

show video and texts on single window

asked 2020-07-17 08:14:34 -0500

Jitendra gravatar image

updated 2020-07-17 08:39:35 -0500

Hi, I would like to show a video stream and sensors data to same window. But video should be displayed in Left half of the LCD and Sensors data should be displayed on right half of the LCD.

I am using 800x480 resolution LCD to display. I could show video and text on same video using opencv. But I don't have idea about above thing.

Please be needful.

I am newbie to opencv, so might be couldn't explain you clearly. Please find below code till now.

import cv2
import sys
import numpy as np
import logging as log
import datetime as dt
from time import sleep
import imutils

b,g,r,a = 0,255,0,0
video_capture = cv2.VideoCapture(0)
anterior = 0

while True:
if not video_capture.isOpened():
    print('Unable to load camera.')

# Capture frame-by-frame
ret, frame =
frame = imutils.resize(frame, width=800,height=480)

text = "Hello"
cv2.putText(frame,text,(100,100),cv2.FONT_HERSHEY_SIMPLEX, 1.5, (b,g,r),1,cv2.LINE_AA)

if cv2.waitKey(1) & 0xFF == ord('q'):

# Display the resulting frame
cv2.imshow('Video', frame)

# When everything is done, release the capture

Thanks in advance. Jitendra

edit retag flag offensive close merge delete

3 answers

Sort by ยป oldest newest most voted

answered 2020-07-17 10:53:49 -0500

berak gravatar image

updated 2020-07-17 13:29:17 -0500

if you really make it "equal halves", your video will look like shit, also text is more or less a "horizontal" thing, so i propose a slightly different idea:

#1: make a nice large empty image:
draw = np.zeros((480,800,3), dtype=np.uint8)

#2: resize the cam frame to 640x480 (keeping a decent aspect ratio)
frame = cv2.resize(frame, (640,480))

#3: blit it into the large img
draw[0:480, 0:640, :] = frame

#3.a: your text rendering into the "draw" mat
# (your code here !)

#4: show it
cv2.imshow("XXX", draw)

#5: update the window (should go *after* imshow())
if cv2.waitKey(1) & 0xFF == ord('q'):

this will leave you with a 800x160 drawing space below the cam img, and another 160x480 region on the right

edit flag offensive delete link more


nice answer! just wonder is it possible in python to resize image directly in a roi of other image

sturkmen gravatar imagesturkmen ( 2020-07-17 11:41:17 -0500 )edit

yes it works

draw = np.zeros((480,800,3), dtype=np.uint8)
frame = cv2.imread(cv2.samples.findFile("lena.jpg"))
draw[0:480, 0:640, :] = cv2.resize(frame, (640,480))
sturkmen gravatar imagesturkmen ( 2020-07-17 14:44:55 -0500 )edit

answered 2020-07-17 10:57:55 -0500

kbarni gravatar image

Create 2 images, one with the video feed (let's say 640x480), the other one with the text (in this case 160x480). Then use frame = hconcat([video,text]) to concatenate them into a 800x480 frame.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2020-07-17 08:14:34 -0500

Seen: 92 times

Last updated: Jul 17 '20