opencv3.3.1 with jdk 1.8 FaceDetect error
Code:
public Computer() {
System.out.println(Computer.class.getResource("haarcascade_frontalface_alt.xml").getPath().substring(1));
initComponents();
}
private DaemonThread myThread = null;
private VideoCapture webSource = null;
private final Mat frame = new Mat(1000, 1000, 1);
private final MatOfByte mem = new MatOfByte();
int count = 0;
CascadeClassifier faceDetector = new CascadeClassifier(Computer.class.getResource("haarcascade_frontalface_alt.xml").getPath().substring(1));
MatOfRect faceDetections = new MatOfRect();
private class DaemonThread implements Runnable {
protected volatile boolean runnable = false;
private JLabel display;
public DaemonThread(JLabel displayLabel) {
this.display = displayLabel;
}
@Override
public void run() {
synchronized (this) {
while (runnable) {
if (webSource.grab()) {
try {
webSource.retrieve(frame);
Graphics g = display.getGraphics();
//add
faceDetector.detectMultiScale(frame, faceDetections); //(Computer.java:73)
for (Rect rect : faceDetections.toArray()) {
// System.out.println("ttt");
Imgproc.rectangle(frame, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height),
new Scalar(0, 255,0));
}
//
Imgcodecs.imencode(".bmp", frame, mem);
Image im = ImageIO.read(new ByteArrayInputStream(mem.toArray()));
BufferedImage buff = (BufferedImage) im;// buff = display
//buff = display
if (g.drawImage(buff, 0, 0, getWidth(), getHeight()-150 , 0, 0, buff.getWidth(), buff.getHeight(), null)) {
if (runnable == false) {
System.out.println("Paused ..... ");
this.wait();
}
}
} catch (Exception e) {
System.out.println("Error!!");
e.printStackTrace();
}
}
}
}
}
}
I've only uploaded a portion of the code
I keep getting errors in making FaceDetect using opencv.
faceDetector.detectMultiScale(frame, faceDetections);
There's an error in this area.
CascadeClassifier faceDetector = new CascadeClassifier(Computer.class.getResource("haarcascade_frontalface_alt.xml").getPath().substring(1));
I revised this to solve it, but it didn't work.
I'm studying Java and opencv alone for the first time and I would appreciate it if you could help me!
Below is the sentence of error.
OpenCV Error: Assertion failed (!empty()) in cv::CascadeClassifier::detectMultiScale, file C:\build\master_winpack-bindings-win64-vc14-static\opencv\modules\objdetect\src\cascadedetect.cpp, line 1698 CvException [org.opencv.core.CvException: cv::Exception: C:\build\master_winpack-bindings-win64-vc14-static\opencv\modules\objdetect\src\cascadedetect.cpp:1698: error: (-215) !empty() in function cv::CascadeClassifier::detectMultiScale ] at org.opencv.objdetect.CascadeClassifier.detectMultiScale_1(Native Method) at org.opencv.objdetect.CascadeClassifier.detectMultiScale(CascadeClassifier.java:162) at test.Computer$DaemonThread.run(Computer.java:73) at java.lang.Thread.run(Thread.java:748)
U can't used arguement
faceDetections
inside perimeterfaceDetector.detectMultiScale(frame, faceDetections);
Thank you for your comment! So...
MatOfRect faceDetections = new MatOfRect();
this is the wrong part? If not, is that code all wrong?faceDetector.detectMultiScale(frame, faceDetections);
Is it impossible to modify this part to make the program possible?Apologized. I didn't see tag that u r using java.
No problem:D But there's another issue...
This issue arises. Can CPP be used in Java? Or is it another problem?
I don't know a thing because it's my first studying. I'm sorry to keep asking. And after that issue comes the same issue as before.