moviepy音视频剪辑:headblur函数遇到的TypeError: integer argument expected, got float错误的解决方案

运行环境如下:

python版本:3.7
opencv-python版本:4.2.0.34
numpy版本:1.19.0

错误信息:

在调用moviepy1.03版本的headblur函数执行人脸跟踪和模糊化处理时,报如下错误:

  File "F:/study/python/project/moviepyTest/moviepyTest.py", line 63, in <module>
    clip_blurred = clip.fx(vfx.headblur, tracking.xi, tracking.yi, 30) #进行模糊化处理,圆半径设置为30像素
  File "C:\Program Files\Python37\lib\site-packages\moviepy\Clip.py", line 212, in fx
    return func(self, *args, **kwargs)
  File "C:\Program Files\Python37\lib\site-packages\moviepy\video\fx\headblur.py", line 53, in headblur
    return clip.fl(fl)
  File "C:\Program Files\Python37\lib\site-packages\moviepy\Clip.py", line 136, in fl
    newclip = self.set_make_frame(lambda t: fun(self.get_frame, t))
  File "", line 2, in set_make_frame
  File "C:\Program Files\Python37\lib\site-packages\moviepy\decorators.py", line 14, in outplace
    f(newclip, *a, **k)
  File "C:\Program Files\Python37\lib\site-packages\moviepy\video\VideoClip.py", line 644, in set_make_frame
    self.size = self.get_frame(0).shape[:2][::-1]
  File "", line 2, in get_frame
  File "C:\Program Files\Python37\lib\site-packages\moviepy\decorators.py", line 89, in wrapper
    return f(*new_a, **new_kw)
  File "C:\Program Files\Python37\lib\site-packages\moviepy\Clip.py", line 93, in get_frame
    return self.make_frame(t)
  File "C:\Program Files\Python37\lib\site-packages\moviepy\Clip.py", line 136, in <lambda>
    newclip = self.set_make_frame(lambda t: fun(self.get_frame, t))
  File "C:\Program Files\Python37\lib\site-packages\moviepy\video\fx\headblur.py", line 42, in fl
    blurred = cv2.blur(orig, (r_blur, r_blur))
TypeError: integer argument expected, got float

Process finished with exit code 1
解决办法:

以下两种方法任选一种即可:
1、在调用headblur函数时,设置参数值为一个整数;
2、修改headblur函数,将if r_blur is None: r_blur = 2 * r_zone / 3
改为:if r_blur is None: r_blur = int(2 * r_zone / 3)

更多moviepy的介绍请参考《PyQt+moviepy音视频剪辑实战文章目录》或《moviepy音视频开发专栏》。

关于收费专栏

老猿的付费专栏《使用PyQt开发图形界面Python应用》专门介绍基于Python的PyQt图形界面开发基础教程,付费专栏《moviepy音视频开发专栏》详细介绍moviepy音视频剪辑合成处理的类相关方法及使用相关方法进行相关剪辑合成场景的处理,两个专栏加起来只需要19.9元,都适合有一定Python基础但无相关专利知识的小白读者学习。这2个收费专栏都有对应免费专栏,只是收费专栏的文章介绍更具体、内容更深入、案例更多。

对于缺乏Python基础的同仁,可以通过老猿的免费专栏《专栏:Python基础教程目录》从零开始学习Python。

如果有兴趣也愿意支持老猿的读者,欢迎购买付费专栏。

跟老猿学Python、学5G!

☞ ░ 前往老猿Python博文目录 ░

你可能感兴趣的:(老猿Python,python,音视频开发,编程语言,moviepy音视频剪辑合成,人脸跟踪)