Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/321.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
Java IntelliJ上的PApplet错误_Java_Intellij Idea_Processing_Kinect_Openkinect - Fatal编程技术网

Java IntelliJ上的PApplet错误

Java IntelliJ上的PApplet错误,java,intellij-idea,processing,kinect,openkinect,Java,Intellij Idea,Processing,Kinect,Openkinect,我正在尝试使用IntelliJ上的Processing and OpenKinect库连接我的Kinect以用于手部检测,此代码适用于Processing 3,但由于某种原因,当我将其以适当的格式放到IntelliJ上时,我收到以下错误: 用法:PApplet[options][sketch args]参见Javadoc 请帕普莱解释一下 这是我正在使用的两个类 Main.java package lol.uk; import processing.core.*; //import org.o

我正在尝试使用IntelliJ上的Processing and OpenKinect库连接我的Kinect以用于手部检测,此代码适用于Processing 3,但由于某种原因,当我将其以适当的格式放到IntelliJ上时,我收到以下错误:

用法:PApplet[options][sketch args]参见Javadoc 请帕普莱解释一下

这是我正在使用的两个类

Main.java

package lol.uk;

import processing.core.*;
//import org.openkinect.freenect.*;
import org.openkinect.processing.*;
import processing.core.PImage;
import processing.core.PVector;
//import processing.core.PImage;

public class Main extends PApplet {

    KinectTracker tracker;
    Kinect kinect;


    public void setup() {
        size(640, 520);
        kinect = new Kinect(this);
        tracker = new KinectTracker();
    }

    public void draw() {
        background(255);

        // Run the tracking analysis
        tracker.track();
        // Show the image
        tracker.display();

        // Let's draw the raw location
        PVector v1 = tracker.getPos();
        fill(50, 100, 250, 200);
        noStroke();
        ellipse(v1.x, v1.y, 20, 20);

        // Let's draw the "lerped" location
        PVector v2 = tracker.getLerpedPos();
        fill(100, 250, 50, 200);
        noStroke();
        ellipse(v2.x, v2.y, 20, 20);

        // Display some info
        int t = tracker.getThreshold();
        fill(0);
        text("threshold: " + t + "    " + "framerate: " + (frameRate) + "    " + "UP increase threshold, DOWN decrease threshold", 10, 500);
    }

    public void keyPressed() {
        int t = tracker.getThreshold();
        if (key == CODED) {
            if (keyCode == UP) {
                t += 5;
                tracker.setThreshold(t);
            } else if (keyCode == DOWN) {
                t -= 5;
                tracker.setThreshold(t);
            }
        }
    }
}
package lol.uk;

import org.openkinect.processing.Kinect;
import processing.core.*;
import processing.core.PImage;
import processing.core.PVector;

public class KinectTracker extends PApplet {
    // Depth threshold
    int threshold = 500;

    Kinect kinect;

    // Raw location
    PVector loc;

    // Interpolated location
    PVector lerpedLoc;

    // Depth data
    int[] depth;

    // What we'll show the user
    PImage display;

    KinectTracker() {
        // This is an awkard use of a global variable here
        // But doing it this way for simplicity
        kinect.initDepth();
        kinect.enableMirror(true);
        // Make a blank image
        display = createImage(kinect.width, kinect.height, RGB);
        // Set up the vectors
        loc = new PVector(0, 0);
        lerpedLoc = new PVector(0, 0);
    }

