基于OpenMV的圖像識別之?dāng)?shù)字識別功能
基于OpenMV的圖像識別
OpenMV簡介
什么是OpenMV
OpenMV是由美國克里斯團(tuán)隊基于MicroPython發(fā)起的開源機器視覺項目,目的是創(chuàng)建低成本,可擴展,使用python驅(qū)動的機器視覺模塊。OpenMV搭載了MicroPython解釋器,使其可以在嵌入式端進(jìn)行python開發(fā),關(guān)于MicroPython可以參照我之前的博客專欄:MicroPython. OpenMV基于32位,ARM Cortex-M7內(nèi)核的OpenMV-H7, 并結(jié)合各種攝像頭,可以進(jìn)行多種機器視覺應(yīng)用的實現(xiàn),比如人臉檢測,物體分類等。
OpenMV是一個開源,低成本,功能強大的機器視覺模塊,以STM32F427CPU為核心,集成了OV7725攝像頭芯片,在小巧的硬件模塊上,用C語言高效地實現(xiàn)了核心機器視覺算法,提供Python編程接口 。同時 OpenMV也是一個可編程的攝像頭,通過Python語言可實現(xiàn)你想要的邏輯。而且攝像頭本身也內(nèi)置了一些圖像處理的算法,使用起來也更加的方便,僅需要寫一些簡單的Python代碼,即可輕松的完成各種機器視覺相關(guān)的任務(wù)。在此,我們通過OpenMV實現(xiàn)了數(shù)字識別。
在打開OpenMV攝像頭鏈接電腦時,會彈出讓你升級的窗口
這時切忌一定要選擇Cancel鍵,
不能選擇升級?。?!
不能選擇升級?。。?/strong>
不能選擇升級?。?!
然后在進(jìn)行下一步的操作
一、數(shù)字識別
數(shù)字識別的基礎(chǔ)是需要配置使用NCC模板匹配。通過NCC模板的匹配可把
需要識別的數(shù)字模板圖片保存到SD卡中,然后可進(jìn)行下一步的識別。
1、可以通過打開模板匹配的歷程來直接打開代碼進(jìn)行使用
2、如果運行出現(xiàn)這個窗口就說明沒有保存模板圖片
所以這時就需要創(chuàng)建一個模板圖片:創(chuàng)建模板圖片的詳細(xì)視頻教程
創(chuàng)建一個模板圖片首先要打開一個helloworld歷程文件
然后在helloworld歷程文件中進(jìn)行匹配0~9這樣的基本數(shù)字,對這些數(shù)字進(jìn)
行一一截取,用它們來作為我們的模板圖片。
在右邊的Frame Buffer框中進(jìn)行截取,注意:不要點Zoom,因為Zoom展示
的是放大后的效果,在識別時可能會導(dǎo)致失幀。
然后點擊左鍵選出一個框(如圖所示)
選完框后點擊右鍵選擇Save Image selection to PC
最后把截取的數(shù)字圖片進(jìn)行保存,一定要保存到OpenMV的SD卡中,保存的文件名可自己
定義
3、把template.pgm改為你創(chuàng)建的模板圖片的名稱
(注意:模板圖片的格式一定要是pgm的格式,轉(zhuǎn)換格式可以在
https://convertio.co/zh/bmp-pgm/網(wǎng)站直接進(jìn)行轉(zhuǎn)換)
4、改完之后就可以運行
下面展示一些 有關(guān)數(shù)字識別的代碼。
此代碼為源代碼,可根據(jù)自己的需求在上面進(jìn)行改動。
代碼來源:數(shù)字識別代碼,可直接引用并修改
# Template Matching Example - Normalized Cross Correlation (NCC) # # This example shows off how to use the NCC feature of your OpenMV Cam to match # image patches to parts of an image... expect for extremely controlled enviorments # NCC is not all to useful. # # WARNING: NCC supports needs to be reworked! As of right now this feature needs # a lot of work to be made into somethin useful. This script will reamin to show # that the functionality exists, but, in its current state is inadequate. import time, sensor, image from image import SEARCH_EX, SEARCH_DS # Reset sensor sensor.reset() # Set sensor settings sensor.set_contrast(1) sensor.set_gainceiling(16) # Max resolution for template matching with SEARCH_EX is QQVGA sensor.set_framesize(sensor.QQVGA) # You can set windowing to reduce the search image. #sensor.set_windowing(((640-80)//2, (480-60)//2, 80, 60)) sensor.set_pixformat(sensor.GRAYSCALE) # Load template. # Template should be a small (eg. 32x32 pixels) grayscale image. template8 = image.Image("/8.pgm") template9 = image.Image("/9.pgm") clock = time.clock() # Run template matching while (True): clock.tick() img = sensor.snapshot() # find_template(template, threshold, [roi, step, search]) # ROI: The region of interest tuple (x, y, w, h). # Step: The loop step used (y+=step, x+=step) use a bigger step to make it faster. # Search is either image.SEARCH_EX for exhaustive search or image.SEARCH_DS for diamond search # # Note1: ROI has to be smaller than the image and bigger than the template. # Note2: In diamond search, step and ROI are both ignored. r 8= img.find_template(template8, 0.70, step=4, search=SEARCH_EX) #, roi=(10, 0, 60, 60)) if r8: img.draw_rectangle(r8) r 9= img.find_template(template9, 0.70, step=4, search=SEARCH_EX) #, roi=(10, 0, 60, 60)) if r9: img.draw_rectangle(r9) print(clock.fps())
運行的結(jié)果如圖所示
到此這篇關(guān)于基于OpenMV的圖像識別之?dāng)?shù)字識別的文章就介紹到這了,更多相關(guān)OpenMV圖像識別內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Pytorch GPU內(nèi)存占用很高,但是利用率很低如何解決
這篇文章主要介紹了Pytorch GPU內(nèi)存占用很高,但是利用率很低的原因及解決方法,具有很好的參考價值,希望對大家 有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-06-06如何使用yolov5輸出檢測到的目標(biāo)坐標(biāo)信息
YOLOv5是一系列在 COCO 數(shù)據(jù)集上預(yù)訓(xùn)練的對象檢測架構(gòu)和模型,下面這篇文章主要給大家介紹了關(guān)于如何使用yolov5輸出檢測到的目標(biāo)坐標(biāo)信息的相關(guān)資料,需要的朋友可以參考下2022-03-03