Ask Your Question
0

How to move image inside a video

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

Erandaka gravatar image

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

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)
        cv2.circle(frame, (paint_x, paint_h), radius, (255, 255, 255), -1)
        video.write(frame)

    video.release()
edit retag flag offensive close merge delete

Comments

2

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 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
3

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

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

Comments

Absoultely, berak.

supra56 gravatar imagesupra56 ( 2018-12-23 12:00:47 -0600 )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 -0600 )edit

Question Tools

1 follower

Stats

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

Seen: 1,744 times

Last updated: Dec 23 '18