2021-08-18 20:15:59 索煒達(dá)電子 4898
項(xiàng)目編號(hào):E341
文件大?。?7M
源碼說明:帶中文注釋
開發(fā)環(huán)境:C編譯器
簡(jiǎn)要概述
本項(xiàng)目為基于OpenCV-Python和STM32F103單片機(jī)的二自由度人臉跟蹤舵機(jī)云臺(tái)系統(tǒng)。
本系統(tǒng)的預(yù)期功能是實(shí)時(shí)檢測(cè)攝像頭中出現(xiàn)的人臉,并對(duì)其進(jìn)行跟蹤。要實(shí)現(xiàn)該功能,主要應(yīng)解決如下問題:
圖像采集
人臉檢測(cè)
舵機(jī)控制
具體實(shí)現(xiàn)思路如下:
圖像采集方面,使用普通的usb攝像頭,這樣可以直接得到數(shù)字圖像無需進(jìn)行數(shù)模轉(zhuǎn)換,而且價(jià)格低廉,在不要求高精度的情況下比較適合。將usb攝像頭直接通過usb數(shù)據(jù)線接到電腦,即可在PC端得到實(shí)時(shí)圖像。
人臉檢測(cè)方面,在PC端編寫用于人臉檢測(cè)的python程序。使用opencv庫(kù),首先對(duì)從攝像頭得到的每一幀實(shí)時(shí)圖像進(jìn)行預(yù)處理,然后調(diào)用opencv自帶的harr分類器檢測(cè)人臉的位置。將檢測(cè)到的人臉的中心點(diǎn)坐標(biāo)用串口發(fā)送給STM32單片機(jī)即可。
舵機(jī)控制方面,使用STM32單片機(jī),根據(jù)串口接收到的來自上位機(jī)的坐標(biāo)分別對(duì)兩個(gè)舵機(jī)進(jìn)行獨(dú)立的位置控制。具體思路是,將圖像的中心點(diǎn)的橫縱坐標(biāo)(恒定值)與人臉中心點(diǎn)的橫縱坐標(biāo)分別作差,將該差值作為偏差輸入到STM32中實(shí)現(xiàn)的兩個(gè)PD控制器中,計(jì)算所需占空比,產(chǎn)生兩路PWM波驅(qū)動(dòng)舵機(jī)向偏差減小的方向轉(zhuǎn)動(dòng)。
實(shí)現(xiàn)效果
經(jīng)測(cè)試,該系統(tǒng)能夠?qū)崿F(xiàn)預(yù)期的功能。經(jīng)過調(diào)參后,調(diào)節(jié)時(shí)間很短,超調(diào)較小,系統(tǒng)的快速性和平穩(wěn)性均能達(dá)到預(yù)期目標(biāo)。系統(tǒng)的不足之處在于有一定穩(wěn)態(tài)誤差,但是考慮到舵機(jī)成本較低,系統(tǒng)的精度處在可以接受的范圍內(nèi)。
下圖分別是單人和多人的跟蹤效果:
目錄│文件列表:
└ 項(xiàng)目
│ Face Tracking Pan.docx
└ face-tracking-pan-tilt-camera
└ face-tracking-pan-tilt-camera
├ code
│ │ track_face.py
│ ├ control
│ │ │ keilkilll.bat
│ │ │ README.TXT
│ │ ├ CORE
│ │ │ │ core_cm3.c
│ │ │ │ core_cm3.h
│ │ │ └ startup_stm32f10x_hd.s
│ │ ├ HARDWARE
│ │ │ ├ KEY
│ │ │ │ │ key.c
│ │ │ │ └ key.h
│ │ │ ├ LED
│ │ │ │ │ led.c
│ │ │ │ └ led.h
│ │ │ ├ PID
│ │ │ │ │ pid.c
│ │ │ │ └ pid.h
│ │ │ ├ serial
│ │ │ │ │ serial.c
│ │ │ │ └ serial.h
│ │ │ └ TIMER
│ │ │ │ timer.c
│ │ │ └ timer.h
│ │ ├ OBJ
│ │ │ └ CONTROL.hex
│ │ ├ STM32F10x_FWLib
│ │ │ ├ inc
│ │ │ │ │ misc.h
│ │ │ │ │ stm32f10x_adc.h
│ │ │ │ │ stm32f10x_bkp.h
│ │ │ │ │ stm32f10x_can.h
│ │ │ │ │ stm32f10x_cec.h
│ │ │ │ │ stm32f10x_crc.h
│ │ │ │ │ stm32f10x_dac.h
│ │ │ │ │ stm32f10x_dbgmcu.h
│ │ │ │ │ stm32f10x_dma.h
│ │ │ │ │ stm32f10x_exti.h
│ │ │ │ │ stm32f10x_flash.h
│ │ │ │ │ stm32f10x_fsmc.h
│ │ │ │ │ stm32f10x_gpio.h
│ │ │ │ │ stm32f10x_i2c.h
│ │ │ │ │ stm32f10x_iwdg.h
│ │ │ │ │ stm32f10x_pwr.h
│ │ │ │ │ stm32f10x_rcc.h
│ │ │ │ │ stm32f10x_rtc.h
│ │ │ │ │ stm32f10x_sdio.h
│ │ │ │ │ stm32f10x_spi.h
│ │ │ │ │ stm32f10x_tim.h
│ │ │ │ │ stm32f10x_usart.h
│ │ │ │ └ stm32f10x_wwdg.h
│ │ │ └ src
│ │ │ │ misc.c
│ │ │ │ stm32f10x_adc.c
│ │ │ │ stm32f10x_bkp.c
│ │ │ │ stm32f10x_can.c
│ │ │ │ stm32f10x_cec.c
│ │ │ │ stm32f10x_crc.c
│ │ │ │ stm32f10x_dac.c
│ │ │ │ stm32f10x_dbgmcu.c
│ │ │ │ stm32f10x_dma.c
│ │ │ │ stm32f10x_exti.c
│ │ │ │ stm32f10x_flash.c
│ │ │ │ stm32f10x_fsmc.c
│ │ │ │ stm32f10x_gpio.c
│ │ │ │ stm32f10x_i2c.c
│ │ │ │ stm32f10x_iwdg.c
│ │ │ │ stm32f10x_pwr.c
│ │ │ │ stm32f10x_rcc.c
│ │ │ │ stm32f10x_rtc.c
│ │ │ │ stm32f10x_sdio.c
│ │ │ │ stm32f10x_spi.c
│ │ │ │ stm32f10x_tim.c
│ │ │ │ stm32f10x_usart.c
│ │ │ └ stm32f10x_wwdg.c
│ │ ├ SYSTEM
│ │ │ ├ delay
│ │ │ │ │ delay.c
│ │ │ │ └ delay.h
│ │ │ ├ sys
│ │ │ │ │ sys.c
│ │ │ │ └ sys.h
│ │ │ └ usart
│ │ │ │ usart.c
│ │ │ └ usart.h
│ │ └ USER
│ │ │ CONTROL.uvguix.James Wu
│ │ │ CONTROL.uvoptx
│ │ │ CONTROL.uvprojx
│ │ │ JLinkSettings.ini
│ │ │ main.c
│ │ │ stm32f10x.h
│ │ │ stm32f10x_conf.h
│ │ │ stm32f10x_it.c
│ │ │ stm32f10x_it.h
│ │ │ system_stm32f10x.c
│ │ │ system_stm32f10x.h
│ │ └ DebugConfig
│ │ └ USART_STM32F103ZE_1.0.0.dbgconf
│ └ data
│ └ haarcascade_frontalface_default.xml
└ images
│ cam_1.jpg
│ cam_1_2.png
│ cam_2.jpg
│ example.gif
│ multi.png
│ README.md
│ result_1.png
│ result_2.png
│ single.png
│ stm32_board.jpg
└ system.jpg