我正在玩OpenCV Java,我决定看看是否可以通过运行detectMultiScale3函数输出OpenCV的CascadeClassifier返回的置信度值。我的代码如下:
//...
if (this.capture.isOpened())
{
this.cameraActive = true;
// grab a frame every 33 ms (30 frames/sec)
Runnable frameGrabber = new Runnable() {
@Override
public void run()
{
// run a couple of iterations before you process the faces
for(int i = 0; i < 3; i++) {
// effectively grab and process a single frame
Mat frame = grabFrame();
MatOfInt rl = new MatOfInt();
MatOfDouble lw = new MatOfDouble();
if(i == 0) {
classifier.detectMultiScale3(frame, faces, rl, lw);
eyeclass.detectMultiScale(frame, eyes);
}
for(Rect rect : faces.toArray()) {
Imgproc.rectangle(
frame,
new Point(rect.x, rect.y),
new Point(rect.x + rect.width, rect.y + rect.height),
new Scalar(255, 0, 0),
5
);
// String print = Double.toString(values[i]);
// Imgproc.putText(frame, print, new Point(rect.x, rect.y), 0, 0.5, new Scalar(255, 255, 255));
}
for(Rect rect : eyes.toArray()) {
Imgproc.rectangle(
frame,
new Point(rect.x, rect.y),
new Point(rect.x + rect.width, rect.y + rect.height),
new Scalar(0, 0, 255),
2
);
}
// convert and show the frame
Image imageToShow = mat2Image(frame);
updateImageView(currentFrame, imageToShow);
}
}
};
this.timer = Executors.newSingleThreadScheduledExecutor();
this.timer.scheduleAtFixedRate(frameGrabber, 0, 99, TimeUnit.MILLISECONDS);
// update the button content
this.button.setText("Stop Camera");
}
每当我仅用detectMultiScale3
替换detectMultiScale
函数时,该程序便会运行,但是每当我使用detectMultiScale3
时,该程序就会特别挂在该函数上。为什么有任何原因,还是我只是错误地使用了此功能?