Opencv 处理开放CV人脸跟踪

Opencv 处理开放CV人脸跟踪,opencv,processing,Opencv,Processing,嗨,我从下面的代码vom Sparkfun开始做一些面部跟踪并得到这个错误: the type OpenCV is ambiguous 我尝试了OpenCV中用于处理库的其他示例。 而且它们可以毫无问题地工作(也是人脸跟踪示例) Sparkfun的原始代码是为不同的OpenCV(我相信是版本1)编写的。 但我无法使其工作,因为代码顶部没有导入库。 因为我安装了OpenCV for Processing,所以我导入了: import gab.opencv.*; 从那时起我就犯了这个错误。 我不

嗨,我从下面的代码vom Sparkfun开始做一些面部跟踪并得到这个错误:

the type OpenCV is ambiguous
我尝试了OpenCV中用于处理库的其他示例。 而且它们可以毫无问题地工作(也是人脸跟踪示例) Sparkfun的原始代码是为不同的OpenCV(我相信是版本1)编写的。 但我无法使其工作,因为代码顶部没有导入库。 因为我安装了OpenCV for Processing,所以我导入了:

import gab.opencv.*;
从那时起我就犯了这个错误。 我不明白为什么它不起作用,也不明白为什么它应该起作用(因为它没有在原始代码中导入OpenCV)

任何帮助都会很好

谢谢

/**********************************************************************************************
* Pan/Tilt Face Tracking Sketch
* Written by Ryan Owens for SparkFun Electronics
* Uses the OpenCV real-time computer vision  framework from Intel
* Based on the OpenCV Processing Examples from ubaa.net
* This example is released under the Beerware License.
* (Use the code however you'd like, but mention us and by me a beer if we ever meet!)
*
* The Pan/Tilt Face Tracking Sketch interfaces with an Arduino Main board to control
* two servos, pan and tilt, which are connected to a webcam. The OpenCV library
* looks for a face in the image from the webcam. If a face is detected the sketch
* uses the coordinates of the face to manipulate the pan and tilt servos to move the webcam
* in order to keep the face in the center of the frame.
*
* Setup-
* A webcam must be connected to the computer.
* An Arduino must be connected to the computer. Note the port which the Arduino is connected on.
* The Arduino must be loaded with the SerialServoControl Sketch.
* Two servos mounted on a pan/tilt backet must be connected to the Arduino pins 2 and 3.
* The Arduino must be powered by a 9V external power supply.
* 
* Read this tutorial for more information:
**********************************************************************************************/
import gab.opencv.*;
import hypermedia.video.*;  //Include the video library to capture images from the webcam
import java.awt.Rectangle;  //A rectangle class which keeps track of the face coordinates.
import processing.serial.*; //The serial library is needed to communicate with the Arduino.


OpenCV opencv; //Create an instance of the OpenCV library.

//Screen Size Parameters
int width = 320;
int height = 240;

// contrast/brightness values
int contrast_value    = 0;
int brightness_value  = 0;

Serial port; // The serial port

//Variables for keeping track of the current servo positions.
char servoTiltPosition = 90;
char servoPanPosition = 90;
//The pan/tilt servo ids for the Arduino serial command interface.
char tiltChannel = 0;
char panChannel = 1;

//These variables hold the x and y location for the middle of the detected face.
int midFaceY=0;
int midFaceX=0;

//The variables correspond to the middle of the screen, and will be compared to the midFace values
int midScreenY = (height/2);
int midScreenX = (width/2);
int midScreenWindow = 10;  //This is the acceptable 'error' for the center of the screen. 

//The degree of change that will be applied to the servo each time we update the position.
int stepSize=1;

