Paste video on the top of the image

Hi, i am new in open cv tool. I hope you guys help to fix this issue .
My concept is paste video on the top of the image.
I mean the image will be backward and the video will be forward!

bgrm_image(this is the image which i want to use as a background of the video )
nparr = np.fromstring(bgrm_image, np.uint8)
bgrm_Img = cv2.imdecode(nparr, cv2.IMREAD_UNCHANGED)
vid = cv2.VideoCapture("transperent.mov")
ret, frame = vid.read()
 try:
        while(ret):
            ret, frame = vid.read()
            if not ret:
                break
            image = cv2.resize(bgrm_Img,(300,300))
            frame = cvzone.overlayPNG(
                image, frame,  [50, 50])
    except Exception as error:
        print(">>>>> error", str(error))
OpenCV(4.6.0) /io/opencv/modules/core/src/arithm.cpp:212: error: (-209:Sizes of input arguments do not match) The operation is neither 'array op array' (where arrays have the same size and type), nor 'array op scalar', nor 'scalar op array' in function 'b

well, your code does not do that. instead it tries to copy a resized version of ‘frame’ onto itself (and fails for god knows why, you’d probably have to look here)

Thanks of response .but the reference you gave i already tried to follow.but the problem is my concept is different . the video will go on the top of image. if it possible ,pls give me more explanation how should i do .
The code bellow is working for image on top of the video

while(ret):
            ret, frame = vid.read()
            if not ret:
                break
            subject = cv2.resize(frame, (250, 250))
            frame = cvzone.overlayPNG(
                frame,  subject, [50, 50])

for starters, you never use bgrm_Img , and you got imgBack, imgFront swapped (thus the error). then, if you really want to do anything using alpha, the overlay needs alpha (but what you get from VideoCapture does not have any), not the bg (your ‘concept’ looks kaputt).

if you dont need alpha (‘replace mode’), it would be a simple:

bgrm_Img = cv2.imdecode(nparr, cv2.IMREAD_COLOR)

# ... later:
bgrm_Img[50:300, 50:300] = subject
# use bgrm_Img further on, not frame ...

(again, try to do without cvzone.overlayPNG, unless you’re 100% clear, why you want to use that !!)

Yeah.You are right!. It’s my bad . Actually i tried this way before

nparr = np.fromstring(bgrm_image, np.uint8)
bgrm_Img = cv2.imdecode(nparr, cv2.IMREAD_UNCHANGED)
vid = cv2.VideoCapture("transperent.mov")
ret, frame = vid.read()
 try:
        while(ret):
            ret, frame = vid.read()
            if not ret:
                break
            image = cv2.resize(bgrm_Img,(300,300))
            frame = cvzone.overlayPNG(
                image, frame,  [50, 50])
    except Exception as error:
        print(">>>>> error", str(error))

i used cvzone.overlayPNG ,so that both image and video go top of each other .

if so, please delete (or answer) your crosspost, else you’re wasting other folks precious time …

yes. but i didn’t find my solution yet !!!