no .vec files after createsamples OpenCV - Haar Training - c++

i need your help :) today i trained possitive image and negative image for HAAR detection. I followed this command below :
opencv_traincascade -data classifier -vec samples.vec -bg negatives.txt\ -numStages 20 -minHitRate 0.999 -maxFalseAlarmRate 0.5 -numPos 1000\ -numNeg 600 -w 80 -h 40 -mode ALL -precalcValBufSize 1024\ -precalcIdxBufSize 1024
(from CodingRobin) on my terminal, it seems "Done".
But there's no .vec files in samples directory. Can anyone help me ??

opencv_traincascade.exe USES the vec file. You must call the opencv_createsamples.exe instead.
The command line should look like:
opencv_createsamples.exe -info positives.txt -vec samples.vec -w 24 -h 24 -num 4455
for your number of samples and width/height
positives.txt should look like (each line):
#path #numberOfObjects #xObj1 #yObj1 #widthObj1 #heightObj1 #xObj2 #...
for example:
image1.png 1 0 0 84 84
image2.jpg 1 100 130 128 128
image3.png 2 10 30 50 50 300 100 101 101
etc.
After that you can train by calling opencv_traincascade with your parameter list and you'll get a .xml file as result.

Related

Compress gifs with vips on the command line

I try to use libvips to compress my gifs, but I can't find the relevant documentation
# vips --version
vips-8.12.2-Tue Jan 25 09:34:32 UTC 2022
This gif is very big, I want to try to compress it with vips
# ls -ahl *.gif
-rw-r--r--. 1 root root 34M 7月 4 10:25 a.gif

Opencv Train Cascade error

I am trying to train a haar cascade using opencv_traincascade executable in opencv 3.1.0.
For the moment I want to do this using only one positive even though the result is inconsistent, in order to be sure that I am passing the right parameters to opencv_createsamples and opencv_traincascade.
bg.txt content:
negatives/img_04436_c1.pgm
negatives/img_04437_c1.pgm
Negatives resolution: width: 1176 height: 640
Positives resolution: width: 40 height: 70
I am using the following command parameters:
For opencv_createsamples:
./opencv_createsamples -img img_04569_c1.pgm -vec samples -bg bg.txt -maxxangle 0.1 -maxyangle 0.1 -maxzangle 0.1 -w 40 -h 70 -num 30
Info file name: (NULL)
Img file name: img_04569_c1.pgm
Vec file name: samples.vec
BG file name: bg.txt
Num: 30
BG color: 0
BG threshold: 80
Invert: FALSE
Max intensity deviation: 40
Max x angle: 0.1
Max y angle: 0.1
Max z angle: 0.1
Show samples: FALSE
Width: 40
Height: 70
Create training samples from single image applying distortions...
Open background image: negatives/img_04436_c1.pgm
Done
For opencv_traincascade:
./opencv_traincascade -data cascade -vec samples -bg bg.txt -w 40 -h 70 -numPos 30 -numStages 1 -numNeg 2
PARAMETERS:
cascadeDirName: cascade
vecFileName: samples.vec
bgFileName: bg.txt
numPos: 30
numNeg: 2
numStages: 2
precalcValBufSize[Mb] : 1024
precalcIdxBufSize[Mb] : 1024
acceptanceRatioBreakValue : -1
stageType: BOOST
featureType: HAAR
sampleWidth: 40
sampleHeight: 70
boostType: GAB
minHitRate: 0.995
maxFalseAlarmRate: 0.5
weightTrimRate: 0.95
maxDepth: 1
maxWeakCount: 100
mode: BASIC
===== TRAINING 0-stage =====
<BEGIN
POS count : consumed 28 : 28
*** Error in `./opencv_traincascade': double free or corruption (out): 0x00000000016749b0 ***
Aborted (core dumped)
My problem is the following:
I am able to create the sample.vec file.
When I run opencv_traincascade I get the following error:
*** Error in `./opencv_traincascade': double free or corruption (out): 0x0000000001e0e9b0 ***
Sometimes I also get a Segmentation Fault error.
I tried to resize the negatives to a lower resolution and I am able to generate the xml file but when I am trying to use it nothing happens. (the classifier is stucked and runs continuously without returning any rectangles)
I want to use my original negatives size.
Can anybody help me to solve this problem ?
If more details are required please leave a comment and I will update my question.

