代码拉取完成,页面将自动刷新
import cv2
import numpy as np
from matplotlib import pyplot as plt
#选择th2实心,th3空心
img = cv2.imread('/home/niangu/桌面/答题卡识别/4.jpeg',0)
img = cv2.medianBlur(img, 5)
ret, th1 = cv2.threshold(img, 127, 255, cv2.THRESH_BINARY)
th2 = cv2.adaptiveThreshold(img, 255, cv2.ADAPTIVE_THRESH_MEAN_C,cv2.THRESH_BINARY,11,2)
th3 = cv2.adaptiveThreshold(img, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY,11,2)
titles = ['Original Image', 'Global Thresholding (v = 127)',
'Adaptive Mean Thresholding', 'Adaptive Gaussian Thresholding']
images = [img, th1, th2, th3]
"""
for i in range(4):
plt.subplot(2,2,i+1)
plt.imshow(images[i],'gray')
plt.title(titles[i])
plt.xticks([])
plt.yticks([])
plt.show()
"""
cv2.namedWindow('img', cv2.WINDOW_NORMAL)
cv2.imshow('img', img)
cv2.namedWindow('th1', cv2.WINDOW_NORMAL)
cv2.imshow('th1', th1)
cv2.namedWindow('th2', cv2.WINDOW_NORMAL)
cv2.imshow('th2', th2)
cv2.namedWindow('th3', cv2.WINDOW_NORMAL)
cv2.imshow('th3', th3)
cv2.waitKey(0)&0xFF
cv2.destroyAllWindows()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。