这个模型是经过简单训练,只能识别四个英文字母:ABCD,是我为了提取答案才训练的,因为科大,百度,以及腾讯的识别不是很准,所以自己训练自己使用,希望能够给你带来方便。下面是训练好的model,如多你感觉图片的类型相似,可直接使用。

1、图片形式,尽量png

2、模型

如果需要可以加我qq:1851999452

3、

 import os
import numpy as np
import cv2
import matplotlib.pyplot as plt
import tensorflow as tf
import keras
from keras.models import Model,load_model
from keras.layers import Conv2D,Dense,Activation,Input,MaxPooling2D,Flatten
from sklearn.model_selection import train_test_split
# file_dir = '/home/youxue/BorD'
# B = []
# A =[]
# C =[]
# label_A=[]
# label_C=[]
# label_B = []
# D = []
# label_D = []
# for file in os.listdir(file_dir):
# if file == 'A':
# for img in os.listdir(os.path.join(file_dir, file)):
# A.append(file_dir + '/' + file + '/' + img)
# label_A.append(0)
# elif file == 'B':
# for img in os.listdir(os.path.join(file_dir, file)):
# B.append(file_dir + '/' + file + '/' + img)
# label_B.append(1)
# elif file == 'C':
# for img in os.listdir(os.path.join(file_dir, file)):
# C.append(file_dir + '/' + file + '/' + img)
# label_C.append(2)
# else:
# for img in os.listdir(os.path.join(file_dir, file)):
# D.append(file_dir + '/' + file + '/' + img)
# label_D.append(3)
#
# print('There are %d B\n There are %d D' % (len(B), len(D)))
#
# image_list = np.hstack((A,B,C,D))
# label_list = np.hstack((label_A,label_B,label_C, label_D))
# temp = np.array([image_list, label_list])
# temp = temp.transpose()
#
#
# np.random.shuffle(temp)
# png_list=[]
# image_list = list(temp[:, 0])
# label_list = list(temp[:, 1])
# label_list = [int(i) for i in label_list]
# for png in image_list:
# png_list.append(cv2.imread(png))
# print(png_list[100].shape)
# png = np.array(png_list)
# label = np.array(label_list)
# x_train,x_test,y_train,y_test=train_test_split(png,label,test_size=0.1)
#
# # plt.imshow(x_train[11])
# # plt.show()
#
# x_train = x_train/255.
# x_test = x_test/255.
#
# y_train = np.eye(4)[y_train.reshape(-1)]
# y_test = np.eye(4)[y_test.reshape(-1)]
# print(x_train.shape,y_train.shape) # input_shape= (24,810,3)
# input_data = Input(input_shape)
# layer1 = Conv2D(32,(3,3),padding='same',activation='relu')(input_data)
# layer2 = MaxPooling2D(pool_size=(2,2))(layer1)
# layer3 = Conv2D(32,(3,3),padding='same',activation='relu')(layer2)
# layer4 = MaxPooling2D(pool_size=(2,2))(layer3)
# layer5 = Conv2D(32,(3,3),padding='same',activation='relu')(layer4)
# layer6 = Flatten()(layer5)
# layer7 = Dense(4)(layer6)
# pred= Activation('softmax')(layer7)
# model= Model(input=input_data,output=pred)
# model.summary()
# model.compile(optimizer='adam',loss='categorical_crossentropy',metrics=['accuracy'])
# model.fit(x_train,y_train,batch_size=32,epochs=20,validation_data=(x_test,y_test))
# model.save('ABCD.model')
model=load_model('ABCD.model')
#这里填写自己的存放路径
with open('id.txt','a+') as f:
#这里填写你需要识别图片的路径
path=''
for png in os.listdir(path):
pn= cv2.imread(os.path.join(path,png))
ids_1 = png.split('answer')[0]
print(type(ids_1))
#png2= cv2.imread('/home/youxue/4907988answer.png')
# plt.imshow(pn)
# plt.show()
img=[]
img.append(pn)
#img.append(png2)
img=np.array(img)
img = img/255. # print(img.shape)
pre=model.predict(img)
for c in pre:
temp= max(c[0],c[1],c[2],c[3])
if temp == c[0]:
ABCD = 'A'
elif temp == c[1]:
ABCD = 'B'
elif temp == c[2]:
ABCD = 'C'
else:
ABCD = 'D' f.write(ids_1 + '--' + ABCD + '\n')