rsync running differently from QProcess compared to bash command line

I am experimenting with launching rsync from QProcess and although it runs, it behaves differently when run from QProcess compared to running the exact same command from the command line.
Here is the command and stdout when run from QProcess
/usr/bin/rsync -atv --stats --progress --port=873 --compress-level=9 --recursive --delete --exclude="/etc/*.conf" --exclude="A*" rsync://myhost.com/haast/tmp/mysync/* /tmp/mysync/
receiving incremental file list
created directory /tmp/mysync
A
0 100% 0.00kB/s 0:00:00 (xfer#1, to-check=6/7)
B
0 100% 0.00kB/s 0:00:00 (xfer#2, to-check=5/7)
test.conf
0 100% 0.00kB/s 0:00:00 (xfer#3, to-check=4/7)
subdir/
subdir/A2
0 100% 0.00kB/s 0:00:00 (xfer#4, to-check=2/7)
subdir/C
0 100% 0.00kB/s 0:00:00 (xfer#5, to-check=1/7)
subdir/D
0 100% 0.00kB/s 0:00:00 (xfer#6, to-check=0/7)
Number of files: 7
Number of files transferred: 6
Total file size: 0 bytes
Total transferred file size: 0 bytes
Literal data: 0 bytes
Matched data: 0 bytes
File list size: 105
File list generation time: 0.001 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 174
Total bytes received: 367
sent 174 bytes received 367 bytes 360.67 bytes/sec
total size is 0 speedup is 0.00
Notice that although I excluded 'A*', it still copied them! Now running the exact same command from the command line:
/usr/bin/rsync -atv --stats --progress --port=873 --compress-level=9 --recursive --delete --exclude="/etc/*.conf" --exclude="A*" rsync://myhost.com/haast/tmp/mysync/* /tmp/mysync/
receiving incremental file list
created directory /tmp/mysync
B
0 100% 0.00kB/s 0:00:00 (xfer#1, to-check=4/5)
test.conf
0 100% 0.00kB/s 0:00:00 (xfer#2, to-check=3/5)
subdir/
subdir/C
0 100% 0.00kB/s 0:00:00 (xfer#3, to-check=1/5)
subdir/D
0 100% 0.00kB/s 0:00:00 (xfer#4, to-check=0/5)
Number of files: 5
Number of files transferred: 4
Total file size: 0 bytes
Total transferred file size: 0 bytes
Literal data: 0 bytes
Matched data: 0 bytes
File list size: 83
File list generation time: 0.001 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 132
Total bytes received: 273
sent 132 bytes received 273 bytes 270.00 bytes/sec
total size is 0 speedup is 0.00
Notice that now the 'A*' exclude is respected! Can someone explain why they are performing differently?
A noticed that if I removed the quotes surrounding the excludes, then the QProcess run performs correctly.
In your command-line execution, bash interpreter performs a previous substitution and remove quotes, so they are not passed to rsync arg list.
Next script shows how bash substitution is performed:
[tmp]$ cat printargs.sh
#!/bin/bash
echo $*
[tmp]$ ./printargs.sh --exclude="A*"
--exclude=A*

Error while creating haar Classifier using OpenCV in Ubuntu 14.04

I'm refererring http://abhishek4273.wordpress.com/2014/02/10/opencv-haar-training/ to create the Haar Classifier in OpenCV, I have got the error in,
$ perl createtrainsamples.pl positives.txt negatives.txt samples 200 "opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 20 -h 20"
opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 20 -h 20 -img ./pos/5.jpg -bg tmp -vec samples/5.jpg.vec -num 40
Info file name: (NULL)
Img file name: ./pos/5.jpg
Vec file name: samples/5.jpg.vec
BG file name: tmp
Num: 40
BG color: 0
BG threshold: 0
Invert: FALSE
Max intensity deviation: 40
Max x angle: 1.1
Max y angle: 1.1
Max z angle: 0.5
Show samples: FALSE
Width: 20
Height: 20
Create training samples from single image applying distortions...
OpenCV Error: Bad argument (Quadrangle is nonconvex or degenerated.) in cvWarpPerspective, file /home/project/OpenCV/opencv-2.4.9/apps/haartraining/cvsamples.cpp, line 217
terminate called after throwing an instance of 'cv::Exception'
what(): /home/project/OpenCV/opencv-2.4.9/apps/haartraining/cvsamples.cpp:217: error: (-5) Quadrangle is nonconvex or degenerated. in function cvWarpPerspective
Above error generated for all the samples in positive folder.
Eventhough it generates error, it has created 8 samples.jpg.vec files in the samples folder.
Actually i have passed 200 as my samples, but it is creating only 8 of those in samples folder and throwing above error, and if try to merge using,
$./mergevec samples.txt samples.vec
It shows following error,
OpenCV Error: Assertion failed (elements_read == 1) in icvGetHaarTraininDataFromVecCallback, file cvhaartraining.cpp, line 1859
terminate called after throwing an instance of 'cv::Exception'
what(): cvhaartraining.cpp:1859: error: (-215) elements_read == 1 in function icvGetHaarTraininDataFromVecCallback
Aborted (core dumped)
If any one knows the answer for the following please do post it.

opencv_traincascade.Unspecified error (No element name has been given)

I'm trying to train my own cascade, but get the following error:
Unspecified error (No element name has been given) in cv::operator
<<, file C:\builds\2_4_PackSlave-win64-vc11-shared\opencv\modules\core\include\
opencv2/core/operations.hpp, line 2910
I made ​​these steps:
I cut 20 photos of the object so that they remained only the desired object
Resize to 30x18
Make objectSamples.dat file like this :
object(1).jpg 1 0 0 30 18
object(10).jpg 1 0 0 30 18
object(11).jpg 1 0 0 30 18
And negatives.dat like :
negatives\1.jpeg
negatives\10.jpg
negatives\11.jpg
size of pic ~ 500x500
4.Make vec file:
opencv_createsamples -info objectSamples.dat -vec objectSamples.vec -w 30 -h 18 -num 20
5.Show samples ( my pictures are shown entirely) : opencv_createsamples -vec objectSamples.vec -w 30 -h 18
6.Try to train : opencv_traincascade -data Cascade -vec objectSamples.vec -bg negatives.dat -numPos 10 -numNeg 10 -numStages 2 -featureType HAAR -w 30 -h 18
But get an error:
What am I doing wrong?
I read these articles and the answer, but I didn't understand, in what a problem:
trouble-when-use-opencv_traincascadeexe
haartraining tutorial
docs.opencv traincascade
Increased the number of images to 1000 positive and 2000 negatives
opencv_traincascade -data Cascade -vec boobsSamples.vec -bg negativesBig/negatives.txt -numPos 400 -numNeg 1000 -numStages 2 -featureType HAAR -w 30 -h 18 -mode ALL
Geting the same error.
Problem solved!
I copied the opencv_traincascade.exe to a folder of images. When I ordered the full path to the opencv_traincascade.exe in the library, the problem disappeared.
F:\OpenCV\opencv\build\x64\vc11\bin\opencv_traincascade -data Cascade -vec positives.vec -bg negativesBig/negatives.txt -numPos 400 -numNeg 1000 -numStages 2 -featureType HAAR -w 30 -h 18 -mode ALL