91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

利用Python如何實現識別照片中的條形碼

發布時間:2020-11-17 14:45:38 來源:億速云 閱讀:602 作者:Leah 欄目:開發技術

這篇文章將為大家詳細講解有關利用Python如何實現識別照片中的條形碼,文章內容質量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關知識有一定的了解。

最近一直在玩數獨,突發奇想實現圖像識別求解數獨,輸入到輸出平均需要0.5s。

整體思路大概就是識別出圖中數字生成list,然后求解。

輸入輸出demo

數獨采用的是微軟自帶的Microsoft sudoku軟件隨便截取的圖像,如下圖所示:

利用Python如何實現識別照片中的條形碼

經過程序求解后,得到的結果如下圖所示:

利用Python如何實現識別照片中的條形碼

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

程序具體流程

程序整體流程如下圖所示:

利用Python如何實現識別照片中的條形碼

讀入圖像后,根據求解輪廓信息找到數字所在位置,以及不包含數字的空白位置,提取數字信息通過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如何實現識別照片中的條形碼就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

柳州市| 肃南| 吉林省| 无极县| 佳木斯市| 丰城市| 尚志市| 石城县| 封开县| 安国市| 九寨沟县| 汕尾市| 兴和县| 织金县| 安阳市| 榆林市| 四子王旗| 平安县| 宣武区| 兴山县| 榕江县| 舟曲县| 淮北市| 奉新县| 原阳县| 巴东县| 开封市| 三门峡市| 巫溪县| 桃园市| 天水市| 阜新| 上思县| 井研县| 杭锦旗| 蒙城县| 渑池县| 会宁县| 玛纳斯县| 河津市| 凭祥市|