CV2识别图片A,B,C,D的更多相关文章

  1. 深度学习原理与框架-猫狗图像识别-卷积神经网络(代码) 1.cv2.resize(图片压缩) 2..get_shape()[1:4].num_elements(获得最后三维度之和) 3.saver.save(训练参数的保存) 4.tf.train.import_meta_graph(加载模型结构) 5.saver.restore(训练参数载入)

    1.cv2.resize(image, (image_size, image_size), 0, 0, cv2.INTER_LINEAR) 参数说明:image表示输入图片,image_size表示变 ...

  2. python 识别图片验证码报IOError

    说一下困扰了我一周的问题:识别图片验证码 本来我按照安装步骤(http://www.cnblogs.com/yeayee/p/4955506.html?utm_source=tuicool&u ...

  3. Atitit java 二维码识别 图片识别

    Atitit java 二维码识别 图片识别 1.1. 解码11.2. 首先,我们先说一下二维码一共有40个尺寸.官方叫版本Version.11.3. 二维码的样例:21.4. 定位图案21.5. 数 ...

  4. python识别图片文字

    因为学校要求要刷一门叫<包装世界>的网课,而课程里有200多道选择题,而且只能在手机完成,网页版无法做题,而看视频是不可能看视频的,这辈子都不可能看...所以写了几行代码来进行百度搜答案. ...

  5. c#实现识别图片上的验证码数字

    这篇文章主要介绍了c#实现识别图片上的验证码数字的方法,本文给大家汇总了2种方法,有需要的小伙伴可以参考下. ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1 ...

  6. Tesseract识别图片提取文字&字库训练

    文中测试了3.0和4.0两个版本.发现3.0识别效率不准确,需要训练词库.4.0识别效率就比较高了,而且支持结果生成pdf.txt等格式.所以推荐使用4.0版本. 这个工具可以用在爬虫的时候获取验证码 ...

  7. 机器学习进阶-图像基本操作-图像数据读取 1.cv2.imread(图片读入) 2.cv2.imshow(图片展示) 3.cv2.waitKey(图片停留的时间) 4.cv2.destroyAllWindows(清除所有的方框界面) 5.cv2.imwrite(对图片进行保存)

    1. cv2.imread('cat.jpg', cv2.IMGREAD_GRAYSCALE)  # 使用imread读入图像(BGR顺序), 使用IMGREAD_GRAYSCALE 使得读入的图片为 ...

  8. Python图片识别找坐标(appium通过识别图片点击坐标)

    ***如果只想了解图片相似度识别,直接看第一步即可 ***如果想了解appium根据图片识别点击坐标,需要看第一.二.三步   背景|在做UI测试时,发现iOS自定义的UI控件,appium识别不到. ...

  9. PYTHON实现识别图片

    自学Python3第5天,今天突发奇想,想用Python识别图片里的文字.没想到Python实现图片文字识别这么简单,只需要一行代码就能搞定 #作者微信:2501902696 from PIL imp ...

随机推荐

  1. MD5(2)

    /************************************************ MD5 算法的Java Bean @author:Topcat Tuppin Last Modifi ...

  2. Coder 健康 知识

  3. [LeetCode] 258. Add Digits 加数字

    Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. ...

  4. [LeetCode] 675. Cut Off Trees for Golf Event 为高尔夫赛事砍树

    You are asked to cut off trees in a forest for a golf event. The forest is represented as a non-nega ...

  5. idea关闭sonarLint自动扫描

    手动运行SonarLint 停止SonarLint自动检测代码之后,可以使用Ctrl+Shift+S手动运行SonarLint检查代码

  6. TCP/IP学习笔记12-- IP协议基础

    IP(internet protocol, 网际协议) IP相当于OSI参考模型中的第三层 -- 网络层. --网络层的下一层--数据链路层的主要作用是在 同一种数据链路 的节点之间进行包传递,而一旦 ...

  7. LeetCode 23. 合并K个排序链表(Merge Two Sorted Lists)

    23. 合并K个排序链表 23. Merge k Sorted Lists 题目描述 合并 k 个排序链表,返回合并后的排序链表.请分析和描述算法的复杂度. LeetCode23. Merge k S ...

  8. [转帖]Chrome用户请尽快更新:谷歌发现两个严重的零日漏洞

    Chrome用户请尽快更新:谷歌发现两个严重的零日漏洞 https://news.cnblogs.com/n/647075/ 强烈建议:Chrome 用户请尽快升级浏览器!在谷歌今天发布的紧急补丁程序 ...

  9. 【转帖】国产PCIe SSD主控芯片获得中国芯大奖 3500MB/s读取

    国产PCIe SSD主控芯片获得中国芯大奖 3500MB/s读取 https://www.cnbeta.com/articles/tech/906033.htm 国产主控 在日前的2019“中国芯”集 ...

  10. Kafka Streams | 流,实时处理和功能

    1.目标 在我们之前的Kafka教程中,我们讨论了Kafka中的ZooKeeper.今天,在这个Kafka Streams教程中,我们将学习Kafka中Streams的实际含义.此外,我们将看到Kaf ...