使用Python3的OpenCV庫(kù)來(lái)識(shí)別攝像頭中的文字,以及使用OCR(光學(xué)字符識(shí)別)技術(shù)。
安裝OpenCV庫(kù)
在命令行中輸入以下命令來(lái)安裝OpenCV庫(kù):
pip install opencv-python
安裝Tesseract OCR庫(kù)
Tesseract OCR庫(kù)是一種免費(fèi)的光學(xué)字符識(shí)別庫(kù),它可以識(shí)別多種語(yǔ)言的文字。您可以在命令行中使用以下命令來(lái)安裝它:
pip install pytesseract
打開(kāi)攝像頭
使用以下代碼打開(kāi)攝像頭:
import cv2
cap = cv2.VideoCapture(0)
讀取攝像頭中的文字
使用以下代碼來(lái)讀取攝像頭中的文字:
import pytesseract
while True:
ret, frame = cap.read()
text = pytesseract.image_to_string(frame, lang='eng')
print(text)
這將輸出攝像頭捕獲的文本。
關(guān)閉攝像頭
使用以下代碼關(guān)閉攝像頭:文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-612835.html
cap.release()
完整代碼:
import cv2
import pytesseract
cap = cv2.VideoCapture(0)
while True:
ret, frame = cap.read()
text = pytesseract.image_to_string(frame, lang='eng')
print(text)
cv2.imshow('frame', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
這個(gè)代碼將打開(kāi)攝像頭,讀取攝像頭中的文字,并在窗口中顯示它。按下“q”鍵退出程序。文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-612835.html
到了這里,關(guān)于Python - OpenCV、OCR識(shí)別攝像頭中的文字的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!