I'm trying to create my haar cascade for screw recognition. I create with the help of utilities from the folder opencv320. I use 700 positive and 1400 negative images. Creation ends before the 16th stage: "the required limit of the acceptance ratio has been reached." I'm trying to use a cascade, but the screws are not recognized. Command to create samples.vec File:
C:\opencv320\opencv\build\x64\vc14\bin>opencv_createsamples.exe -info D:\TrainingSample\Good.dat -vec D:\TrainingSample\samples.vec -w 40 -h 20 -num 702
Command to create a classifier:
C:\opencv320\opencv\build\x64\vc14\bin>opencv_traincascade.exe -data haarcascade -vec samples.vec -bg Bad.dat -numStages 16 -minhitrate 0.999 -maxFalseAlarmRate 0.4 -numPos 561 -numNeg 1403 -w 40 -h 20 -mode ALL -precalcValBufSize 2048 -precalcIdxBufSize 2048
Code to use the cascade:
MyApp.screw_cascade.detectMultiScale(gray, screw, 1.1, 2, 0, new Size(40, 20), new Size());
for (Rect rect : screw.toArray()) {
//Core.rectangle(frame, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height), new Scalar(0, 255, 0));
Point center = new Point(rect.x + rect.width * 0.5, rect.y + rect.height * 0.5);
Core.ellipse(frame, center, new Size(rect.width * 0.5, rect.height * 0.5), 0, 0, 360, new Scalar(0, 255, 0), 4, 8, 0);
Core.putText(frame, "Screw", new Point(rect.x, rect.y), Core.FONT_HERSHEY_PLAIN, 1.0, new Scalar(0, 255, 255));
}
What am I doing wrong? Can you advise something that can help me?
All the commands I used for training I pointed out at the beginning. Additionally, I uploaded all the files used for training, including all photos, to Google drive. For training, I took images of objects without a background (*.png), superimposed them on the background, cut out the site with the object, the position of the object on the image was recorded in a file Good.dat.
The result of attempts for several days: it was possible to create a cascade for detecting nuts with virtually no gaps. To create, we used 40 images of the nut at different angles without background, which were superimposed on the fragments of each of the backgrounds (25 background pictures). A total of 2100 positive and 4000+ negative. To create a file, use the command:
opencv_createsamples.exe -info D:\TrainingSample\Good.dat -vec D:\TrainingSample\samples.vec -maxxangle 1.1 -maxyangle 1.1 -maxzangle 0.5 -w 20 -h 20 -num 2099
To create a cascade, the command was used:
opencv_traincascade.exe -data haarcascade -vec samples.vec -bg Bad.dat -numStages 12 -minhitrate 0.999 -maxFalseAlarmRate 0.3 -numPos 1680 -numNeg 4049 -w 20 -h 20 -mode ALL -precalcValBufSize 2048 -precalcIdxBufSize 2048
The training took 10 hours.