翻譯|使用教程|編輯:楊鵬連|2021-02-20 11:42:57.513|閱讀 328 次
概述:有人可能對基于Intel的Python應(yīng)用程序能否很好地運行感到好奇Apple M1 Mac。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
Dynamsoft Barcode Reader SDK一款多功能的條碼讀取控件,只需要幾行代碼就可以將條碼讀取功能嵌入到Web或桌面應(yīng)用程序。這可以節(jié)省數(shù)月的開發(fā)時間和成本。能支持多種圖像文件格式以及從攝像機或掃描儀獲取的DIB格式。使用Dynamsoft Barcode Reader SDK,你可以創(chuàng)建強大且實用的條形碼掃描儀軟件,以滿足你的業(yè)務(wù)需求。
點擊下載Dynamsoft Barcode Reader最新版
有人可能對基于Intel的Python應(yīng)用程序能否很好地運行感到好奇Apple M1 Mac。我最近用Dynamsoft Python條形碼SDK進(jìn)行了測試,該SDK使用本機x86_64庫和CPython。事實證明,使用pip該工具安裝輪包并運行我的Python條碼讀取器應(yīng)用程序沒有任何問題。
安裝Pip和Python條形碼轉(zhuǎn)盤軟件包
當(dāng)您打開終端應(yīng)用程序并Python3第一次輸入時,將彈出一個提示對話框,用于安裝命令行開發(fā)人員工具。
單擊Install并等待一段時間以安裝相關(guān)工具。之后,您可以python3在終端中成功運行。
下一步是安裝pip:curl //bootstrap.pypa.io/get-pip.py -o get-pip.py python3 get-pip.py準(zhǔn)備好點子之后,您可以嘗試安裝Dynamsoft Python條形碼SDK:
python3 -m pip install dbr如果看到失敗消息,請不要感到驚訝。
% file $(which python3) /usr/bin/python3: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit executable x86_64] [arm64e:Mach-O 64-bit executable arm64e] /usr/bin/python3 (for architecture x86_64): Mach-O 64-bit executable x86_64 /usr/bin/python3 (for architecture arm64e): Mach-O 64-bit executable arm64e如您所見,Python 3是通用應(yīng)用程序,支持x86_64。因此,我們可以通過指定arch安裝x86_64 wheel軟件包:
arch -x86_64 $(which python3) -m pip install dbr恭喜你!您已經(jīng)安裝了Dynamsoft Python條形碼SDK。從現(xiàn)在開始,您可以開始使用網(wǎng)絡(luò)攝像頭創(chuàng)建條形碼掃描應(yīng)用程序。
在Apple M1 Mac上構(gòu)建基于網(wǎng)絡(luò)攝像頭的Python條形碼閱讀器
安裝OpenCV-Python以捕獲網(wǎng)絡(luò)攝像頭視頻流:
arch -x86_64 $(which python3) -m pip opencv-python打開相機并實時顯示視頻流:
import cv2 as cv cap = cv.VideoCapture(0) while True: _ret, frame = cap.read() if not _ret: break cv.imshow('BarcodeReader', frame) ch = cv.waitKey(1) # ESC if ch == 27: break由于掃描條形碼是一項占用大量CPU的任務(wù),因此我們應(yīng)該在Python進(jìn)程而不是Python線程中運行它:
from dbr import * from multiprocessing import Process, Queue def process_barcode_frame(license, frameQueue, resultQueue): # Create Dynamsoft Barcode Reader reader = BarcodeReader() # Apply for a trial license: //www.dynamsoft.com/customer/license/trialLicense reader.init_license(license) settings = reader.get_runtime_settings() settings.max_algorithm_thread_count = 1 reader.update_runtime_settings(settings) while True: results = None try: frame = frameQueue.get(False, 10) if type(frame) is str: break except: continue try: frameHeight, frameWidth, channel = frame.shape[:3] results = reader.decode_buffer_manually(np.array(frame).tobytes(), frameWidth, frameHeight, frame.strides[0], EnumImagePixelFormat.IPF_RGB_888) except BarcodeReaderError as error: print(error) try: resultQueue.put(results, False, 10) except: pass barcodeScanning = Process(target=process_barcode_frame, args=(license, frameQueue, resultQueue)) barcodeScanning.start()注意:您還需要有效的SDK許可證。
在主要過程中,創(chuàng)建兩個隊列以連續(xù)發(fā)送圖像幀和接收條形碼掃描結(jié)果:
frameQueue = Queue(size) resultQueue = Queue(size) while True: _ret, frame = cap.read() if not _ret: break try: results = resultQueue.get(False, 10) except: pass cv.imshow('BarcodeReader', frame) # Append a frame to the frame queue try: frameQueue.put(frame.copy(), False, 10) except: pass ch = cv.waitKey(1) # ESC if ch == 27: break現(xiàn)在,我們可以測試Python條形碼程序:
arch -x86_64 $(which python3) barcode_scanning.py license.txt還有一件事,由于相機權(quán)限的限制,您可能無法運行該應(yīng)用程序。除了終端應(yīng)用程序,您還可以安裝iTerm2來請求攝像頭訪問。
最后,我們可以在Apple M1 Mac上進(jìn)行條形碼掃描。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自: