Hi,
I was looking into adding a timestamp (some time refered to as timeoverlay) in the BalenaCam stream project, any ideas on how to modify or approch this feature.
The idea is that time is overlayed on the video, so we know in the excact time for record keeping, incase we only keep small part of the stream.
import asyncio, json, os, cv2, platform, sys
from time import sleep
from aiohttp import web
from av import VideoFrame
from aiortc import RTCPeerConnection, RTCSessionDescription, VideoStreamTrack, RTCIceServer, RTCConfiguration
from aiohttp_basicauth import BasicAuthMiddleware
class CameraDevice():
def __init__(self):
self.cap = cv2.VideoCapture(0)
self.cap.set(3, 640)
self.cap.set(4, 480)
def rotate(self, frame):
if flip:
(h, w) = frame.shape[:2]
center = (w/2, h/2)
M = cv2.getRotationMatrix2D(center, 180, 1.0)
frame = cv2.warpAffine(frame, M, (w, h))
return frame
This file has been truncated. show original
@mbalamat would you like to colobrate on this,
Hi @shams3049 ,
here https://github.com/balena-io-playground/balena-cam/blob/eb3519da565fb25a4b532a9b823f82eb86ea484b/balena-cam/app/server.py#L23 we get a frame of the camera. CV2 lib has a function cv2.putText() that puts text on a frame.
So you could put datetime as a text on the frame before it is returned.
Also PRs are welcome.
I hope this helps!
@mbalamat Yup, actually that’s what I was looking for. Thanks
if flip:
(h, w) = frame.shape[:2]
center = (w/2, h/2)
M = cv2.getRotationMatrix2D(center, 180, 1.0)
frame = cv2.warpAffine(frame, M, (w, h))
return frame
async def get_latest_frame(self):
font = cv2.FONT_HERSHEY_COMPLEX
ret, frame = self.cap.read()
frame = cv2.putText(frame, self.datet, (10,50), font, 1, (0, 255, 255), 2, cv2.LINE_AA)
await asyncio.sleep(0)
return self.rotate(frame)
async def get_jpeg_frame(self):
encode_param = (int(cv2.IMWRITE_JPEG_QUALITY), 90)
frame = await self.get_latest_frame()
frame, encimg = cv2.imencode('.jpg', frame, encode_param)
return encimg.tostring()
class PeerConnectionFactory():
I am not able to see any stream though, do you think there is something wroung with my implementation
Hey @shams3049 I added the same changes and it works.