亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Python識(shí)別處理照片中的條形碼

 更新時(shí)間:2020年11月16日 10:20:05   作者:破曉之愛(ài)  
這篇文章主要介紹了Python識(shí)別處理照片中的條形碼,幫助大家更好的利用python處理圖片,提高辦公效率,感興趣的朋友可以了解下

最近一直在玩數(shù)獨(dú),突發(fā)奇想實(shí)現(xiàn)圖像識(shí)別求解數(shù)獨(dú),輸入到輸出平均需要0.5s。

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

輸入輸出demo

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

經(jīng)過(guò)程序求解后,得到的結(jié)果如下圖所示:

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,比如多次出現(xiàn)var,index只會(huì)返回最左側(cè)的
            if production.right.index(var) != len(production.right) - 1:
                follow_dic[var] = first_dic[production.right[production.right.index(var) + 1]] | follow_dic[var]
            # 沒(méi)有考慮右邊有非終結(jié)符但是為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

程序具體流程

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

讀入圖像后,根據(jù)求解輪廓信息找到數(shù)字所在位置,以及不包含數(shù)字的空白位置,提取數(shù)字信息通過(guò)KNN識(shí)別,識(shí)別出數(shù)字;無(wú)數(shù)字信息的在list中置0;生成未求解數(shù)獨(dú)list,之后求解數(shù)獨(dú),將信息在原圖中顯示出來(lái)。

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", " 關(guān)鍵字"], [1, "lexicalanalysis", " 標(biāo)識(shí)符"], [13, "(", " 左括號(hào)"], [14, ")", " 右括號(hào)"], [20, "{", " 左大括號(hào)"],
          [4, "float", " 關(guān)鍵字"], [1, "a", " 標(biāo)識(shí)符"], [15, ";", " 分號(hào)"], [5, "int", " 關(guān)鍵字"], [1, "b", " 標(biāo)識(shí)符"],
          [15, ";", " 分號(hào)"], [1, "a", " 標(biāo)識(shí)符"], [12, "=", " 賦值號(hào)"], [3, "1.1", " 浮點(diǎn)數(shù)"], [15, ";", " 分號(hào)"], [1, "b", " 標(biāo)識(shí)符"],
          [12, "=", " 賦值號(hào)"], [2, "2", " 整數(shù)"], [15, ";", " 分號(hào)"], [8, "while", "  關(guān)鍵字"], [13, "(", " 左括號(hào)"],
          [1, "b", " 標(biāo)識(shí)符"], [17, "<", " 小于號(hào)"], [2, "100", " 整數(shù)"], [14, ")", " 右括號(hào)"], [20, "{", " 左大括號(hào)"],
          [1, "b", " 標(biāo)識(shí)符"], [12, "=", " 賦值號(hào)"], [1, "b", " 標(biāo)識(shí)符"], [9, "+", " 加 號(hào)"], [2, "1", " 整數(shù)"], [15, ";", " 分號(hào)"],
          [1, "a", " 標(biāo)識(shí)符"], [12, "=", " 賦值號(hào)"], [1, "a", " 標(biāo)識(shí)符"], [9, "+", " 加號(hào)"], [2, "3", " 整數(shù)"], [15, ";", " 分號(hào)"],
          [21, "}", " 右大括號(hào)"], [15, ";", " 分號(hào)"], [6, "if", " 關(guān)鍵字"], [13, "(", " 左括號(hào)"], [1, "a", " 標(biāo)識(shí)符"],
          [16, ">", " 大于號(hào)"], [2, "5", " 整數(shù)"], [14, ")", " 右括號(hào)"], [20, "{", " 左大括號(hào)"], [1, "b", " 標(biāo)識(shí)符"],
          [12, "=", " 賦值號(hào)"], [1, "b", " 標(biāo)識(shí)符"], [10, "-", " 減號(hào)"], [2, "1", " 整數(shù)"], [15, ";", " 分號(hào)"], [21, "}", " 右大括號(hào)"],
          [7, "else", " 關(guān)鍵字"], [20, "{", " 左大括號(hào)"], [1, "b", " 標(biāo)識(shí)符"], [12, "=", " 賦值號(hào)"], [1, "b", " 標(biāo)識(shí)符"],
          [9, "+", " 加號(hào)"], [2, "1", " 整數(shù)"], [15, ";", " 分號(hào)"], [21, "}", " 右大括號(hào)"], [21, "}", " 右大括號(hào)"]]