    public void track() {
        // Get the raw depth as array of integers
        depth = kinect.getRawDepth();

        // Being overly cautious here
        if (depth == null) return;

        float sumX = 0;
        float sumY = 0;
        float count = 0;

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

                int offset =  x + y*kinect.width;
                // Grabbing the raw depth
                int rawDepth = depth[offset];

                // Testing against threshold
                if (rawDepth < threshold) {
                    sumX += x;
                    sumY += y;
                    count++;
                }
            }
        }
        // As long as we found something
        if (count != 0) {
            loc = new PVector(sumX/count, sumY/count);
        }

        // Interpolating the location, doing it arbitrarily for now
        lerpedLoc.x = PApplet.lerp(lerpedLoc.x, loc.x, 0.3f);
        lerpedLoc.y = PApplet.lerp(lerpedLoc.y, loc.y, 0.3f);
    }

    PVector getLerpedPos() {
        return lerpedLoc;
    }

    PVector getPos() {
        return loc;
    }

    public void display() {
        PImage img = kinect.getDepthImage();

        // Being overly cautious here
        if (depth == null || img == null) return;

        // Going to rewrite the depth image to show which pixels are in threshold
        // A lot of this is redundant, but this is just for demonstration purposes
        display.loadPixels();
        for (int x = 0; x < kinect.width; x++) {
            for (int y = 0; y < kinect.height; y++) {

                int offset = x + y * kinect.width;
                // Raw depth
                int rawDepth = depth[offset];
                int pix = x + y * display.width;
                if (rawDepth < threshold) {
                    // A red color instead
                    display.pixels[pix] = color(150, 50, 50);
                } else {
                    display.pixels[pix] = img.pixels[offset];
                }
            }
        }
        display.updatePixels();

        // Draw the image
        image(display, 0, 0);
    }

    int getThreshold() {
        return threshold;
    }

    public void setThreshold(int t) {
        threshold =  t;
    }
}
KinectTracker.java

package lol.uk;

import processing.core.*;
//import org.openkinect.freenect.*;
import org.openkinect.processing.*;
import processing.core.PImage;
import processing.core.PVector;
//import processing.core.PImage;

public class Main extends PApplet {

    KinectTracker tracker;
    Kinect kinect;


    public void setup() {
        size(640, 520);
        kinect = new Kinect(this);
        tracker = new KinectTracker();
    }

    public void draw() {
        background(255);

        // Run the tracking analysis
        tracker.track();
        // Show the image
        tracker.display();

        // Let's draw the raw location
        PVector v1 = tracker.getPos();
        fill(50, 100, 250, 200);
        noStroke();
        ellipse(v1.x, v1.y, 20, 20);

        // Let's draw the "lerped" location
        PVector v2 = tracker.getLerpedPos();
        fill(100, 250, 50, 200);
        noStroke();
        ellipse(v2.x, v2.y, 20, 20);

        // Display some info
        int t = tracker.getThreshold();
        fill(0);
        text("threshold: " + t + "    " + "framerate: " + (frameRate) + "    " + "UP increase threshold, DOWN decrease threshold", 10, 500);
    }

    public void keyPressed() {
        int t = tracker.getThreshold();
        if (key == CODED) {
            if (keyCode == UP) {
                t += 5;
                tracker.setThreshold(t);
            } else if (keyCode == DOWN) {
                t -= 5;
                tracker.setThreshold(t);
            }
        }
    }
}
package lol.uk;

import org.openkinect.processing.Kinect;
import processing.core.*;
import processing.core.PImage;
import processing.core.PVector;

public class KinectTracker extends PApplet {
    // Depth threshold
    int threshold = 500;

    Kinect kinect;

    // Raw location
    PVector loc;

    // Interpolated location
    PVector lerpedLoc;

    // Depth data
    int[] depth;

    // What we'll show the user
    PImage display;

    KinectTracker() {
        // This is an awkard use of a global variable here
        // But doing it this way for simplicity
        kinect.initDepth();
        kinect.enableMirror(true);
        // Make a blank image
        display = createImage(kinect.width, kinect.height, RGB);
        // Set up the vectors
        loc = new PVector(0, 0);
        lerpedLoc = new PVector(0, 0);
    }

