运行环境如下:
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 FilesPython37libsite-packagesmoviepyClip.py", line 212, in fx
return func(self, *args, **kwargs)
File "C:Program FilesPython37libsite-packagesmoviepyvideofxheadblur.py", line 53, in headblur
return clip.fl(fl)
File "C:Program FilesPython37libsite-packagesmoviepyClip.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 FilesPython37libsite-packagesmoviepydecorators.py", line 14, in outplace
f(newclip, *a, **k)
File "C:Program FilesPython37libsite-packagesmoviepyvideoVideoClip.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 FilesPython37libsite-packagesmoviepydecorators.py", line 89, in wrapper
return f(*new_a, **new_kw)
File "C:Program FilesPython37libsite-packagesmoviepyClip.py", line 93, in get_frame
return self.make_frame(t)
File "C:Program FilesPython37libsite-packagesmoviepyClip.py", line 136, in <lambda>
newclip = self.set_make_frame(lambda t: fun(self.get_frame, t))
File "C:Program FilesPython37libsite-packagesmoviepyvideofxheadblur.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。
如果有兴趣也愿意支持老猿的读者,欢迎购买付费专栏。