最近一直在玩数独,突发奇想实现图像识别求解数独,输入到输出平均需要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 识别条形码的资料请关注其它相关文章!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线
暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。
艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。
《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。
更新日志
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]