gpt4 book ai didi

java - IntelliJ 上的 PApplet 错误

转载 作者:太空宇宙 更新时间:2023-11-04 12:42:33 25 4
gpt4 key购买 nike

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

Usage: PApplet [options] [sketch args] See the Javadoc for PApplet for an explanation.

这是我正在使用的两个类。

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);
}
}
}
}

KinectTracker.java

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;
}
}

最佳答案

PApplet 需要几个参数才能启动。你提供这些了吗?

请参阅此页面的示例:https://processing.org/tutorials/eclipse/

关于java - IntelliJ 上的 PApplet 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36691232/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com