VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > temp > 简明python教程 >
  • 【Python | opencv+PIL】常见操作(创建、添加帧、绘图、读取等)的效率对比及其(3)

(sec) ======================================== ======================================== Function name: task_3 ======================================== Function has the return content below: None ======================================== Summary of Function Timer: Count of loops: 100 Average time of loops: 0.013229802739999979 (sec) Minimum of every loop time: 0.01082132600000002 (sec) Maximum of every loop time: 0.018015121000000023 (sec) Total time of loops: 1.3229802739999978 (sec) ======================================== ======================================== Function name: task_4 ======================================== Function has the return content below: None ======================================== Summary of Function Timer: Count of loops: 100 Average time of loops: 2.1959869999998995e-05 (sec) Minimum of every loop time: 3.109999999750812e-07 (sec) Maximum of every loop time: 0.0021468490000000617 (sec) Total time of loops: 0.0021959869999998993 (sec) ======================================== ======================================== Function name: task_5_matrix ======================================== Function has the return content below: None ======================================== Summary of Function Timer: Count of loops: 100 Average time of loops: 1.4977880000011101e-05 (sec) Minimum of every loop time: 1.0263000000065858e-05 (sec) Maximum of every loop time: 4.571699999988965e-05 (sec) Total time of loops: 0.0014977880000011101 (sec) ======================================== ======================================== Function name: task_5_pillow ======================================== Function has the return content below: None ======================================== Summary of Function Timer: Count of loops: 100 Average time of loops: 0.0029445669399999997 (sec) Minimum of every loop time: 0.0026519169999998926 (sec) Maximum of every loop time: 0.00473345600000008 (sec) Total time of loops: 0.29445669399999996 (sec) ======================================== ======================================== Function name: task_6_opencv ======================================== Function has the return content below: None ======================================== Summary of Function Timer: Count of loops: 100 Average time of loops: 0.02255292473999999 (sec) Minimum of every loop time: 0.021661312000000432 (sec) Maximum of every loop time: 0.032752587999999694 (sec) Total time of loops: 2.255292473999999 (sec) ======================================== ======================================== Function name: task_6_pillow ======================================== Function has the return content below: None ======================================== Summary of Function Timer: Count of loops: 100 Average time of loops: 0.00025689415000005765 (sec) Minimum of every loop time: 0.0001309319999993619 (sec) Maximum of every loop time: 0.011476918999999697 (sec) Total time of loops: 0.025689415000005766 (sec) ======================================== ======================================== Function name: task_7_list ======================================== Function has the return content below: None ======================================== Summary of Function Timer: Count of loops: 100 Average time of loops: 0.38457812533999997 (sec) Minimum of every loop time: 0.3564736689999961 (sec) Maximum of every loop time: 0.4698194010000005 (sec) Total time of loops: 38.457812534 (sec) ======================================== ======================================== Function name: task_7_asarray ======================================== Function has the return content below: None ======================================== Summary of Function Timer: Count of loops: 100 Average time of loops: 0.007278045390000258 (sec) Minimum of every loop time: 0.007068772000003776 (sec) Maximum of every loop time: 0.007784698999998341 (sec) Total time of loops: 0.7278045390000258 (sec) ======================================== ======================================== Function name: task_7_array ======================================== Function has the return content below: None ======================================== Summary of Function Timer: Count of loops: 100 Average time of loops: 0.010643305210000377 (sec) Minimum of every loop time: 0.009964515000000063 (sec) Maximum of every loop time: 0.011806892999999263 (sec) Total time of loops: 1.0643305210000378 (sec) ======================================== ======================================== Function name: task_8_matrix ======================================== Function has the return content below: None ======================================== Summary of Function Timer: Count of loops: 100 Average time of loops: 2.8363499999528583e-06 (sec) Minimum of every loop time: 1.5549999972108708e-06 (sec) Maximum of every loop time: 4.1673999994884525e-05 (sec) Total time of loops: 0.00028363499999528585 (sec) ======================================== ======================================== Function name: task_8_pillow_putpixel ======================================== Function has the return content below: None ======================================== Summary of Function Timer: Count of loops: 100 Average time of loops: 2.1925700001901305e-06 (sec) Minimum of every loop time: 1.2439999963476112e-06 (sec) Maximum of every loop time: 2.1769999996479328e-05 (sec) Total time of loops: 0.00021925700001901305 (sec) ======================================== ======================================== Function name: task_8_pillow_point ======================================== Function has the return content below: None ======================================== Summary of Function Timer: Count of loops: 100 Average time of loops: 2.3574000000081697e-06 (sec) Minimum of every loop time: 1.5549999972108708e-06 (sec) Maximum of every loop time: 1.8971000002920846e-05 (sec) Total time of loops: 0.00023574000000081696 (sec) ======================================== ======================================== Function name: task_9_line_matrix ======================================== Function has the return content below: None ======================================== Summary of Function Timer: Count of loops: 100 Average time of loops: 0.0004368183000000414 (sec) Minimum of every loop time: 0.0004301160000039772 (sec) Maximum of every loop time: 0.000561359000002426 (sec) Total time of loops: 0.04368183000000414 (sec) ======================================== ======================================== Function name: task_9_line_pillow ======================================== Function has the return content below: None ======================================== Summary of Function Timer: Count of loops: 100 Average time of loops: 3.4956700000066122e-06 (sec) Minimum of every loop time: 2.4879999998006497e-06 (sec) Maximum of every loop time: 2.519200000250521e-05 (sec) Total time of loops: 0.0003495670000006612 (sec) ======================================== ======================================== Function name: task_9_line_opencv ======================================== Function has the return content below: None ======================================== Summary of Function Timer: Count of loops: 100 Average time of loops: 3.5982899999709163e-06 (sec) Minimum of every loop time: 2.4879999998006497e-06 (sec) Maximum of every loop time: 4.727200000331777e-05 (sec) Total time of loops: 0.0003598289999970916 (sec) ======================================== ======================================== Function name: task_9_rectangle_matrix ======================================== Function has the return content below: None ======================================== Summary of Function Timer: Count of loops: 100 Average time of loops: 0.1735227326999994 (sec) Minimum of every loop time: 0.17267937900000163 (sec) Maximum of every loop time: 0.19454626299999944 (sec) Total time of loops: 17.35227326999994 (sec) ======================================== ======================================== Function name: task_9_rectangle_pillow ======================================== Function has the return content below: None ======================================== Summary of Function Timer: Count of loops: 100 Average time of loops: 3.0409819999803745e-05 (sec) Minimum of every loop time: 2.9545000003849964e-05 (sec) Maximum of every loop time: 7.153000000670318e-05 (sec) Total time of loops: 0.0030409819999803744 (sec) ======================================== ======================================== Function name: task_9_rectangle_opencv ======================================== Function has the return content below: None ======================================== Summary of Function Timer: Count of loops: 100 Average time of loops: 6.522652000001016e-05 (sec) Minimum of every loop time: 6.25109999958795e-05 (sec) Maximum of every loop time: 0.0002674619999964989 (sec) Total time of loops: 0.006522652000001017 (sec) ======================================== ======================================== Function name: task_9_circle_pillow_arc ======================================== Function has the return content below: None ======================================== Summary of Function Timer: Count of loops: 100 Average time of loops: 2.7626349999891885e-05 (sec) Minimum of every loop time: 2.6745999996080627e-05 (sec) Maximum of every loop time: 6.531100000017886e-05 (sec) Total time of loops: 0.0027626349999891886 (sec) ======================================== ======================================== Function name: task_9_circle_pillow_ellipse ======================================== Function has the return content below: None ======================================== Summary of Function Timer: Count of loops: 100 Average time of loops: 0.0002000553400001337 (sec) Minimum of every loop time: 0.00019841900000017176 (sec) Maximum of every loop time: 0.0002512900000013474 (sec) Total time of loops: 0.02000553400001337 (sec) ======================================== ======================================== Function name: task_9_circle_opencv_circle ======================================== Function has the return content below: None ======================================== Summary of Function Timer: Count of loops: 100 Average time of loops: 6.074186999960318e-05 (sec) Minimum of every loop time: 5.815699999800472e-05 (sec) Maximum of every loop time: 0.00016856299999545854 (sec) Total time of loops: 0.006074186999960318 (sec) ======================================== ======================================== Function name: task_9_circle_opencv_ellipse ======================================== Function has the return content below: None ======================================== Summary of Function Timer: Count of loops: 100 Average time of loops: 6.716407000013192e-05 (sec) Minimum of every loop time: 6.593300000190538e-05 (sec) Maximum of every loop time: 0.00012471200000163662 (sec) Total time of loops: 0.0067164070000131915 (sec) ======================================== ======================================== Function name: task_9_ellipse_pillow ======================================== Function has the return content below: None ======================================== Summary of Function Timer: Count of loops: 100 Average time of loops: 0.0002104615099997176 (sec) Minimum of every loop time: 0.00020619399999333154 (sec) Maximum of every loop time: 0.00040772399999866593 (sec) Total time of loops: 0.021046150999971758 (sec) ======================================== ======================================== Function name: task_9_ellipse_opencv ======================================== Function has the return content below: None ======================================== Summary of Function Timer: Count of loops: 100 Average time of loops: 8.027900999998394e-05 (sec) Minimum of every loop time: 7.837199999727318e-05 (sec) Maximum of every loop time: 0.00020712799999955678 (sec) Total time of loops: 0.008027900999998394 (sec) ======================================== ======================================== Function name: task_9_text_pillow ======================================== Function has the return content below: None ======================================== Summary of Function Timer: Count of loops: 100 Average time of loops: 0.0007998544599997359 (sec) Minimum of every loop time: 0.0007778169999994589 (sec) Maximum of every loop time: 0.0016240550000006237 (sec) Total time of loops: 0.07998544599997359 (sec) ======================================== ======================================== Function name: task_9_text_opencv ======================================== Function has the return content below: None ======================================== Summary of Function Timer: Count of loops: 100 Average time of loops: 3.116865999970742e-05 (sec) Minimum of every loop time: 3.0166999998471056e-05 (sec) Maximum of every loop time: 9.610000000037644e-05 (sec) Total time of loops: 0.0031168659999707415 (sec) ======================================== ======================================== Function name: task_11_pillow ======================================== Function has the return content below: None ======================================== Summary of Function Timer: Count of loops: 100 Average time of loops: 0.033835311859999495 (sec) Minimum of every loop time: 0.03373037900000497 (sec) Maximum of every loop time: 0.034273077999998236 (sec) Total time of loops: 3.3835311859999493 (sec) ======================================== ======================================== Function name: task_11_opencv_imread ======================================== Function has the return content below: None ======================================== Summary of Function Timer: Count of loops: 100 Average time of loops: 0.028288081510000042 (sec) Minimum of every loop time: 0.028133581999995272 (sec) Maximum of every loop time: 0.02905974700000513 (sec) Total time of loops: 2.828808151000004 (sec) ======================================== ======================================== Function name: task_11_opencv_asarray ======================================== Function has the return content below: None ======================================== Summary of Function Timer: Count of loops: 100 Average time of loops: 0.02815422919999975 (sec) Minimum of every loop time: 0.0279864769999989 (sec) Maximum of every loop time: 0.029095201000004067 (sec) Total time of loops: 2.8154229199999747 (sec) ======================================== ======================================== Function name: task_11_opencv_array ======================================== Function has the return content below: None ======================================== Summary of Function Timer: Count of loops: 100 Average time of loops: 0.028195894160001414 (sec) Minimum of every loop time: 0.028047434000001203 (sec) Maximum of every loop time: 0.02866104100000655 (sec) Total time of loops: 2.8195894160001416 (sec) ========================================

