Inserting text into a stream using Python OpenCV
Question: Good day, which adds to the video stream and sends the text back into the
stream. The idea is that I want the program to listen to certain IP addresses
and port stream, using the OpenCV library, this stream divided into frames and
each frame inserted text and then re-imposed in the stream. I need to do this
in python. Input and output stream will use the H.264 codec. Here I found the
code in python which can thus adjust the video, but I needed to do this from
the stream. Please advise.

    
    
    import numpy as np
    import cv2
    
    capture = cv2.VideoCapture(0)
    capture = cv2.VideoCapture("simpsnovi,prilis_drsne_pro_tv_03.avi")
    
    flag, frame = capture.read()
    width = np.size(frame, 1)
    height = np.size(frame, 0)
    #fourcc=cv2.cv.CV_FOURCC('I', 'Y', 'U', 'V'), #this is the codec that works for me
    writer = cv2.VideoWriter(filename="your_writing_file.avi", 
    fourcc=cv2.cv.CV_FOURCC('X','V','I','D'), #this is the codec that works for me
    
    fps=25, #frames per second, I suggest 15 as a rough initial estimate
    frameSize=(width, height))
    
    while True:
        flag, frame = capture.read()
        if flag == 0:
            break
        x = width/2
        y = height/2
        text_color = (255,0,0)
        cv2.putText(frame, "your_string", (x,y), cv2.FONT_HERSHEY_PLAIN, 1.0, text_color, thickness=1,linetype=cv2.CV_AA)
        writer.write(frame)
    


Answer: First of all you need **UDP** socket server! That server will listen on some
IP and PORT for you. Then, you can work with OpenCV.

