1 Star 0 Fork 0

念古/opencv

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
答题卡分项提取.py 2.13 KB
一键复制 编辑 原始数据 按行查看 历史
念古 提交于 2019-12-30 17:05 . Add files via upload
import cv2
import imutils
import numpy as np
img1 = cv2.imread('/home/niangu/桌面/答题卡识别/test2/D.jpg')
img = cv2.imread('/home/niangu/桌面/答题卡识别/答案提取.png')
clahe = cv2.createCLAHE(clipLimit=1.0, tileGridSize=(8, 8))
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(gray, (5, 5), 0)
dilate = cv2.dilate(blurred, cv2.getStructuringElement(cv2.MORPH_RECT, (3, 3)))
edged = cv2.Canny(dilate, 30, 120, 3) # 边缘检测
cv2.line(edged, (0, 7), (400, 7), (255, 0, 0), 1)
for i in range(0, 5):
j = i*100
cv2.line(edged, (j, 0), (j, 700), (255, 0, 0), 2)
for i in range(0, 5):
if i == 0:
g = 20
if i > 0:
g = 20 + i*16
cv2.line(edged, (g, 0), (g, 700), (255, 0, 0), 1)
for i in range(0, 5):
if i == 0:
g = 122
if i > 0:
g = 125 + i*16
cv2.line(edged, (g, 0), (g, 700), (255, 0, 0), 1)
for i in range(0, 5):
if i == 0:
g = 225
if i > 0:
g = 230 + i*16
cv2.line(edged, (g, 0), (g, 700), (255, 0, 0), 1)
for i in range(0, 5):
if i == 0:
g = 328
if i > 0:
g = 332 + i*16
cv2.line(edged, (g, 0), (g, 700), (255, 0, 0), 1)
for i in range(0, 8):
j = i*100
#cv2.line(img, (0, j), (400, j), (255, 0, 0), 2)
d = j + 25 + i
cv2.line(edged, (0, d), (400, d), (255, 0, 0), 1)
if i < 3:
f = d + 20
cv2.line(edged, (0, f), (400, f), (255, 0, 0), 1)
if i >= 3:
f = d + 18
cv2.line(edged, (0, f), (400, f), (255, 0, 0), 1)
c = f + 15
cv2.line(edged, (0, c), (400, c), (255, 0, 0), 1)
z = c + 16
cv2.line(edged, (0, z), (400, z), (255, 0, 0), 1)
e = z + 15 + 3
cv2.line(edged, (0, e), (400, e), (255, 0, 0), 1)
#cv2.line(img, (0, x), (400, x), (255, 0, 0), 1)
u = z + 29
cv2.line(edged, (0, u), (400, u), (255, 0, 0), 1)
"""
for i in range(0, 4):
f = 125 + (i*15)
cv2.line(img, (0, f), (400, f), (255, 0, 0), 1)
"""
cv2.imwrite('答题卡提取答案.png', edged)
cv2.namedWindow('img2', cv2.WINDOW_NORMAL)
cv2.imshow('img2', edged)
cv2.namedWindow('img21', cv2.WINDOW_NORMAL)
cv2.imshow('img21', img)
cv2.waitKey(0)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/niangu/opencv.git
[email protected]:niangu/opencv.git
niangu
opencv
opencv
master

搜索帮助