【Python | opencv+PIL】常见操作(创建、添加帧、绘图、读取等)的效率对比及其优化

一、背景

本人准备用python做图像和视频编辑的操作,却发现opencv和PIL的效率并不是很理想,并且同样的需求有多种不同的写法并有着不同的效率。见全网并无较完整的效率对比文档,遂决定自己丰衣足食。

二、目的

本篇文章将对Python下的opencv接口函数及PIL(Pillow)函数的常用部分进行逐个运行并计时(多次测算取平均时间和最短时间,次数一般在100次以上),并简单使用numba、ctypes、cython等方法优化代码。

三、测试方法及环境

1.硬件

CPU:Intel(R) Core(TM) i3-3220 CPU @ 3.30GHz 3.30 GHz

内存:4.00 GB

硬盘:ATA WDC WD5000AAKX-7 SCSI Disk Device

2.软件:

操作系统:Windows 7 Service Pack 1 Ultimate 64bit zh-cn

Python解释器:3.7.5 64bit (provided by Anaconda)

各模块:皆为最新

(事情有所变化,暂时使用下面机房电脑的配置进行测试)

1.硬件

CPU:Intel(R) Xeon(R) Silver 4116 CPU @ 2.10GHz 2.10 GHz

内存:3.00 GB

硬盘:VMware Virtual disk SCSI Disk Service

2.软件:

操作系统:Windows 7 Service Pack 1 Ultimate 64bit zh-cn (powered by VMware Horizon View Client)

Python解释器:3.7.3 64bit (provided by Anaconda)

各模块:皆为最新

四、具体实现

1.待测试函数

以下定义新建的视频规定为MP4格式、mp4v编码、1920*1080尺寸、60帧速率;定义新建的图片为JPG格式、1920*1080尺寸、RGB通道。

根据实际需要(其实是我自己的需要),先暂定测试以下函数[1][2]:

1)创建视频

vw = cv2.VideoWriter('out.mp4', cv2.VideoWriter_fourcc(*'mp4v'), 60, (1920, 1080)) # Return MP4 video object

2)视频帧读取(视频不好做测试数据,故使用了手头上现成的。in.mp4参数:时长27秒,尺寸1920x1080,数据速率17073kbps,总比特率17331kbps,帧速率29fps,大小55.7MB)

cap = cv2.VideoCapture('in.mp4')

while cap.isOpened():

    ret, frame = cap.read() # frame return a numpy.ndarray object (WRITEABLE) with RGB of pixels

    if not ret: # Return True when read operation is successful

        break # Read operation fails and break

cap.release()

3)视频帧写入[3] (PS:为什么Opencv官方教程中没有这个函数...)

vw.write(frame)

4)写入视频(后来发现这个应该类似于file.close(),只是一个释放文件对象的过程,并不是真的在这个时候写入所有的数据。之前看见在release之前文件是空的应该是数据还没有从内存写入磁盘导致的)

vw.release()

5)创建图片 ( matrix & pillow object )

# Matrix

arr = np.zeros((1080, 1920, 3), dtype=np.uint8) # numpy中xy貌似是颠倒的,于是长1920宽1080的图像输出的shape应该是1080x1920,第三维度3表示图片通道为RGB

# Return a numpy.ndarray object (WRITEABLE)

# Pillow

img = Image.new('RGB', (1920, 1080)) # 这里的xy没有颠倒

6)图片读取(opencv & pillow)(使用新建的图片,满足上面的定义,大小33kb)

# OpenCV

arr = cv2.imread('in.jpg') # Notice that OpenCV don't support ALPHA channel

# Pillow

img = Image.open('in.jpg') # Return a PIL.Image.Image object

7)图片数据结构转换

arr1 = list(img.im) # Return a list

arr2 = np.asarray(img) # Return a np.ndarray object (NOT WRITEABLE) (Shallow copy)

arr3 = np.array(img) # Return a np.ndarray object (WRITEABLE) (Deep copy)

8)图片点操作(matrix & pillow object )

# Matrix

arr3[0][0] = (255, 255, 255)

# Pillow

img.putpixel((0, 0), (255, 255, 255)) # Putpixel

draw = ImageDraw.Draw(img) # ImageDraw.Point

draw.point((0, 0), (255, 255, 255))

# PS: OpenCV don't has a function that draw a pixel directly so we don't show the code here

9)图片其他绘图操作(matrix & pillow object & opencv )

这里我们测试画直线、画矩形、画圆(不包括matrix)、画椭圆操作(不包括matrix)、绘制文字(不包括matrix)。

注:pillow中默认绘制的图形都是实心的[4],而opencv要设置线宽为负值才是实心的[5]。

### Line

# Matrix

for x in range(100, 500):

    arr3[100][x] = (255, 255, 255) # 注意到numpy的颠倒

# Pillow

draw.line((100, 100, 500, 100), (255, 255, 255))

# OpenCV

cv2.line(arr, (100, 100), (500, 100), (255, 255, 255), 1) # 最后的1表示线宽

### Rectangle

# Matrix

for x in range(100, 500):

    for y in range(100, 500):

        arr3[y][x] = (255, 255, 255)

# Pillow

draw.rectangle((100, 100, 500, 500), (255, 255, 255))

# OpenCV

cv2.rectangle(arr, (100, 100), (500, 500), (255, 255, 255), -1)

### Circle

# Pillow

draw.arc((100, 100, 500, 500), 0, 360, (255, 255, 255)) # PIL.ImageDraw.Draw.arc

# arc方法前一个四元元组表示圆弧的左上点右下点,这里表示半径200、中心(300, 300);后面两个整数表示度数(0-360表示整个圆)

draw.ellipse((100, 100, 500, 500), (255, 255, 255)) # PIL.ImageDraw.Draw.ellipse

# ellipse方法同样表示两点

# OpenCV

cv2.circle(arr, (300, 300), 200, (255, 255, 255), -1) # cv2.circle

# 与Pillow不同的是,这里读取的是中心点和半径,更符合正常的习惯;1表示线宽,如果是-1则是实心圆

cv2.ellipse(arr, (300, 300), (200, 200), 0, 0, 360, (255, 255, 255), -1) # cv2.ellipse

# 这里第一个二元组是椭圆中心,第二个二元组分别表示半长轴长和半短轴长(注:中文文档漏掉了“半”字),后面三个参数分别表示椭圆本身逆时针旋转角(相当于坐标轴旋转)、起始角度和终止角度(0-360表示整个圆)

### Ellipse

# Pillow

draw.ellipse((100, 100, 700, 500), (255, 255, 255)) # 表示椭圆中心(400, 300),半长轴300,半短轴200

# OpenCV

cv2.ellipse(arr, (400, 300), (300, 200), 0, 0, 360, (255, 255, 255), -1)

### Text

# Pillow

font = ImageFont.truetype('simkai.ttf', 32) # 楷体,字号32

draw.text((100, 100), 'Hello, world!', (255, 255, 255), font) # 这里的坐标是左上角

# OpenCV

font = cv2.FONT_HERSHEY_SIMPLEX

cv2.putText(arr, 'Hello, world!', (100, 200), font, 2, (255, 255, 255), 1, cv2.LINE_AA) # 这里的坐标是左下角,1表示线宽(cv2不支持中文输出,故不测试中文)

其中opencv的字体参数参考:[6]

10)图片其他操作

11)写入图片( Pillow & OpenCV)

# Pillow

img.save('out.jpg')

# OpenCV

cv2.imwrite('out.jpg', arr) # Read from cv2.imread

cv2.imwrite('out.jpg', arr2) # np.asarray

cv2.imwrite('out.jpg', arr3) # np.array

2.时间计算工具

这里的时间计算工具用一个类实现给定次数的循环智能循环(自动控制循环次数)的功能,并能给出每次循环的函数返回值、循环次数、平均时间、最短时间、最长时间、总共用时。

对于自动判断循环次数的算法参考了Python的timeit模块源码(autorange函数)[7]:

(简书富文本貌似没有代码功能,我代码扔ubuntu pastebin上)

https://paste.ubuntu.com/p/GmVym6WNzw/

测试结果(将整个文件作为模块以op为名字调用):

In [168]: op.timer.better_print(op.timer.gettime(op.testfunc, 10000))

========================================

Function name:

testfunc

========================================

Function has the return content below:

9999

========================================

Summary of Function Timer:

Count of loops: 100

Average time of loops: 0.00039519199983260476 (sec)

Minimum of every loop time: 0.0002532999988034135 (sec)

Maximum of every loop time: 0.0010392999993200647 (sec)

Total time of loops: 0.03951919998326048 (sec)

========================================

In [169]: op.timer.better_print(op.timer.gettime(op.testfunc, 100000))

========================================

Function name:

testfunc

========================================

Function has the return content below:

99999

========================================

Summary of Function Timer:

Count of loops: 100

Average time of loops: 0.0029596240000137187 (sec)

Minimum of every loop time: 0.002567899999121437 (sec)

Maximum of every loop time: 0.006201700000019628 (sec)

Total time of loops: 0.29596240000137186 (sec)

========================================

In [170]: op.timer.better_print(op.timer.gettime(op.testfunc, 10))

========================================

Function name:

testfunc

========================================

Function has the return content below:

9

========================================

Summary of Function Timer:

Count of loops: 100

Average time of loops: 9.039999349624849e-07 (sec)

Minimum of every loop time: 7.999988156370819e-07 (sec)

Maximum of every loop time: 2.6999987312592566e-06 (sec)

Total time of loops: 9.03999934962485e-05 (sec)

========================================


3.完整代码

https://paste.ubuntu.com/p/5VdRWPDnZ8/

在此我先停一下,各位可以猜猜哪种方式更胜一筹。

flag

flag

flag

flag

flag

flag

flag

flag

flag

flag

flag

flag

flag

五、结果

1.现象

其中task_2(读取视频文件)占用时间过多,我们不予循环测试,下面的结果栏中将给出单次运行的结果(取第一次)。

In [10]: import time

In [11]: s = time.perf_counter(); op.task_2(); f = time.perf_counter(); f - s

Out[11]: 8.617467135000027

In [12]: s = time.perf_counter(); op.task_2(); f = time.perf_counter(); f - s

Out[12]: 8.663589091999995

cmder.exe中运行结果:

E:\test1

$ python3 opencv_pil_time.py

========================================

Function name:

task_1

========================================

Function has the return content below:

None

========================================

Summary of Function Timer:

Count of loops: 100

Average time of loops: 0.0016054189199999984 (sec)

Minimum of every loop time: 0.0013979550000000063 (sec)

Maximum of every loop time: 0.0057973939999999835 (sec)

Total time of loops: 0.16054189199999985 (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得,而且我还是高二生,实在无力全身心投入其中。实验方法带来的误差以及内容的错漏,尚希见谅!

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

参考资料:

[1]Pillow (PIL Fork) 7.0.0.dev0 英文文档

[2]OpenCV Python Tutorials 翻译OpenCV-Python Tutorials

[3]Python&OpenCV - 读写(read&write)视频(video) 详解 及 代码

[4]Python图像处理库PIL的ImageDraw模块介绍

[5]python opencv cv2.rectangle 参数含义

[6] python中cv2.putText参数详解

[7]Python 3.7 timeit

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 212,294评论 6 493
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,493评论 3 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 157,790评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,595评论 1 284
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,718评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,906评论 1 290
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,053评论 3 410
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,797评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,250评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,570评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,711评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,388评论 4 332
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,018评论 3 316
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,796评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,023评论 1 266
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,461评论 2 360
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,595评论 2 350

推荐阅读更多精彩内容