运行环境如下:
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 "<decorator-gen-61>", 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 "<decorator-gen-11>", 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音视频开发专栏》。