void setup() {
  //Create a window for the sketch.
  size( width, height );

  opencv = new OpenCV( this );
  opencv.capture( width, height );                   // open video stream
  opencv.cascade( OpenCV.CASCADE_FRONTALFACE_ALT );  // load detection description, here-> front face detection : "haarcascade_frontalface_alt.xml"

  println(Serial.list()); // List COM-ports (Use this to figure out which port the Arduino is connected to)

  //select first com-port from the list (change the number in the [] if your sketch fails to connect to the Arduino)
  port = new Serial(this, Serial.list()[0], 57600);   //Baud rate is set to 57600 to match the Arduino baud rate.

  // print usage
  println( "Drag mouse on X-axis inside this sketch window to change contrast" );
  println( "Drag mouse on Y-axis inside this sketch window to change brightness" );

  //Send the initial pan/tilt angles to the Arduino to set the device up to look straight forward.
  port.write(tiltChannel);    //Send the Tilt Servo ID
  port.write(servoTiltPosition);  //Send the Tilt Position (currently 90 degrees)
  port.write(panChannel);         //Send the Pan Servo ID
  port.write(servoPanPosition);   //Send the Pan Position (currently 90 degrees)
}


public void stop() {
  opencv.stop();
  super.stop();
}



void draw() {
  // grab a new frame
  // and convert to gray
  opencv.read();
  opencv.convert( GRAY );
  opencv.contrast( contrast_value );
  opencv.brightness( brightness_value );

  // proceed detection
  Rectangle[] faces = opencv.detect( 1.2, 2, OpenCV.HAAR_DO_CANNY_PRUNING, 40, 40 );

  // display the image
  image( opencv.image(), 0, 0 );

  // draw face area(s)
  noFill();
  stroke(255,0,0);
  for( int i=0; i<faces.length; i++ ) {
    rect( faces[i].x, faces[i].y, faces[i].width, faces[i].height );
  }

  //Find out if any faces were detected.
  if(faces.length > 0){
    //If a face was found, find the midpoint of the first face in the frame.
    //NOTE: The .x and .y of the face rectangle corresponds to the upper left corner of the rectangle,
    //      so we manipulate these values to find the midpoint of the rectangle.
    midFaceY = faces[0].y + (faces[0].height/2);
    midFaceX = faces[0].x + (faces[0].width/2);

    //Find out if the Y component of the face is below the middle of the screen.
    if(midFaceY < (midScreenY - midScreenWindow)){
      if(servoTiltPosition >= 5)servoTiltPosition -= stepSize; //If it is below the middle of the screen, update the tilt position variable to lower the tilt servo.
    }
    //Find out if the Y component of the face is above the middle of the screen.
    else if(midFaceY > (midScreenY + midScreenWindow)){
      if(servoTiltPosition <= 175)servoTiltPosition +=stepSize; //Update the tilt position variable to raise the tilt servo.
    }
    //Find out if the X component of the face is to the left of the middle of the screen.
    if(midFaceX < (midScreenX - midScreenWindow)){
      if(servoPanPosition >= 5)servoPanPosition -= stepSize; //Update the pan position variable to move the servo to the left.
    }
    //Find out if the X component of the face is to the right of the middle of the screen.
    else if(midFaceX > (midScreenX + midScreenWindow)){
      if(servoPanPosition <= 175)servoPanPosition +=stepSize; //Update the pan position variable to move the servo to the right.
    }

  }
  //Update the servo positions by sending the serial command to the Arduino.
  port.write(tiltChannel);      //Send the tilt servo ID
  port.write(servoTiltPosition); //Send the updated tilt position.
  port.write(panChannel);        //Send the Pan servo ID
  port.write(servoPanPosition);  //Send the updated pan position.
  delay(1);
}



/**
 * Changes contrast/brigthness values
 */
