The Python algorithm automatically cuts the video, and the video is silky smooth without a video editor

When I saw people using PR editing software to do this kind of silky one-click dress-up video, I wanted to try it myself. However, PR is too difficult to use, so it is better to type code to save trouble.

At first, I wanted to use moviepy's moviepy.video.fx.all.mask_color mask for processing, but found that the complexity of target recognition was a bit too high. Then change the way of thinking and deal with it, it will be successful. Let's take a look at the finished product first.

Python silky clothes changing algorithm demonstration

Or the old way to talk about the machine configuration first, if the machine configuration is not enough, you can't play this.

Software, hardware and skill requirements

  • The best CPU is I7-8750 or above, otherwise the overall production will be very slow
  • Python version 3.6 and above
  • Due to the modules involved in deep learning, a graphics card is required from now on.

Description of color transformation

  • A wide range of color spaces are supported. Such as conversion between various color spaces such as RGB, HSL/HSV, CMY/CMYK, etc. For example XYZ to sRGB, Spectral to XYZ, CIE Lab to Adobe RGB.
  • Color difference calculation.
  • Color adaptation (change light source).
  • RGB to hex and vice versa.

Python application plugin

colormath and MiVOS apply color conversion adjustments and module interactivity, respectively.

Thought process

You might be wondering where this thing came out?

First of all, we need to understand the method of color switching conversion.

Simple example of CIE Lab to CIE XYZ conversion.

from colormath.color_objects import LabColor, XYZColor
from colormath.color_conversions import convert_color

lab = LabColor(0.903, 16.296, -2.22)
xyz = convert_color(lab, XYZColor)

want to convert using a different RGB space

from colormath.color_objects import XYZColor, HSLColor, AdobeRGBColor
from colormath.color_conversions import convert_color

xyz = XYZColor(0.1, 0.2, 0.3)
hsl = convert_color(xyz, HSLColor, through_rgb_type=AdobeRGBColor)
# 转换回 XYZ,确保在 return 时使用相同的 RGB 颜色空间。
xyz2 = convert_color(hsl, XYZColor, through_rgb_type=AdobeRGBColor)

Delta E equation

from colormath.color_objects import LabColor
from colormath.color_diff import delta_e_cie1976

# 参考颜色
color1 = LabColor(lab_l=0.9, lab_a=16.3, lab_b=-2.22)
# 与参考进行比较的颜色
color2 = LabColor(lab_l=0.7, lab_a=14.2, lab_b=-1.80)
# 作为浮点数的 delta E 值
delta_e = delta_e_cie1976(color1, color2)

MiVOS module interactive

You can understand this place as replacing the final composite effect picture frame by frame after identifying the corresponding color point.

insert image description here

insert image description here
insert image description here

Guess you like

Origin blog.csdn.net/qq_20288327/article/details/123897091