0
我正在使用Processing(processing.org)处理需要面部跟踪的项目。现在的问题是,由于for循环,程序将耗尽内存。我想停止循环或至少解决内存不足的问题。这是代码。如何停止for循环(OpenCV)
import hypermedia.video.*;
import java.awt.Rectangle;
OpenCV opencv;
// contrast/brightness values
int contrast_value = 0;
int brightness_value = 0;
void setup() {
size(900, 600);
opencv = new OpenCV(this);
opencv.capture(width, height); // open video stream
opencv.cascade(OpenCV.CASCADE_FRONTALFACE_ALT); // load detection description, here-> front face detection : "haarcascade_frontalface_alt.xml"
// print usage
println("Drag mouse on X-axis inside this sketch window to change contrast");
println("Drag mouse on Y-axis inside this sketch window to change brightness");
}
public void stop() {
opencv.stop();
super.stop();
}
void draw() {
// grab a new frame
// and convert to gray
opencv.read();
opencv.convert(GRAY);
opencv.contrast(contrast_value);
opencv.brightness(brightness_value);
// proceed detection
Rectangle[] faces = opencv.detect(1.2, 2, OpenCV.HAAR_DO_CANNY_PRUNING, 40, 40);
// display the image
image(opencv.image(), 0, 0);
// draw face area(s)
noFill();
stroke(255,0,0);
for(int i=0; i<faces.length; i++) {
rect(faces[i].x, faces[i].y, faces[i].width, faces[i].height);
}
}
void mouseDragged() {
contrast_value = (int) map(mouseX, 0, width, -128, 128);
brightness_value = (int) map(mouseY, 0, width, -128, 128);
}
谢谢!
Wheres the for loop? – 2013-04-24 12:50:18
为什么当你想停止循环?对于(int i = 0; i
Alexey
2013-04-24 13:26:39
; } 这是循环。我想要停止它,或者释放先前所用的内存,因为如果它继续存在,我将耗尽存储空间。然后它会在20秒后显示一个MemoryError。 – user1927992 2013-04-24 15:12:37