首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >找不到名为“Robot”的类

找不到名为“Robot”的类
EN

Stack Overflow用户
提问于 2016-05-28 13:56:12
回答 1查看 45关注 0票数 0

我正在创建一个通过面部检测来移动鼠标光标的程序。我在网上找到了this程序,我正在想办法改变它。

我得到的唯一错误是它找不到名为Robot的类。我确实尝试过用制表符、空格等来解决这个问题,但是我不知道问题出在哪里。

代码语言:javascript
运行
复制
import JMyron.*; 
import pFaceDetect.*;

JMyron m; 
PFaceDetect face;
PFaceDetect hand;
PImage img; 

Robot robby;

int search_width = 320;
int search_height = 240;
float actualX=search_width/2;
float actualY=search_height/2;
int x_rato = 0;
int y_rato = 0;

void setup() {  
 size(320,240,P3D);  
 m = new JMyron();  
 m.start(width,height);  
 face = new PFaceDetect(this,width,height, "haarcascade_frontalface_alt.xml");
 hand = new PFaceDetect(this,width,height, "aGest.xml");

 img = createImage(width,height,ARGB);  
 noFill();  
 stroke(255,0,0);  

 try
 {
   robby = new Robot();
 }
 catch (AWTException e)
 {
   println("Robot class not supported by your system!");
   exit();
 }
}  

void draw() {  
 m.update();  

 int[] imgNormal = m.cameraImage();  
 this.loadPixels();  
 for(int i=1; i<width;i++){  
   for(int j=1;j<height;j++){  
    this.pixels[(m.width() - i - 1) + j * m.width()] = imgNormal[(i) + j * m.width()];  
   }  
 }  
 this.updatePixels();  

 arraycopy(m.cameraImage(),img.pixels);

 face.findFaces(img); 
 drawFace(); 
 hand.findFaces(img);
 drawHand();

  // code for drawing the lines     
  line((width/2-10),0,(width/2-10),height);
  line((width/2+10),0,(width/2+10),height);
  line(0,(height/2-10),width,(height/2-10));
  line(0,(height/2+10),width,(height/2+10));

  //verifica posição do ponto
  //diagonal subir para direita
  if (actualX < (width/2-10) && actualY < (height/2-10))
   {
     x_rato = x_rato + 4;
     y_rato = y_rato - 4;
   }

   else if (actualX > (width/2+10) && actualY < (height/2-10))
   {
     x_rato = x_rato - 4;
     y_rato = y_rato - 4;
   }
   //subir 
   else if (actualX < (width/2+10) && actualX > (width/2-10) && actualY < (height/2-10))
   {
     y_rato = y_rato - 4;
   }

   else if (actualX < (width/2+10) && actualX > (width/2-10) && actualY > (height/2+10))
   {
     y_rato = y_rato + 4;
   }

   else if (actualX < (width/2-10) && actualY > (height/2+10))
   {
     x_rato = x_rato + 4;
     y_rato = y_rato + 4;
   }
   //diagonal descer para esquerda
   else if (actualX > (width/2+10) && actualY > (height/2+10))
   {
     x_rato = x_rato - 4;
     y_rato = y_rato + 4;
   }
   else if (actualX > (width/2+10) && actualY < (height/2+10) && actualY > (height/2-10))
   {
     x_rato = x_rato - 4;
   }

   else if (actualX < (width/2-10) && actualY < (height/2+10) && actualY > (height/2-10))
   {
     x_rato = x_rato + 4;
   }
   print(actualY+"\n");
   robby.mouseMove(screen.width/2+x_rato, screen.height/2+y_rato);
}

void drawFace() {
 int [][] res = face.getFaces();
 if (res.length>0) {
   for (int i=0;i<res.length;i++) {
     int x = res[i][0];
     int y = res[i][1];
     int w = res[i][2];
     int h = res[i][3];
     x = x + w/2;
     actualX = round(actualX + 0.1*(x-actualX));
     y = y + h/2;
     actualY = round(actualY + 0.1*(y-actualY));
     /*pushMatrix();
     strokeWeight(10);*/
     point(width-actualX, actualY);
     //popMatrix();
   }
 }
}

void drawHand() {
 int [][] res = hand.getFaces();
 if (res.length>0) {
   print("ai"+"\n");
   robby.mousePress(InputEvent.BUTTON1_MASK);
   robby.delay(500);
   robby.mouseRelease(InputEvent.BUTTON1_MASK);
   }
}


void stop() {
 m.stop();
 super.stop();
}
EN

回答 1

Stack Overflow用户

发布于 2016-05-28 19:06:01

您可能需要先导入代码顶部的Robot

代码语言:javascript
运行
复制
import java.awt.Robot;

此外,您可能希望查看一个较新的库,该库可以提供人脸检测功能,如OpenCV Processing

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37495715

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档