I'm working on a OpenCV java project that detects wire container rigid from an image. I'm pretty new into customizing Haar Cascade Classifier by using Cascade Trainer GUI tool. I added 50 photos of wire container rigid only in the p folder and 200 other photos in the n folder. After generating the Haar Cascade Classifier XML file, I ran the java code using the xml file and it's not detecting the wire container on an image. I tested using the Haar Cascade Classifier xml file for face detection and it works but not for wire containers. Am I doing something wrong? Please insist.
here is a sample photo of a wire container that i'm trying to detect.
And here is my code that i used.
public class DetectContainerDemo {
public static void main(String[] args) {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
System.out.println("\nRunning Detect containers Demo");
CascadeClassifier contDetector = new CascadeClassifier("data_files//cascade.xml");
Mat image = Imgcodecs.imread("target//testcont2.jpg");
// Detect Container in the image.
// MatOfRect is a special container class for Rect.
MatOfRect contDetections = new MatOfRect();
contDetector.detectMultiScale(image, contDetections);
System.out.println(String.format("Detected %s containers", contDetections.toArray().length));
// Draw a bounding box around the container.
for (Rect rect : contDetections.toArray()) {
Imgproc.rectangle(image, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height), new Scalar(0, 255, 0));
}
BufferedImage meh = (BufferedImage) HighGui.toBufferedImage(image);
//HighGui.toBufferedImage(m)
File output = new File("target\\test1.png");
try {
ImageIO.write(meh, "png", output);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Please let me know if this is feasible or am I doing it wrong. the code above pretty much loads the xml file and detect an object using the detectMultiScale method from Opencv library.