(很奇怪为什么循环次数都是100次,感觉可能timer算法有问题)

时间单位:秒,精确度:3位有效数字,制作成表格(红字表示所在子操作名中平均时间最短的函数,如若平均时间最短按照时间排列顺序依次比较)(图片读取一栏的红字标错位置了,应该打在pillow的下面)

 

 

2.结论

1)前四项由于没有对比就不多说了,不过感觉opencv读取视频的速度确实有些慢(6.5MB/s,90.8frame/s)。当然写入数据也很慢(75.8frame/s),不过尺寸不同,就不互相比较了。

2)创建图片操作numpy数组要比pillow的对象要快一些(也就两个数量级吧~)

3)数据结构转换中numpy比list快几乎是显然的hhh,其中asarray要比array略快一点,大概是因为array深复制而asarray浅复制;当然asarray的结果是not writable的,估计是因为image对象存储的数组本身就是只读的吧。如果只是为了读取图片方便塞视频里就用asarray。

4)没想到图片点操作里面numpy的索引赋值竟然比putpixel还要慢一点!真是大开眼界。。。果然pillow源码里面说“自带api要快一点”是真的。。。

5)图片读取、图片绘图绝大多数情况下pillow秒杀numpy和opencv,只有在写文字的时候opencv体现出比较大的效率优势,但是opencv的字体有很多限制,还是弃置了。(我手头上有一套字模,还是可以测试一下numpy写字速度的,不过估计还是要慢一些,而且字模做起来也比较臃肿,就不试了~)