void mouseDragged() {
  contrast_value   = (int) map( mouseX, 0, width, -128, 128 );
  brightness_value = (int) map( mouseY, 0, width, -128, 128 );
}
/**********************************************************************************************
*平移/倾斜面跟踪草图
*由Ryan Owens为SparkFun Electronics撰写
*使用英特尔的OpenCV实时计算机视觉框架
*基于ubaa.net中的OpenCV处理示例
*此示例是根据Beerware许可证发布的。
*(请随意使用代码,但请提及我们,如果我们见过面,请给我一杯啤酒!)
*
*摇摄/倾斜面跟踪草图与Arduino主板连接,以进行控制
*两个伺服系统,摇摄和倾斜,连接到网络摄像头。OpenCV库
*从网络摄像头的图像中查找人脸。如果检测到面,则绘制草图
*使用面部坐标操纵摇摄和倾斜伺服来移动网络摄像头
*以使面保持在框架的中心。
*
*设置-
*网络摄像头必须连接到计算机。
*Arduino必须连接到计算机。注意Arduino连接的端口。
*Arduino必须加载SerialServoControl草图。
*安装在摇摄/倾斜靠背上的两个伺服必须连接到Arduino针脚2和3。
*Arduino必须由9V外部电源供电。
* 
*有关详细信息,请阅读本教程:
**********************************************************************************************/
导入gab.opencv.*;
导入超媒体。视频。*//包括用于从网络摄像头捕获图像的视频库
导入java.awt.Rectangle//跟踪面坐标的矩形类。
输入处理。串行。*//串行库需要与Arduino通信。
OpenCV-OpenCV//创建OpenCV库的实例。
//屏幕尺寸参数
整数宽度=320;
整数高度=240;
//对比度/亮度值
int对比度_值=0;
int亮度_值=0;
串行端口;//串口
//用于跟踪当前伺服位置的变量。
字符位置=90;
字符位置=90;
//Arduino串行命令接口的平移/倾斜伺服ID。
字符倾斜通道=0;
char panChannel=1;
//这些变量保留检测到的面中间的x和y位置。
int midFaceY=0;
int midFaceX=0;
//变量对应于屏幕中间,并将与中间面值进行比较
内斜中线=(高度/2);
int中屏幕=(宽度/2);
int中屏幕窗口=10//这是屏幕中心可接受的“错误”。
//每次更新位置时应用于伺服的变化程度。
int步长=1;
无效设置(){
//为草图创建一个窗口。
尺寸(宽度、高度);
opencv=新的opencv(本);
opencv.capture(宽度、高度);//打开视频流
opencv.cascade(opencv.cascade\u FRONTALFACE\u ALT);//加载检测描述,此处->正面检测:“haarcascade\u FRONTALFACE\u ALT.xml”
println(Serial.list());//列出COM端口(使用此选项确定Arduino连接到哪个端口)
//从列表中选择第一个com端口(如果草图未能连接到Arduino,请更改[]中的编号)
port=new Serial(这是Serial.list()[0],57600);//波特率设置为57600以匹配Arduino波特率。
//打印使用
println(“在此草图窗口内的X轴上拖动鼠标以更改对比度”);
println(“在此草图窗口内Y轴上拖动鼠标以更改亮度”);
//将初始摇摄/倾斜角度发送至Arduino,将设备设置为向前看。
port.write(倾斜通道);//发送倾斜伺服ID
port.write(伺服倾斜位置);//发送倾斜位置(当前为90度)
port.write(panChannel);//发送Pan伺服ID
port.write(servoPanPosition);//发送平移位置(当前为90度)
}
公共停车场(){
opencv.stop();
super.stop();
}
作废提款(){
//抓住一个新的框架
//并转换为灰色
opencv.read();
opencv.convert(灰色);
opencv.对比度(对比度值);
opencv.亮度(亮度值);
//继续检测
矩形[]面=opencv.detect(1.2,2,opencv.HAAR\u DO\u CANNY\u修剪,40,40);
//显示图像
图像(opencv.image(),0,0);
//绘制面区域(s)
noFill();
冲程(255,0,0);
对于(int i=0;i 0){
//如果找到面,请找到帧中第一个面的中点。
//注:面矩形的.x和.y对应于矩形的左上角,
//所以我们操纵这些值来找到矩形的中点。
midFaceY=面[0]。y+(面[0]。高度/2);
midFaceX=面[0]。x+(面[0]。宽度/2);
//确定面的Y分量是否位于屏幕中间以下。
if(中间面<(中间斜纹-中间斜纹){
如果(servoTiltPosition>=5)servoTiltPosition-=stepSize;//如果低于屏幕中间,则更新倾斜位置变量以降低倾斜伺服。
}
//确定面的Y分量是否位于屏幕中间上方。
否则,如果(中间面>(中间斜纹+中间斜纹){
如果(servoTiltPosition=5)servoPanPosition-=stepSize;//更新平移位置变量以向左移动伺服。
}
//找出fa的X分量