Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.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
Image 在处理中为单个草图创建多个窗口_Image_Image Processing_Processing - Fatal编程技术网

Image 在处理中为单个草图创建多个窗口

Image 在处理中为单个草图创建多个窗口,image,image-processing,processing,Image,Image Processing,Processing,如何在处理中创建单个草图的多个窗口 实际上,我想在一个窗口中检测和跟踪特定颜色(通过网络摄像头),并将检测到的坐标显示为另一个窗口中的点。到目前为止,我能够在检测到坐标的同一窗口中显示这些点。但我想将其分为两个不同的窗口。您需要创建一个新的帧和一个新的PApplet。。。下面是一个示例草图: import javax.swing.*; SecondApplet s; void setup() { size(640, 480); PFrame f = new PFrame(width,

如何在处理中创建单个草图的多个窗口


实际上,我想在一个窗口中检测和跟踪特定颜色(通过网络摄像头),并将检测到的坐标显示为另一个窗口中的点。到目前为止,我能够在检测到坐标的同一窗口中显示这些点。但我想将其分为两个不同的窗口。

您需要创建一个新的帧和一个新的PApplet。。。下面是一个示例草图:

import javax.swing.*; 
SecondApplet s;
void setup() {
  size(640, 480);
  PFrame f = new PFrame(width, height);
  frame.setTitle("first window");
  f.setTitle("second window");
  fill(0);
}
void draw() {
  background(255);
  ellipse(mouseX, mouseY, 10, 10);
  s.setGhostCursor(mouseX, mouseY);
}
public class PFrame extends JFrame {
  public PFrame(int width, int height) {
    setBounds(100, 100, width, height);
    s = new SecondApplet();
    add(s);
    s.init();
    show();
  }
}
public class SecondApplet extends PApplet {
  int ghostX, ghostY;
  public void setup() {
    background(0);
    noStroke();
  }

  public void draw() {
    background(50);
    fill(255);
    ellipse(mouseX, mouseY, 10, 10);
    fill(0);
    ellipse(ghostX, ghostY, 10, 10);
  }
  public void setGhostCursor(int ghostX, int ghostY) {
    this.ghostX = ghostX;
    this.ghostY = ghostY;
  }
}

一个选项可能是创建一个两倍于原始窗口大小的草图,并将检测到的坐标偏移草图大小的一半

下面是一个非常粗略的代码片段(假设聚合blob将是检测到的颜色blob):

老实说,覆盖跟踪的信息可能更容易。例如,如果要进行颜色跟踪,只需显示跟踪区域边界框的轮廓即可

如果您真的想显示另一个窗口,可以使用。 请看一个正在运行的代码示例。

我建议使用GUI库进行处理,该库内置了一些处理多个窗口的功能。我以前用过一个摄像头,效果很好。它附带了一个可以轻松生成窗口的对象。网站上有一个解释基础知识的网站

我已经包括了一些旧的代码,我有,将向您展示基本的想法。代码中发生的事情是,我制作了两个gwindow,并分别向它们发送一个PImage来显示:一个获取网络摄像头图像,另一个获取受影响的图像。这样做的方法是扩充GWinData对象,使其也包含希望传递给windows的数据。我并没有为每个窗口创建一个特定的对象,而是创建了一个包含两个PImages的对象。每个GWindow都有自己的绘制循环(在示例底部),在该循环中,它从覆盖的GWinData对象加载PImage并显示它。在主绘制循环中,我读取网络摄像头,然后对其进行处理以创建两个图像,然后将它们存储到GWinData对象中

希望这能给你足够的时间开始

import guicomponents.*;
import processing.video.*;

private GWindow window;
private GWindow window2;

Capture video;

PImage sorted;
PImage imgdif; // image with pixel thresholding

MyWinData data;

void setup(){

  size(640, 480,P2D); // Change size to 320 x 240 if too slow at 640 x 480

  // Uses the default video input, see the reference if this causes an error
  video = new Capture(this, 640, 480, 24);
  numPixels = video.width * video.height;

  data = new MyWinData();

  window = new GWindow(this, "TEST", 0,0, 640,480, true, P2D);
  window.isAlwaysOnTop();
  window.addData(data);
  window.addDrawHandler(this, "Window1draw");

  window2 = new GWindow(this, "TEST", 640,0 , 640,480, true, P2D);
  window2.isAlwaysOnTop();
  window2.addData(data);
  window2.addDrawHandler(this, "Window2draw");

  loadColors("64rev.csv");
  colorlength = mycolors.length;
  distances = new float[colorlength];

  noCursor(); 
}

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

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

      imgdif = get(); // clones the last image drawn to the screen v1.1     
      sorted = get();
      /// Removed a lot of code here that did the processing

      // hand data to our data class to pass to other windows
      data.sortedimage = sorted;
      data.difimage = imgdif;

    }
}

class MyWinData extends GWinData {
   public PImage sortedimage; 
   public PImage difimage;

   MyWinData(){
      sortedimage = createImage(640,480,RGB); 
      difimage = createImage(640,480,RGB);
    }
}


public void Window1draw(GWinApplet a, GWinData d){
  MyWinData data = (MyWinData) d;
  a.image(data.sortedimage, 0,0);
}


public void Window2draw(GWinApplet a, GWinData d){
  MyWinData data = (MyWinData) d;
  a.image(data.difimage,0,0);
}

乔治的解决方案(将尺寸增加一倍)可能也是我更喜欢的方案,因为它总是将东西整齐地放在适当的位置!你介意看看这个吗?我在这里遇到了一个类似的问题,我想知道这个解决方案是否适用于我的情况?你介意看看这个吗?我在这里遇到了一个类似的问题,我想知道这个解决方案是否适用于我的情况?
import guicomponents.*;
import processing.video.*;

private GWindow window;
private GWindow window2;

Capture video;

PImage sorted;
PImage imgdif; // image with pixel thresholding

MyWinData data;

void setup(){

  size(640, 480,P2D); // Change size to 320 x 240 if too slow at 640 x 480

  // Uses the default video input, see the reference if this causes an error
  video = new Capture(this, 640, 480, 24);
  numPixels = video.width * video.height;

  data = new MyWinData();

  window = new GWindow(this, "TEST", 0,0, 640,480, true, P2D);
  window.isAlwaysOnTop();
  window.addData(data);
  window.addDrawHandler(this, "Window1draw");

  window2 = new GWindow(this, "TEST", 640,0 , 640,480, true, P2D);
  window2.isAlwaysOnTop();
  window2.addData(data);
  window2.addDrawHandler(this, "Window2draw");

  loadColors("64rev.csv");
  colorlength = mycolors.length;
  distances = new float[colorlength];

  noCursor(); 
}

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

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

      imgdif = get(); // clones the last image drawn to the screen v1.1     
      sorted = get();
      /// Removed a lot of code here that did the processing

      // hand data to our data class to pass to other windows
      data.sortedimage = sorted;
      data.difimage = imgdif;

    }
}

class MyWinData extends GWinData {
   public PImage sortedimage; 
   public PImage difimage;

   MyWinData(){
      sortedimage = createImage(640,480,RGB); 
      difimage = createImage(640,480,RGB);
    }
}


public void Window1draw(GWinApplet a, GWinData d){
  MyWinData data = (MyWinData) d;
  a.image(data.sortedimage, 0,0);
}


public void Window2draw(GWinApplet a, GWinData d){
  MyWinData data = (MyWinData) d;
  a.image(data.difimage,0,0);
}