Skip to content

zjuPeco/color_base_image_crop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Color based image/video crop

This repo is a simple tool to cut image or video based on color by python. You can remove the annoying padding with a simple command.

Usage and results

There are a few differences between cropping a video and cropping an image.

Crop Video

Steps:

(1) Auto detect the padding color with the four corners of the video or Use the padding color specified by user.

(2) Find the hsv space range with the padding color.

(3) Get the color mask of the first frame with the hsv space range.

(4) Cut all frames with the mask of the first frame. Once along width and Once along height.

(5) Resize all frames to the desired output size.

Commands:

Just input the video and give an output path.

python3 codes/crop_video_by_color.py --input_video ./data/1.mp4 --output_video ./results/videos/1.mp4

auto crop

Resize the image and crop to the output size.

python3 codes/crop_video_by_color.py --input_video ./data/1.mp4 --output_video ./results/videos/1_720x1080.mp4 --output_size 720x1080

resize and crop

Resize the image and pad to the output size

python3 codes/crop_video_by_color.py --input_video ./data/1.mp4 --output_video ./results/videos/1_720x1080_pad.mp4 --output_size 720x1080 --pad_mode outside

resize and pad

Crop Image

Steps:

(1) Auto detect the padding color with the four corners of the image or Use the padding color specified by user.

(2) Find the hsv space range with the padding color.

(3) Get the color mask of the image with the hsv space range.

(4) Cut image with the mask. Once along width and twice along height.

(5) Resize all frames to the desired output size.

Command:

python3 codes/crop_image_by_color.py --input_image ./data/5.jpeg --output_image_dir ./results/images/5/

auto crop

You can also specify the output size just like it does while cropping a video.

To do

  • Improve the accuracy of auto detecting padding color.
  • Refer to more frames while cutting a video.

About

crop images or videos by padding color

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages