python 3.6 使用 opencv 3.4 做图像二值化和显示

首先下载 opencv 3.4 的python 包:

opencv_python-3.4.1-cp36-cp36m-win_amd64.whl , 从这里: https://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv

然后在控制台里安装这个包:

python -mpip install opencv_python-3.4.1-cp36-cp36m-win_amd64.whl

测试一下是否可行:

import cv2
import matplotlib.pyplot as plt

img = cv2.imread('fig/sinx.png',0)
r ,  thr = cv2.threshold( img , 200 , 255 , cv2.THRESH_BINARY ) 

plt.imshow( thr , 'gray')

plt.show()


#cv2.imshow("1" , thr ) 
#cv2.waitKey(0)
#cv2.destroyAllWindows()

sinx.png 如下:

fig/sinx.png