How to mask a video with an image on opencv - python

I want to create a mask over the whole human figure and replace it with an image that is responsive to the moving human figure. The image attached will give you a better idea of what is I mean.
The Image in the background will be still and won't move but the figure will seem like it punched a hole into the foreground. The figures however they move will go over the static background image and show the contents of the image. The figures, if they overlap as seen in the first image (see overlapping leg) should not break the mask and should still display the contents of the background.

Related

Is there a way to increase the size of the background image in turtle?

I am trying to make a game in python 3 which requires a background image. I already have the image. The problem here is my image looks small compared to the big screen. I don't want to change the size of the screen because then I would have to redo all the coordinates of the other objects on the screen. Is there any way I can increase the size of the background image?
Ps. I'm using Python 3 and on VS code.
Thanks in advance!
This is the picture of what the small picture looks like.enter image description here
In order to increase the size of the image, you would need too increase the resolution.
Assuming that you are using windows, open the png with Microsoft Photos, and click on the three horizontal dots at the top right.
A dropdown menu will open, press the third option from the top labeled "Resize"
After this, press on "Define custom dimensions" and you may manipulate the dimensions of the image as you like.
Then, simply save the resized image, and use it in your project.
you can also do this using CV2 library
import cv2
image=cv2.imread("image.png")
scale_percent=1.5
width=int(image.shape[1]*scale_percent)
height=int(image.shape[0]*scale_percent)
dimension=(width,height)
resized = cv2.resize(image,dimension, interpolation = cv2.INTER_AREA)
print(resized.shape)
cv2.imwrite("output.png",resized)
OR you can use PIL library as well
from PIL import Image
image = Image.open("image.png")
image.save("output.png", dpi=(image.size[0]*1.5,image.size[1]*1.5))

Lines drawn around Region of Interest (ROI) using OpenCV

The role of this program is to draw Houghlines on an external window, when lines are detected in a game. However, when I implemented the ROI to avoid having useless lines detected, the border of the ROI is still detected as a line (obviously it is)
As shown in the image below, you may notice how the arrow show the detected line from the ROI.
How can I make it that it ignores the lines around the border?
I tried to overlap the ROI with other lines but openCV still detects the borders as lines.
I am using Python.
Thanks!
Solved it, was an amateur mistake! If anyone meets this problem, you will have to fix it by putting the region of interest code after converting the image to gray and then to edge detection; hence, Convert image to gray -> Convert image to Canny/Sobel (edge detection) -> Set image to ROI

Opencv: How to stitch four trapezoid images to make a square image?

I am currently trying very hard to figure out a way to make these four trapezoid images into one nice image. The final image should look something like this(used photoshop to make it):
That above image will be complied with four of these images:
The problem is that when I try to rotate and combine these images, the black surroundings come into the final image as well like this:
How am I supposed to rid of the blacked out area or make it transparent? I've tried using a mask but that only make the black area white instead. I have also tried using the alpha channel, but that didn't work(although maybe I was doing wrong). Any ideas on what I can do in OpenCV?
I did actually figure it out. I did it with these steps:
Create two SAME SIZED black backgrounds with numpy zeros
Put one image in each background where you want them(for me, it was left and top)
Then all you need to do is cv.add(first, second)
The reason it works is because black pixels are 0,0,0 so adding to a pixel that is, say, 25,62,34, the pixel doesn't change and thus rids of the black corner.

Custom shape cutouts of a video using Python

I wish to use Python to show a cutout in a certain shape of one video overlaid on top of another video. The invisible parts of the overlaid video should be translucent, so the 'background' video can be seen in those parts. The issue here is that the location of the overlay is dynamic, while the shape remains the same. This means I cannot simply preprocess the videos.
I was thinking to take stills from the overlaid video at runtime, cut out the overlay and superimpose it on the background video in the right location. This would have to be done at a high frequency (30 fps+, probably).
As an example:
I would want the red cutout of this image:
http://i.imgur.com/jEQqvR0.jpg
to appear on top of another image
The Python Image Library (PIL) seems to be able to crop images easily, but only in rectangles and not in a custom shape. I could probably add rectangles together to create a custom shape, but I was hoping there would be an easier way. Maybe I'm overlooking things.
So my question is: What would be the easiest way to do the cut-out? I'm also open to other suggestions for approaches. Ideally, I would use a dynamically positioned translucent video mask partially obscuring the background video with parts of the overlaid video but I'm not sure if this is at all possible.

How can I make the background of an image appear transparent without PIL?

I'm trying to make a GUI in tkinter that uses one image as an overlay on top of another, but when I place the image over the lower one, the transparent area of the image appears as grey.
I've searched for solutions to this, but all the results that I've found have pointed towards using PIL.
Is it possible for me to use transparent, or partially transparent images in the python tkinter module without using PIL?
You could use some basic photoshop tools like the magic wand tool to remove the background, but keep in mind, some PNG format images have a faint background. This is either in the from of a watermark, or the image background was rendered with a lower opacity than the rest of the image. Your GUI may also have a layer placed above the images by default. Does it appear on each image seperatly when loaded into the GUI?

Categories