当前位置:网站首页>Gadgets: color based video and image cutting
Gadgets: color based video and image cutting
2022-06-13 02:16:00 【zjuPeco】
List of articles
1 Preface
Recently, I worked on a short video related project , I found that many of the input videos have black edges , Some may be white edges or edges of other colors . This has a great impact on downstream model processing . So I wrote an automatic judge of the color of the filling edge , A gadget that automatically cuts video or pictures according to the color . This is really convenient , So share it .
The code is visible https://github.com/zjuPeco/color_base_image_crop.
2 Brief description of the scheme
All colors will rgb Values map to hsv After space , Then map to a color table summarized in advance . Every hsv Corresponding to a name in the color table .
For video cutting :
(1) Read the first frame of the video .
(3) If no background color is specified , According to the four corners of the picture block, Take the mode to infer the background color .block_size Can be set up .
(3) Get the color name corresponding to each pixel in the whole image , obtain mask.
(4) according to mask Select cut point , First, find it in the direction of width , And then find it according to the height .
(5) All frames of the video are cut according to the cutting point .
(6) Output the cut image to the specified size .
For image cutting :
(1) If no background color is specified , According to the four corners of the picture block, Take the mode to infer the background color .block_size Can be set up .
(2) Get the color name corresponding to each pixel in the whole image , obtain mask.
(3) according to mask Select cut point , First, find it in the direction of width , And then find it according to the height , And then find it in the direction of width .
(4) Output the cut image to the specified size .
3 effect
(1) Cut video , And output according to the cutting size .
python3 codes/crop_video_by_color.py --input_video ./data/1.mp4 --output_video ./results/videos/1.mp4

(2) Cut video , And press resize after crop Output to the specified size
python3 codes/crop_video_by_color.py --input_video ./data/1.mp4 --output_video ./results/videos/1_720x1080.mp4 --output_size 720x1080

(3) Cut video , And press resize after pad To the specified 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

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

边栏推荐
- What are the differences in cache/tlb?
- In addition to the full screen without holes under the screen, the Red Devils 7 series also has these black technologies
- Basic exercises of test questions letter graphics ※
- [work with notes] MFC solves the problem that pressing ESC and enter will automatically exit
- Ruixing coffee 2022, extricating itself from difficulties and ushering in a smooth path
- Configuring virtual private network FRR for Huawei equipment
- rsync 傳輸排除目錄
- Basic exercise of test questions Yanghui triangle (two-dimensional array and shallow copy)
- Area of basic exercise circle ※
- Armv8-m learning notes - getting started
猜你喜欢
![[51nod.3210] binary Statistics (bit operation)](/img/37/aa4a549deebf994b0049d41d49ff12.jpg)
[51nod.3210] binary Statistics (bit operation)
![[open source] libinimini: a minimalist ini parsing library for single chip computers](/img/99/f2ded6c189bd45ea6c1e9f86fd64c1.jpg)
[open source] libinimini: a minimalist ini parsing library for single chip computers

Introduction to armv8/armv9 - learning this article is enough
![[learning notes] xr872 GUI littlevgl 8.0 migration (file system)](/img/9b/0bf88354e8cfdbcc1ea91311c9a823.jpg)
[learning notes] xr872 GUI littlevgl 8.0 migration (file system)
![[the third day of actual combat of smart lock project based on stm32f401ret6 in 10 days] communication foundation and understanding serial port](/img/82/ed215078da0325b3adf95dcd6ffe30.jpg)
[the third day of actual combat of smart lock project based on stm32f401ret6 in 10 days] communication foundation and understanding serial port

Huawei equipment is configured with CE dual attribution

Chapter7-11_ Deep Learning for Question Answering (2/2)

Stm32+ze-08 formaldehyde sensor tutorial
![[the second day of actual combat of smart lock project based on stm32f401ret6 in 10 days] (lighting with library function and register respectively)](/img/f7/b2463d8ffe75113d352cae332046db.jpg)
[the second day of actual combat of smart lock project based on stm32f401ret6 in 10 days] (lighting with library function and register respectively)

Barrykay electronics rushes to the scientific innovation board: it is planned to raise 360million yuan. Mr. and Mrs. Wang Binhua are the major shareholders
随机推荐
Restrict cell input type and display format in CXGRID control
How to learn C language and share super detailed experience (learning note 1 -- basic data types of C language)
ROS learning-6 detailed explanation of publisher programming syntax
Ruixing coffee 2022, extricating itself from difficulties and ushering in a smooth path
Decoding iFLYTEK open platform 2.0 is a fertile land for developers and a source of industrial innovation
Armv8-m (Cortex-M) TrustZone summary and introduction
I didn't expect that the index occupies several times as much space as the data MySQL queries the space occupied by each table in the database, and the space occupied by data and indexes. It is used i
Application and examples of C language structure
The commercial value of Kwai is being seen by more and more brands and businesses
Huawei equipment is configured with CE dual attribution
[the 4th day of the 10 day smart lock project based on stm32f401ret6] what is interrupt, interrupt service function, system tick timer
Record: how to solve the problem of "the system cannot find the specified path" in the picture message uploaded by transferto() of multipartfile class [valid through personal test]
【 unity】 Problems Encountered in Packaging webgl Project and their resolution Records
JS get element
Paper reading - beat tracking by dynamic programming
Rsync transport exclusion directory
Sensor: sht30 temperature and humidity sensor testing ambient temperature and humidity experiment (code attached at the bottom)
ROS learning-8 pit for custom action programming
Looking at Qianxin's "wild prospect" of network security from the 2021 annual performance report
Vivo released originos ocean, and the domestic customized system is getting better and better