以上就是Python識(shí)別處理照片中的條形碼的詳細(xì)內(nèi)容,更多關(guān)于python 識(shí)別條形碼的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • 單身狗福利?Python爬取某婚戀網(wǎng)征婚數(shù)據(jù)

    單身狗福利?Python爬取某婚戀網(wǎng)征婚數(shù)據(jù)

    今天我就當(dāng)回媒婆,給男性程序員來(lái)點(diǎn)福利.今天目標(biāo)爬取征婚網(wǎng)上呈現(xiàn)出來(lái)的女生信息保存成excel表格供大家篩選心儀的女生,需要的朋友可以參考下
    2021-06-06
  • Python3 使用cookiejar管理cookie的方法

    Python3 使用cookiejar管理cookie的方法

    今天小編就為大家分享一篇Python3 使用cookiejar管理cookie的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-12-12
  • python如何重載模塊實(shí)例解析

    python如何重載模塊實(shí)例解析

    這篇文章主要介紹了python如何重載模塊實(shí)例解析,涉及模塊的概念,載入和重載的實(shí)例,小編覺(jué)得還是挺不錯(cuò)的,具有一定借鑒價(jià)值,需要的朋友可以參考下
    2018-01-01
  • conda虛擬環(huán)境默認(rèn)路徑的修改方法

    conda虛擬環(huán)境默認(rèn)路徑的修改方法

    最近發(fā)現(xiàn)我linux系統(tǒng)中的/dev/root目錄利用率占用了100%,這對(duì)后面文件的操作帶來(lái)了一些麻煩,下面這篇文章主要給大家介紹了關(guān)于conda虛擬環(huán)境默認(rèn)路徑的修改方法,需要的朋友可以參考下
    2022-07-07
  • pandas 數(shù)據(jù)實(shí)現(xiàn)行間計(jì)算的方法

    pandas 數(shù)據(jù)實(shí)現(xiàn)行間計(jì)算的方法

    今天小編就為大家分享一篇pandas 數(shù)據(jù)實(shí)現(xiàn)行間計(jì)算的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-06-06
  • python Flask實(shí)現(xiàn)restful api service

    python Flask實(shí)現(xiàn)restful api service

    本篇文章主要介紹了python Flask實(shí)現(xiàn)restful api service,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-12-12
  • Python中不同類之間調(diào)用方法的四種方式小結(jié)

    Python中不同類之間調(diào)用方法的四種方式小結(jié)

    類是一種面向?qū)ο蟮木幊谭妒?它允許我們將數(shù)據(jù)和功能封裝在一個(gè)實(shí)體中,本文主要介紹了Python中不同類之間調(diào)用方法的四種方式小結(jié),具有一定的參考價(jià)值,感興趣的可以了解一下
    2024-02-02
  • Python3二分查找?guī)旌瘮?shù)bisect(),bisect_left()和bisect_right()的區(qū)別

    Python3二分查找?guī)旌瘮?shù)bisect(),bisect_left()和bisect_right()的區(qū)別

    這篇文章主要介紹了Python3二分查找?guī)旌瘮?shù)bisect(),bisect_left()和bisect_right()的區(qū)別,本文通過(guò)示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-03-03
  • 以Python的Pyspider為例剖析搜索引擎的網(wǎng)絡(luò)爬蟲(chóng)實(shí)現(xiàn)方法

    以Python的Pyspider為例剖析搜索引擎的網(wǎng)絡(luò)爬蟲(chóng)實(shí)現(xiàn)方法

    這篇文章主要介紹了以Python的Pyspider為例剖析搜索引擎的網(wǎng)絡(luò)爬蟲(chóng)實(shí)現(xiàn)方法,Pyspider是一個(gè)開(kāi)源項(xiàng)目、用Python語(yǔ)言編寫(xiě)十分簡(jiǎn)潔且具有爬蟲(chóng)程序的代表性,需要的朋友可以參考下
    2015-03-03
  • python 安全地刪除列表元素的方法

    python 安全地刪除列表元素的方法

    這篇文章主要介紹了python 安全地刪除列表元素的方法,分享的方法有 創(chuàng)建新列表,過(guò)濾元素和列表副本上迭代,下面相關(guān)內(nèi)容需要的小伙伴可以參考一下
    2022-03-03

最新評(píng)論