黑松山资源网 Design By www.paidiu.com
最近一直在玩数独,突发奇想实现图像识别求解数独,输入到输出平均需要0.5s。
整体思路大概就是识别出图中数字生成list,然后求解。
输入输出demo
数独采用的是微软自带的Microsoft sudoku软件随便截取的图像,如下图所示:
经过程序求解后,得到的结果如下图所示:
def getFollow(varset, terminalset, first_dic, production_list): follow_dic = {} done = {} for var in varset: follow_dic[var] = set() done[var] = 0 follow_dic["A1"].add("#") # for var in terminalset: # follow_dic[var]=set() # done[var] = 0 for var in follow_dic: getFollowForVar(var, varset, terminalset, first_dic, production_list, follow_dic, done) return follow_dic def getFollowForVar(var, varset, terminalset, first_dic, production_list, follow_dic, done): if done[var] == 1: return for production in production_list: if var in production.right: ##index这里在某些极端情况下有bug,比如多次出现var,index只会返回最左侧的 if production.right.index(var) != len(production.right) - 1: follow_dic[var] = first_dic[production.right[production.right.index(var) + 1]] | follow_dic[var] # 没有考虑右边有非终结符但是为null的情况 if production.right[len(production.right) - 1] == var: if var != production.left[0]: # print(var, "吸纳", production.left[0]) getFollowForVar(production.left[0], varset, terminalset, first_dic, production_list, follow_dic, done) follow_dic[var] = follow_dic[var] | follow_dic[production.left[0]] done[var] = 1
程序具体流程
程序整体流程如下图所示:
读入图像后,根据求解轮廓信息找到数字所在位置,以及不包含数字的空白位置,提取数字信息通过KNN识别,识别出数字;无数字信息的在list中置0;生成未求解数独list,之后求解数独,将信息在原图中显示出来。
def initProduction(): production_list = [] production = Production(["A1"], ["A"], 0) production_list.append(production) production = Production(["A"], ["E", "I", "(", ")", "{", "D", "}"], 1) production_list.append(production) production = Production(["E"], ["int"], 2) production_list.append(production) production = Production(["E"], ["float"], 3) production_list.append(production) production = Production(["D"], ["D", ";", "B"], 4) production_list.append(production) production = Production(["B"], ["F"], 5) production_list.append(production) production = Production(["B"], ["G"], 6) production_list.append(production) production = Production(["B"], ["M"], 7) production_list.append(production) production = Production(["F"], ["E", "I"], 8) production_list.append(production) production = Production(["G"], ["I", "=", "P"], 9) production_list.append(production) production = Production(["P"], ["K"], 10) production_list.append(production) production = Production(["P"], ["K", "+", "P"], 11) production_list.append(production) production = Production(["P"], ["K", "-", "P"], 12) production_list.append(production) production = Production(["I"], ["id"], 13) production_list.append(production) production = Production(["K"], ["I"], 14) production_list.append(production) production = Production(["K"], ["number"], 15) production_list.append(production) production = Production(["K"], ["floating"], 16) production_list.append(production) production = Production(["M"], ["while", "(", "T", ")", "{", "D", ";", "}"], 18) production_list.append(production) production = Production(["N"], ["if", "(", "T", ")", "{", "D",";", "}", "else", "{", "D", ";","}"], 19) production_list.append(production) production = Production(["T"], ["K", "L", "K"], 20) production_list.append(production) production = Production(["L"], [">"], 21) production_list.append(production) production = Production(["L"], ["<"], 22) production_list.append(production) production = Production(["L"], [">="], 23) production_list.append(production) production = Production(["L"], ["<="], 24) production_list.append(production) production = Production(["L"], ["=="], 25) production_list.append(production) production = Production(["D"], ["B"], 26) production_list.append(production) production = Production(["B"], ["N"], 27) production_list.append(production) return production_list source = [[5, "int", " 关键字"], [1, "lexicalanalysis", " 标识符"], [13, "(", " 左括号"], [14, ")", " 右括号"], [20, "{", " 左大括号"], [4, "float", " 关键字"], [1, "a", " 标识符"], [15, ";", " 分号"], [5, "int", " 关键字"], [1, "b", " 标识符"], [15, ";", " 分号"], [1, "a", " 标识符"], [12, "=", " 赋值号"], [3, "1.1", " 浮点数"], [15, ";", " 分号"], [1, "b", " 标识符"], [12, "=", " 赋值号"], [2, "2", " 整数"], [15, ";", " 分号"], [8, "while", " 关键字"], [13, "(", " 左括号"], [1, "b", " 标识符"], [17, "<", " 小于号"], [2, "100", " 整数"], [14, ")", " 右括号"], [20, "{", " 左大括号"], [1, "b", " 标识符"], [12, "=", " 赋值号"], [1, "b", " 标识符"], [9, "+", " 加 号"], [2, "1", " 整数"], [15, ";", " 分号"], [1, "a", " 标识符"], [12, "=", " 赋值号"], [1, "a", " 标识符"], [9, "+", " 加号"], [2, "3", " 整数"], [15, ";", " 分号"], [21, "}", " 右大括号"], [15, ";", " 分号"], [6, "if", " 关键字"], [13, "(", " 左括号"], [1, "a", " 标识符"], [16, ">", " 大于号"], [2, "5", " 整数"], [14, ")", " 右括号"], [20, "{", " 左大括号"], [1, "b", " 标识符"], [12, "=", " 赋值号"], [1, "b", " 标识符"], [10, "-", " 减号"], [2, "1", " 整数"], [15, ";", " 分号"], [21, "}", " 右大括号"], [7, "else", " 关键字"], [20, "{", " 左大括号"], [1, "b", " 标识符"], [12, "=", " 赋值号"], [1, "b", " 标识符"], [9, "+", " 加号"], [2, "1", " 整数"], [15, ";", " 分号"], [21, "}", " 右大括号"], [21, "}", " 右大括号"]]
以上就是Python识别处理照片中的条形码的详细内容,更多关于python 识别条形码的资料请关注其它相关文章!
黑松山资源网 Design By www.paidiu.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
黑松山资源网 Design By www.paidiu.com
暂无评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新日志
2024年10月05日
2024年10月05日
- 群星《前途海量 电影原声专辑》[FLAC/分轨][227.78MB]
- 张信哲.1992-知道新曲与精丫巨石】【WAV+CUE】
- 王翠玲.1995-ANGEL【新艺宝】【WAV+CUE】
- 景冈山.1996-我的眼里只有你【大地唱片】【WAV+CUE】
- 群星《八戒 电影原声带》[320K/MP3][188.97MB]
- 群星《我的阿勒泰 影视原声带》[320K/MP3][139.47MB]
- 纪钧瀚《胎教古典音乐 钢琴与大提琴的沉浸时光》[320K/MP3][148.91MB]
- 刘雅丽.2001-丽花皇后·EMI精选王【EMI百代】【FLAC分轨】
- 齐秦.1994-黄金十年1981-1990CHINA.TOUR.LIVE精丫上华】【WAV+CUE】
- 群星.2008-本色·百代音乐人创作专辑【EMI百代】【WAV+CUE】
- 群星.2001-同步过冬AVCD【环球】【WAV+CUE】
- 群星.2020-同步过冬2020冀待晴空【环球】【WAV+CUE】
- 沈雁.1986-四季(2012梦田复刻版)【白云唱片】【WAV+CUE】
- 纪钧瀚《胎教古典音乐 钢琴与大提琴的沉浸时光》[FLAC/分轨][257.88MB]
- 《国语老歌 怀旧篇 3CD》[WAV/分轨][1.6GB]