Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Colors 我想跟踪两种颜色,但只记录这两种颜色的运动并隐藏视频提要_Colors_Processing_Webcam_Tracking - Fatal编程技术网

Colors 我想跟踪两种颜色,但只记录这两种颜色的运动并隐藏视频提要

Colors 我想跟踪两种颜色,但只记录这两种颜色的运动并隐藏视频提要,colors,processing,webcam,tracking,Colors,Processing,Webcam,Tracking,背景:我将分析袋鼠妈妈护理期间父母的呼吸运动,我希望尊重他们的隐私,不记录他们,只记录我贴在他们胸部和腹部的贴纸的运动 到目前为止,我能够通过下面的代码跟踪基于网络摄像头输入的2种颜色。不过,为了保护家长的隐私,我只想记录跟踪的颜色,而不是网络摄像头的视频 有人知道如何添加背景色,同时还能跟踪颜色吗 import processing.video.*; Capture video; final int TOLERANCE = 20; float XRc = 0;// XY coordin

背景:我将分析袋鼠妈妈护理期间父母的呼吸运动,我希望尊重他们的隐私,不记录他们,只记录我贴在他们胸部和腹部的贴纸的运动

到目前为止,我能够通过下面的代码跟踪基于网络摄像头输入的2种颜色。不过,为了保护家长的隐私,我只想记录跟踪的颜色,而不是网络摄像头的视频

有人知道如何添加背景色,同时还能跟踪颜色吗

import processing.video.*;


Capture video; 
final int TOLERANCE = 20;

float XRc = 0;// XY coordinate of the center of the first target
float YRc = 0;
float XRh = 0;// XY coordinate of the center of the second target
float YRh = 0;

int ii=0; //Mouse click counter

color trackColor; //The first color is the center of the robot 
color trackColor2; //The second color is the head of the robot

void setup() {

size(640,480);
video = new Capture(this,640,480);
video.start();

trackColor = color(255,0,0);
trackColor2 = color(255,0,0);

smooth();
}

void draw() {
background(0);
if (video.available()) {
    video.read();
}

video.loadPixels();
image(video,0,0);

  float r2 = red(trackColor);
  float g2 = green(trackColor);
  float b2 = blue(trackColor);

  float r3 = red(trackColor2);
  float g3 = green(trackColor2);
  float b3 = blue(trackColor2);




  int somme_x = 0, somme_y = 0; 
  int compteur = 0;

  int somme_x2 = 0, somme_y2 = 0; 
  int compteur2 = 0;



  for(int x = 0; x < video.width; x++) {
    for(int y = 0; y < video.height; y++) {

      int currentLoc = x + y*video.width;
      color currentColor = video.pixels[currentLoc];

      float r1 = red(currentColor);
      float g1 = green(currentColor);
      float b1 = blue(currentColor);


      if(dist(r1,g1,b1,r2,g2,b2) < TOLERANCE) {
         somme_x += x;
         somme_y += y;
        compteur++;
      }

      else if(compteur > 0) { 
        XRc = somme_x / compteur;
        YRc = somme_y / compteur;
      }


      if(dist(r1,g1,b1,r3,g3,b3) < TOLERANCE) {
         somme_x2 += x;
         somme_y2 += y;
        compteur2++;
      }

      else if(compteur2 > 0) { 
        XRh = somme_x2 / compteur2;
        YRh = somme_y2 / compteur2;
      }



  }
  }




  if(XRc != 0 || YRc != 0) { // Draw a circle at the first target
    fill(trackColor);
    strokeWeight(0.05);
    stroke(0);
    ellipse(XRc,YRc,20,20);
  }


  if(XRh != 0 || YRh != 0) {// Draw a circle at the second target
    fill(trackColor2);
    strokeWeight(0.05);
    stroke(0);
    ellipse(XRh,YRh,20,20);
  }

}
void mousePressed() {
  if (mousePressed && (mouseButton == RIGHT)) { // Save color where the mouse is clicked in trackColor variable  
  if(ii==0){  

    if (mouseY>480){mouseY=0;mouseX=0;}
  int loc = mouseX + mouseY*video.width;

  trackColor = video.pixels[loc];
ii=1;  
}
  else if(ii==1){  
    if (mouseY>480){mouseY=0;mouseX=0;}
  int loc2 = mouseX + mouseY*video.width;
  trackColor2 = video.pixels[loc2];
ii=2;  

}


  }
  }
尝试添加背景0;就在你画第一个圆之前。它应该覆盖视频,你可以在上面画圆圈

问候 何塞