6)写图片还是opencv要快一点点,当然asarray和array在多精确几个数字就是asarray快了,如果只有三位那就是array更快一点。

 

六、优化

(待续)

 

七、总结反思

这个项目我大概从一个月前就有想法了,最近一周一直在抽时间做,净时间估计都有十几个小时了。最后一天(11月16日)晚上我拖到12点,作业还没做完,困得要死,也就做了个大概--没有优化的部分,也没有表格,还因为事先没查好api返工了好几次。这件事让我深感个人的力量的薄弱 ,以及我自己水平的低下。

不过这次的项目让我掌握了多方面搜索数据(尤其是api)的能力,诸如找官方文档啊,看源码啊之类的,晦涩难懂的源代码和英文文档我也尽可能啃掉了,也算是一大进步了吧。

然后就是项目的内容。本次的测试我尽可能从自己能想到的角度给出足够多的实现方法来对比运行效率,孰优孰劣一下子就清楚了。不过也要看情况,比如说给定的数据全是数组,你要是为了追求图像处理函数的效率而全部转成pil对象,也并不是好的。除了时间效率的差距,我们也可以看出PIL的图像处理能力果然还是上等,opencv只是视频库附带一个简陋的图像处理能力,真正到解决图像问题时候还是应该选择PIL。

当然,这次的实验也有不科学的地方,诸如没有控制好无关变量,甚至可能导致相反的结果。我不是专业搞cs得,而且我还是高二生,实在无力全身心投入其中。实验方法带来的误差以及内容的错漏,尚希见谅!

最后希望各位能在这篇充满艰辛的博客中得到点什么。哪怕是一点处理编程项目时的教训而不是博客内容本身,我也心满意足了。


相关教程
          
关于我们--广告服务--免责声明--本站帮助-友情链接--版权声明--联系我们       黑ICP备07002182号