CV2识别图片A,B,C,D
这个模型是经过简单训练,只能识别四个英文字母: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.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表示变 ...
- python 识别图片验证码报IOError
说一下困扰了我一周的问题:识别图片验证码 本来我按照安装步骤(http://www.cnblogs.com/yeayee/p/4955506.html?utm_source=tuicool&u ...
- Atitit java 二维码识别 图片识别
Atitit java 二维码识别 图片识别 1.1. 解码11.2. 首先,我们先说一下二维码一共有40个尺寸.官方叫版本Version.11.3. 二维码的样例:21.4. 定位图案21.5. 数 ...
- python识别图片文字
因为学校要求要刷一门叫<包装世界>的网课,而课程里有200多道选择题,而且只能在手机完成,网页版无法做题,而看视频是不可能看视频的,这辈子都不可能看...所以写了几行代码来进行百度搜答案. ...
- c#实现识别图片上的验证码数字
这篇文章主要介绍了c#实现识别图片上的验证码数字的方法,本文给大家汇总了2种方法,有需要的小伙伴可以参考下. ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1 ...
- Tesseract识别图片提取文字&字库训练
文中测试了3.0和4.0两个版本.发现3.0识别效率不准确,需要训练词库.4.0识别效率就比较高了,而且支持结果生成pdf.txt等格式.所以推荐使用4.0版本. 这个工具可以用在爬虫的时候获取验证码 ...
- 机器学习进阶-图像基本操作-图像数据读取 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 使得读入的图片为 ...
- Python图片识别找坐标(appium通过识别图片点击坐标)
***如果只想了解图片相似度识别,直接看第一步即可 ***如果想了解appium根据图片识别点击坐标,需要看第一.二.三步 背景|在做UI测试时,发现iOS自定义的UI控件,appium识别不到. ...
- PYTHON实现识别图片
自学Python3第5天,今天突发奇想,想用Python识别图片里的文字.没想到Python实现图片文字识别这么简单,只需要一行代码就能搞定 #作者微信:2501902696 from PIL imp ...
随机推荐
- IntelliJ IDEA添加JavaDOC注释 方法 快捷键
第一种方法 Settings ->Keymap ->Other ->Fix doc comment ->右键 ->选择 Add Keyboard Shortcut, 然后 ...
- [LeetCode] 203. Remove Linked List Elements 移除链表元素
Remove all elements from a linked list of integers that have value val. ExampleGiven: 1 --> 2 --& ...
- Java之变量和数据类型
变量 什么是变量 变量就是初中的代数的概念.例如一个简单的方程,x,y都是变量 y=x+1 在Java中,变量分为两种:基本类型的变量和引用类型的变量 在Java中,变量必须先定义后使用,在定义变量的 ...
- Redis哨兵(Sentinel)模式
Redis哨兵(Sentinel)模式 主从切换技术的方法是:当主服务器宕机后,需要手动把一台从服务器切换为主服务器,这就需要人工干预,费事费力,还会造成一段时间内服务不可用.这不是一种推荐的方式 ...
- oracle创建用户并指定表空间
/*第1步:创建ODPS数据表空间 */create tablespace ODPS logging datafile '/home/oracle/tablespace_dir/ODPS.dbf' s ...
- #安装memcache
安装memcache sudo apt-get install memcached sudo apt search php-memcache sudo apt-get install php-memc ...
- 阿里P8架构师谈:阿里双11秒杀系统如何设计?
秒杀是电商业务里的标志性事件,这样的典型高并发场景会遇见什么样的挑战呢,然后又是如何来解决的呢? 秒杀活动场景 淘宝双11秒杀场景,大量的用户短时间内涌入,瞬间流量巨大(高并发),比如:1000万人同 ...
- Java开发笔记(一百二十六)Swing的窗口
前面介绍了AWT界面编程的若干技术,在编码实践的时候,会发现AWT用起来甚是别扭,它的毛病包括但不限于下列几点:1.对中文的支持不好,要想在界面上正常显示汉字,还得在运行时指定额外的运行参数“-Dfi ...
- TiDB基本架构简单总结
TiDB特点 高可用 水平拓展 事务 SQL支持 TiDB架构 和MySql不同,TiDB是一个分布式的数据库而不是单个进程,所以整个TiDB是由以下角色组成: TiKV, PD, TiDB, T ...
- 【LEETCODE】39、第561题 Array Partition I
package y2019.Algorithm.array; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.array * ...