【发布时间】:2017-03-30 17:19:13
【问题描述】:
我正在从事面部跟踪项目。我在 python 上成功编码了人脸检测。我需要通过网络摄像头跟踪我的脸。我有 arduino 用于电机控制。我无法追踪我的脸,很难与 arduino 交流。以及我应该使用什么代码来跟踪我不知道轴。请帮忙????
【问题讨论】:
我正在从事面部跟踪项目。我在 python 上成功编码了人脸检测。我需要通过网络摄像头跟踪我的脸。我有 arduino 用于电机控制。我无法追踪我的脸,很难与 arduino 交流。以及我应该使用什么代码来跟踪我不知道轴。请帮忙????
【问题讨论】:
Face Detection in Python Using a Webcam
import cv2
import sys
cascPath = sys.argv[1]
faceCascade = cv2.CascadeClassifier(cascPath)
video_capture = cv2.VideoCapture(0)
while True:
# Capture frame-by-frame
ret, frame = video_capture.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(
gray,
scaleFactor=1.1,
minNeighbors=5,
minSize=(30, 30),
flags=cv2.cv.CV_HAAR_SCALE_IMAGE
)
# Draw a rectangle around the faces
for (x, y, w, h) in faces:
cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
# Display the resulting frame
cv2.imshow('Video', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything is done, release the capture
video_capture.release()
cv2.destroyAllWindows()
但是你知道你不能在任何类型的微控制器上的 arduino 或任何其他 OpenCV 喜欢的(图像处理库)上使用它 就此而言,因为它们的处理器功率非常低,仅足以处理一些 IO 命令,但您也可以使用一些更昂贵的相机模块,并在硬件上内置人脸检测。 进行人脸检测;但如果使用网络摄像头,您将需要 raspberry pi 或任何其他具有足够 CPU 和 GPU 的单板电脑来完成这项工作。
和python的交流可以去arduino playground
安装pySerial后,从Arduino读取数据就很简单了:
>>> import serial
>>> ser = serial.Serial('/dev/tty.usbserial', 9600)
>>> while True:
... print ser.readline()
'1 Hello world!\r\n'
'2 Hello world!\r\n'
'3 Hello world!\r\n'
【讨论】: