Ask Your Question

How to move image inside a video

asked 2018-12-23 04:00:00 -0500

Erandaka gravatar image

updated 2018-12-23 04:20:29 -0500

This code is working fine. output of below codeIt creates a noise video and moves a circle inside the video from left to right. But I want to do a different thing. I want to add moving images not a circle. Further says I have to create a video. Inside the video, I have to move images from left to right like the circle of the above code. I am a beginner to opencv and python. Could someone please help for giving some advises or references to reach my final outcome.

import numpy as np
import cv2
from cv2 import VideoWriter, VideoWriter_fourcc

def main2():
    width = 1280
    height = 720
    FPS = 24
    seconds = 10
    radius = 150
    paint_h = int(height / 2)

    img = cv2.imread('./before/mother.jpg')

    fourcc = VideoWriter_fourcc(*'MP42')
    video = VideoWriter('./circle_noise.avi', fourcc, float(FPS), (width, height))

    for paint_x in range(-radius, width + radius, 6):
        frame = np.random.randint(0, 256,
                                  (height, width, 3),
                                  dtype=np.uint8), (paint_x, paint_h), radius, (255, 255, 255), -1)

edit retag flag offensive close merge delete



you mean you want to have a video stream where pictures moves all over the video while it playing right?

Allaye gravatar imageAllaye ( 2018-12-23 05:18:49 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2018-12-23 06:12:14 -0500

berak gravatar image

it's all about numpy slices .

assuming, you have a small src image, and a larger dst image, you paste it like:

h,w,c = src.shape        # of the small insert image
x,y = ...                # top-left corner, where to put it in the large image.
dst[y:y+h, x:x+w] = src  # that's it already ;)
edit flag offensive delete link more


Absoultely, berak.

supra56 gravatar imagesupra56 ( 2018-12-23 12:00:47 -0500 )edit

you mean you want to have a video stream where pictures moves all over the video while it playing right? TorrentTurboTaxGogoanime

Morichtykoko gravatar imageMorichtykoko ( 2019-01-01 04:43:06 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2018-12-23 04:00:00 -0500

Seen: 642 times

Last updated: Dec 23 '18