我想跟踪面对安卓——我在电脑上用它——现在我想在安卓上。arduino 程序控制的平移和倾斜伺服系统。我必须只将一个字符示例“w”发送到 arduino,因此 arduino 使其 +1 移动伺服等。我无法将该字符发送到 arduino。
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
mRgba = inputFrame.rgba();
mGray = inputFrame.gray();
if (mAbsoluteFaceSize == 0) {
int height = mGray.rows();
if (Math.round(height * mRelativeFaceSize) > 0) {
mAbsoluteFaceSize = Math.round(height * mRelativeFaceSize);
}
mNativeDetector.setMinFaceSize(mAbsoluteFaceSize);
}
MatOfRect faces = new MatOfRect();
if (mDetectorType == JAVA_DETECTOR) {
if (mJavaDetector != null)
mJavaDetector.detectMultiScale(mGray, faces, 1.1, 2, 2, // TODO: objdetect.CV_HAAR_SCALE_IMAGE
new Size(mAbsoluteFaceSize, mAbsoluteFaceSize), new Size());
}
else if (mDetectorType == NATIVE_DETECTOR) {
if (mNativeDetector != null)
mNativeDetector.detect(mGray, faces);
}
else {
Log.e(TAG, "Detection method is not selected!");
}
Rect[] facesArray = faces.toArray();
for (int i = 0; i < facesArray.length; i++)
Core.rectangle(mRgba, facesArray[i].tl(), facesArray[i].br(), FACE_RECT_COLOR, 3);
for( int i=0; i<facesArray.length; i++ ) {
rect( facesArray[i].x, facesArray[i].y, facesArray[i].width, facesArray[i].height );
if(facesArray[i].x < 640){
arduinoPort.write("w");
// println("left");
//moutput.write("d");
//mOutputStream.write("d".toString());
}
if(facesArray[i].x + facesArray[i].width > 1280){
//println("right");
arduinoPort.write("a");
}
if(facesArray[i].y + facesArray[i].height > 640){
//println("bottom");
arduinoPort.write("s");
}
if(facesArray[i].y < 320){
// println("top");
arduinoPort.write("w");
}
if ((facesArray[i].x > 640) && (facesArray[i].x + facesArray[i].width < 1280)){
//println("center");
arduinoPort.write("z");
}
return mRgba;
这是一个arduino代码
#include <Max3421e.h>
#include <Usb.h>
#include <AndroidAccessory.h>
#include <Servo.h>
Servo WristServo;
Servo BaseServo;
int tilt = 90;
int pan = 90;
void setup()
{
Serial.begin(9600);
WristServo.attach(11);
BaseServo.attach(12);
WristServo.write(tilt);
BaseServo.write(pan);
}
void loop()
{
if(Serial.available() > 0)
{
int data = Serial.read();
switch(data)
{
case 'w' : if (pan > 0) {pan -=1;} break;
case 's' : if (pan > 0) {pan +=1;} break;
case 'a' : if (tilt < 180) {tilt -=1;} break;
case 'd' : if (tilt > 0) {tilt +=1;} break;
default : break;
}
}
WristServo.write(tilt);
BaseServo.write(pan);
}