import cv2
from matplotlib import pyplot as plt
im = cv2.imread(r"F:\vc0.png")
im_gray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
im_at_mean = cv2.adaptiveThreshold(im_gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 5, 7)
im_at_mean2 = cv2.adaptiveThreshold(im_gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 5, 10)
retval,im_at_fixed = cv2.threshold(im_gray, 50, 255, cv2.THRESH_BINARY)
plt.subplot(2, 2, 1),plt.imshow(im_gray,'gray')
plt.subplot(2, 2, 2),plt.imshow(im_at_mean,'gray')
plt.subplot(2, 2, 3),plt.imshow(im_at_mean2,'gray')
plt.subplot(2, 2, 4),plt.imshow(im_at_fixed,'gray')
plt.show()
参考:
http://blog.csdn.net/what_lei/article/details/49159655
http://blog.csdn.net/deerlux/article/details/48477219
http://www.voidcn.com/article/p-ynhesxkf-cm.html
http://blog.csdn.net/dulingtingzi/article/details/51242483# OpenCV之Python学习笔记
http://blog.csdn.net/xinxing__8185/article/details/48440133#使用opencv按一定间隔截取视频帧
http://blog.csdn.net/qq_14845119/article/details/52354394#windows下的python+ opencv安装攻略
https://zhuanlan.zhihu.com/p/24425116
安装:
http://www.cnblogs.com/lclblack/p/6377710.html
裁剪图片:
# cut img
img = cv2.imread(r"./{}/{}.jpeg".format(l,l))
img_shape = img.shape
w = (img_shape[1] - 750) // 2
h = (img_shape[0] - 422) // 2
crop_img = img[h:422 + h, w:750 + w]
cv2.imwrite(r"./{}/{}_422.jpeg".format(l, l), crop_img)
w = (img_shape[1] - 500) // 2
h = (img_shape[0] - 600) // 2
crop_img = img[h:600 + h, w:500 + w]
cv2.imwrite(r"./{}/{}_500.jpeg".format(l, l), crop_img)
参考:
https://gxnotes.com/article/109552.html#Python在OpenCV中裁剪图像