WebCam流上的时间覆盖

时间:2019-08-27 07:54:45

标签: python opencv gstreamer

我想在图像上编码或添加时间戳。因为这是在远程设备上运行的Web应用程序的一部分。解决此问题的最佳方法是什么?如何使用cv2将time.time()添加到图像本身。

如有其他建议,请随时提出建议

class CameraDevice():
    def __init__(self):
        self.cap = cv2.VideoCapture(0)
        self.time = time() #timestamp
        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

async def get_latest_frame(self):
    ret, frame = self.cap.read()
    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()

1 个答案:

答案 0 :(得分:-1)

您可以使用PIL在每个帧上添加日期。

from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont

...
pil_frame = Image.fromarray(img)
drawing = ImageDraw.Draw(pil_frame)
black = (3, 8, 12)
font = ImageFont.truetype("Pillow/Tests/fonts/FreeMono.ttf", 40)
drawing.text(pos, text, fill=black, font=font)
...

检查此链接:http://www.blog.pythonlibrary.org/2017/10/17/how-to-watermark-your-photos-with-python/