资源简介
利用Haarcascade所建立的脸部特征模型,对OpenCV处理过的帧图像实现脸部检测。之后,根据识别到的区域,来确定所识别到物体的中心点。根据物体的中心点和视频画面的中心点之间的误差,可以确定出转动的方向。最后通过与Arduino互联完成舵机的驱动,并实现摄像头对主体脸部的跟踪。

代码片段和文件信息
import time
import cv2
import serial
import asyncio
import threading
class PID:
def __init__(self kP=0.1 kI=0.0 kD=0.0):
# initialize gains
self.kP = kP
self.kI = kI
self.kD = kD
def initialize(self):
# intialize the current and previous time
# self.currTime = time.time()
# self.prevTime = self.currTime
# initialize the previous error
self.prevError = 0
# initialize the term result variables
self.cP = 0
self.cI = 0
self.cD = 0
def update(self errordeltaTime):
# grab the current time and calculate delta time
self.currTime = time.time()
# delta error
deltaError = error - self.prevError
# proportional term
self.cP = error
# integral term
self.cI += error * deltaTime
# derivative term and prevent divide by zero
self.cD = (deltaError / deltaTime) if deltaTime > 0 else 0
# # save previous time and error for the next update
self.prevError = error
# sum the terms and return
return sum([
self.kP * self.cP
self.kI * self.cI
self.kD * self.cD])
def conter():
if cap.isOpened():
res img = cap.read()
(hw) = img.shape[:2]
return h//2w//2
def inrange(nummin=0max=180):
return (num > min and num < max)
async def face_capture():
global center_x #人脸中心的坐标
global center_y
global deltatime
global Scan
global flag
while cap.isOpened():
pretime = time.time()
res img = cap.read()
gray = cv2.cvtColor(img cv2.COLOR_BGR2GRAY)
Scan = face.detectMultiScale(grayscaleFactor=1.3minNeighbors=3)
# print(type(Scan))
for (x y w h) in Scan:
cv2.rectangle(img (x y) (x + w y + h) (255 0 0) 2) # 依靠对角线来定矩形
center_x = int(x + w/2)
center_y = int(y + h / 2)
cv2.imshow(“CaptureFace“img)
deltatime = time.time()-pretime
# print(deltatime)
await asyncio.sleep(0.01)
key = cv2.waitKey(50) & 0xff
if key == 27: # ESC的ASCALL码是27
flag = 1
break
cap.release()
cv2.destroyAllWindows()
async def caculatePID():
print(“Start“)
global pan_angle
global tilt_angle
p1i1d1 = 0.0200.0550.00031
# p1i1d1 = 000
# p2i2d2 = 000
p2i2d2 = 0.0220.00210.00038
pid_pan = PID(p1 i1 d1)
pid_tilt = PID(p2 i2 d2)
while flag == 0:
pid_pan.initialize()
pid_tilt.initialize()
if isinstance(Scan tuple) == False:
head_pan = pid_pan.update(cx-center_xdeltaTime=deltatime)
head_tilt = pid_tilt.update(cy-center_ydeltaTime=deltatime)
else:
head_pan = head_tilt = 0
if inrange
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2020-05-24 12:45 Face-tracking\
文件 3933 2020-05-22 13:11 Face-tracking\FaceTracking_PID.py
文件 930127 2020-03-16 11:20 Face-tracking\haarcascade_frontalface_default.xm
文件 140975 2020-03-17 17:47 Face-tracking\haarcascade_frontalface_default.zip
文件 694 2020-05-09 21:10 Face-tracking\pan-tilt.ino
- 上一篇:QT项目code.rar
- 下一篇:2018最新git视频教程
相关资源
- Pythonamp;课堂amp;笔记(高淇amp;400;集第
- Python中Numpy库最新教程
- 用python编写的移动彩信的发送程序
- Python全栈学习笔记面向对象大作业:
- python实现的ftp自动上传、下载脚本
- ADNS-3080光流传感器测试程序Arduino
- Python版的A*寻路算法
- IronPython IDE
- EESkill NRF24L01 无线模块用户手册
- Arduino nano 工程文件
- Arduino教程 Lesson 之--自制风扇
- 基于Arduino的智能环境监控系统设计
- 基于Arduino和Machtalk的温棚环境监测系
- pip-10.0.1.tar.gz
- Data Science from Scratch 2nd Edition
- shape_predictor_68_face_landmarks.dat.bz2 68个标
- 爬取豆瓣电影TOP250程序,包含非常详
- arduino pca9685多舵机同时控制案例
- 中文维基百科语料库百度网盘网址.
- MSCNN_dehaze.rar
- 爬取豆瓣排行榜电影数据(含GUI界面
- 字典文本资源
- Brainfuck / OoK 解码脚本
- arduino技术内幕
- Arduino电子设计实战指南.零基础篇_超
- 物联网智能家居平台DIY:ARDUINO 物联网
- 实验1.zip arduino跑马灯led灯实验,串口
- 案例实战信用卡欺诈检测数据集
- opencat所有资料.zip
- 招商策略_抱团启示录那些年我们一起
评论
共有 条评论