    public void track() {
        // Get the raw depth as array of integers
        depth = kinect.getRawDepth();

        // Being overly cautious here
        if (depth == null) return;

        float sumX = 0;
        float sumY = 0;
        float count = 0;

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

                int offset =  x + y*kinect.width;
                // Grabbing the raw depth
                int rawDepth = depth[offset];

                // Testing against threshold
                if (rawDepth < threshold) {
                    sumX += x;
                    sumY += y;
                    count++;
                }
            }
        }
        // As long as we found something
        if (count != 0) {
            loc = new PVector(sumX/count, sumY/count);
        }

        // Interpolating the location, doing it arbitrarily for now
        lerpedLoc.x = PApplet.lerp(lerpedLoc.x, loc.x, 0.3f);
        lerpedLoc.y = PApplet.lerp(lerpedLoc.y, loc.y, 0.3f);
    }

    PVector getLerpedPos() {
        return lerpedLoc;
    }

    PVector getPos() {
        return loc;
    }

    public void display() {
        PImage img = kinect.getDepthImage();

        // Being overly cautious here
        if (depth == null || img == null) return;

        // Going to rewrite the depth image to show which pixels are in threshold
        // A lot of this is redundant, but this is just for demonstration purposes
        display.loadPixels();
        for (int x = 0; x < kinect.width; x++) {
            for (int y = 0; y < kinect.height; y++) {

                int offset = x + y * kinect.width;
                // Raw depth
                int rawDepth = depth[offset];
                int pix = x + y * display.width;
                if (rawDepth < threshold) {
                    // A red color instead
                    display.pixels[pix] = color(150, 50, 50);
                } else {
                    display.pixels[pix] = img.pixels[offset];
                }
            }
        }
        display.updatePixels();

        // Draw the image
        image(display, 0, 0);
    }

    int getThreshold() {
        return threshold;
    }

    public void setThreshold(int t) {
        threshold =  t;
    }
}
包lol.uk;
导入org.openkinect.processing.Kinect;
进口加工。核心。*;
导入加工.core.PImage;
导入processing.core.PVector;
公共类KinectTracker扩展PApplet{
//深度阈值
int阈值=500;
Kinect-Kinect;
//原始位置
PVector-loc;
//插值定位
PVector lerpedLoc;
//深度数据
int[]深度;
//我们将向用户展示什么
图像显示;
KinectTracker(){
//这是一个全局变量的awkard用法
//但是这样做是为了简单
kinect.initDepth();
kinect.enableMirror(真);
//制作空白图像
显示=创建图像(kinect.width、kinect.height、RGB);
//设置向量
loc=新的PVector(0,0);
lerpedLoc=新PVector(0,0);
}
公共空间轨道(){
//以整数数组的形式获取原始深度
depth=kinect.getRawDepth();
//在这里过于谨慎
if(depth==null)返回;
浮点数sumX=0;
浮点数sumY=0;
浮点数=0;
对于(int x=0;x
PApplet需要几个参数才能启动。你提供了吗


请参阅本页以获取示例:

PApplet需要几个参数来启动。你提供了吗


请参阅本页以获取示例:

为什么有两个类扩展了
PApplet

99.99%的时候,您应该只有一个扩展了PApplet的类。然后将该类的实例传递给其他类,以便调用处理函数

除非您有很好的理由扩展
PApplet
两次,否则您应该只扩展一次

为什么没有
main()
方法?


如果您不是从Processing editor运行此命令,则需要编写自己的
main()
方法来启动代码。在
main()
方法中,您需要调用
PApplet.main(“YourSketchClassNameHere”)
函数来告诉Processing启动草图。

为什么有两个类扩展
PApplet

99.99%的时候,您应该只有一个扩展了PApplet的类。然后将该类的实例传递给其他类,以便调用处理函数

除非您有很好的理由扩展
PApplet
两次,否则您应该只扩展一次

为什么没有
main()
方法?


如果您不是从Processing editor运行此命令,则需要编写自己的
main()
方法来启动代码。在
main()
方法中,您需要调用
PApplet.main(“您的SketchClassNamehere”)
函数来告诉Processing启动您的草图。

我尝试过添加参数,但它似乎没有任何作用,您可以尝试在这方面添加参数吗?感谢you@chessefries不,当然我不能这样做,因为参数是特定于您执行程序的。你是如何添加参数的?我已经尝试添加参数,但似乎没有任何作用,你可以尝试添加参数吗?感谢you@chessefries不,当然我不能这样做,因为参数是特定于您执行程序的。你是如何添加参数的?