Recently, we wanted to merge two images into one using a custom black and white mask. To avoid using heavy GUI-based software, we decided to do it using the composite command of the ImageMagick package. Using the composite program, you can overlap one image over another. The command used is straightforward once you get the order of the parameters in the command line.
The first parameter (${BLACK_PART}) is the input picture you want to be placed in all black parts of the mask. The second parameter (${WHITE_PART}) is the input photo you wish to use on all white parts of the mask. The third parameter (${MASK}) is the black and white image that you will be used to merge the previous two images. The final parameter (${OUTPUT}) is the filename to write the final results.
Below we present the results of a demo we created using the above command:
Recently, we were trying to apply blurriness to the frames of a video using a custom mask. Our needs would not be short of describing using geometric shapes, so we created the following image (blur.png) as a template for the blurring effect:
The above mask applies a blur effect to all black pixels and leaves all white pixels in the original image intact.
This command creates a new copy of the input file and places it into the folder named blur, so be sure to make the folder before using the above command (e.g., using the command mkdir blur).
Parameters and other information
-mask this flag assosiates the filename that is given with the mask of the command.
-blur defines the geometry that is used reduce image noise and reduce detail levels. To increase the blurriness you can increase the number in this variable 0x8.
+mask The ‘plus’ form of the operator +mask removes the mask from the input image.
The version of convert that we used for this example was the following:
The above command finds all frames in the current folder and executes the convert command described above. Since FFmpeg names the frames as PPM, we used that to filter our search. The blur folder is in the same folder as the original images. To avoid processing the pictures in that folder again, we defined the -maxdepth parameter in find that prevents it from navigating into child folders of the one we are working in.
Source code for the implementation that created this video will be uploaded soon.
A first attempt at using a pre-trained implementation of Mask R-CNN on Python 3, Keras, and TensorFlow. The model generates bounding boxes and segmentation masks for each instance of an object in each frame. It’s based on Feature Pyramid Network (FPN) and a ResNet101 backbone.
Setup
Conda / Anaconda
First of all, we installed and activated anaconda on an Ubuntu 20.04LTS desktop. To do so, we installed the following dependencies from the repositories:
Following the previous step, we used the commands below to create a virtual environment for our code. We needed python version 3.9 (as highlighted here https://www.anaconda.com/products/individual#linux) and OpenCV for python.
When we tried to execute our code in the virtual environment:
python3 main.py --video="/home/bob/Videos/Live @ Santa Claus Village 2021-11-13 12_12.mp4";
We got the following error:
Traceback (most recent call last):
File "/home/bob/MaskRCNN/main.py", line 6, in <module>
from cv2 import cv2
File "/home/bob/anaconda3/envs/MaskRNN/lib/python3.9/site-packages/cv2/__init__.py", line 180, in <module>
bootstrap()
File "/home/bob/anaconda3/envs/MaskRNN/lib/python3.9/site-packages/cv2/__init__.py", line 152, in bootstrap
native_module = importlib.import_module("cv2")
File "/home/bob/anaconda3/envs/MaskRNN/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ImportError: libGL.so.1: cannot open shared object file: No such file or directory
We realized that we were missing some additional dependencies for OpenCV as our Ubuntu installation was minimal. To fix this issue, we installed the following package from the repositories:
Assuming you want to make the following changes to the network device eth0
Change the IP to the static value 192.168.1.2
Set the Subnet Mask to 255.255.255.0
Set the Default Gateway for the device to be 192.168.1.1
and you want to avoid using ifconfig and route that are obsolete you can perform these changes using the following two commands
sudo ip addr add 192.168.1.2/24 dev eth0;
sudo ip route add default via 192.168.1.1 dev eth0;
Please note that the netmask is given in CIDR notation (it is the /24 right after the IP of the device in the ip addr command).
A subnet mask (netmask) is a bitmask that encodes the prefix length in quad-dotted notation: 32 bits, starting with a number of 1 bits equal to the prefix length, ending with 0 bits, and encoded in four-part dotted-decimal format: 255.255.255.0. A subnet mask encodes the same information as a prefix length, but predates the advent of CIDR. In CIDR notation, the prefix bits are always contiguous, whereas subnet masks may specify non-contiguous bits.