I have sone problem with size of sample traincascade. I use opencv_traincascade.exe to train rear of car. Size of rear of car which i need to have a size 72x48. Now i use createsample to create 2000 sample size 72x48 with command
D:\Project_Android\Classifier\bin\opencv_createsamples.exe -info positive.txt -bg negative.txt -vec vector.vec -num 2000 -w 72 -h 48
Now, i have a vector file and negative.txt (sure negative.txt have absolute direction to background images). i use opencv_traincascade.exe with command.
D:\Project_Android\Classifier\bin\opencv_traincascade.exe -data HaarTraining -vec vector.vec -bg negative.txt -numPos 250 -numNeg 1500 -numStages 10 -nonsym -minhitrate 0.999 -maxfalsealarm 0.5 -mode ALL -w 72 -h 48 -precalcValBufSize 2046 -precalcIdxBufSize 2046 PAUSE
I get an error.
When i use size 24x24 (-w 24 -h 24) for createsample.exe step and cascadetraining step, everything is ok, traincasecade is run.
it seem to be size 24x24 is a default size of sample and it still remain. and i seem to be cannot config it in file .bat (i write command in file bat and click file bat to run)
And one thing i see in command window in above picture that: -precalcValBufSize and -precalcIdxBufSize still remain default value 1024. No change with -w -h -precalcValBufSize -precalcIdxBufSize.
So what problem with it, i don't understand why don't i choose size of sample for train. I just can use size 24x24, all size other always give error "Assertion failed <_img.row*_img.height == vecSize> in CvcascadeImageReader...pla pla"
Please help me to solve this problem. So many thank to you
Related
I try to upload a video via the graph API but as the title states, I get an error that states that I use an unsupported video format.
I thought maybe the original video file doesn't match the video specifications as defined on https://developers.facebook.com/docs/instagram-api/reference/ig-user/media#video-specifications so I wrote a function to convert the file to match the specification, using ffmpeg with the following command (I tried many different ones, but this is the last one I tried)
ffmpeg -i ${tmpInFile} -vf format=yuv420p -vf scale=-2:720 -pix_fmt yuv420p -r 30 -movflags +faststart -c:v libx264 -b:v 3M -c:a aac -b:a 128k -ac 2 -ar 44100 -shortest -f mp4 ${tmpOutFile}
Unfortunately, the error persists.
Here's the complete process:
First I use await fetch('/api/convert-mp4', { method: 'POST', body: file }); to send the uploaded video file to the backend.
Next I get the blob data from the request with const blob = await request.blob();.
Then I create a temporary file with await fs.writeFile(tmpInFile, await blob.stream()).
Then I call ffmpeg with the above command mentioned above and then read the file with const buffer = await fs.readFile(tmpOutFile);.
Then I send the buffer as response body back to the client with return {status: 200,body: buffer}.
Then I get the blob data from the response with const blob = await convertVideoResponse.blob();.
Finally I convert it back into a file object with
const convertedFile = new File([blob], file.name, { type: 'video/mp4' });
This file I upload to Supabase Storage (https://supabase.com/storage), and get a publicly accessible url (which I confirmed by opening it in an incognito tab).
In the supabase dashboard I can see the video file has the correct media container (video/mp4) and the file size is small enough.
Does anyone have an idea what could be the issue?
Edit:
By changing the ffmpeg command to use h265 instead of h254 ffmpeg -i ${tmpInFile} -vf format=yuv420p -vf scale=-2:1350 -pix_fmt yuv420p -r 30 -movflags +faststart -c:v libx265 -vtag hvc1 -an -x265-params crf=25 -b:v 3M -c:a copy -c:a aac -b:a 128k -ac 2 -ar 44100 -shortest -f mp4 ${tmpOutFile} I managed to get it to work for some videos but not all, which confuses me, as I assumed that the video attributes should be the same for all videos processed by the same command.
I had the very same issue, and GOT IT TO WORK!
TL;DR
Make sure your video is not too long
More details
In the end I came up with this as an example:
ffmpeg -i input.mp4 \
-c:v libx264 -aspect 16:9 -crf 18 \
-vf "scale=iw*min(1280/iw\,720/ih):ih*min(1280/iw\,720/ih),pad=1280:720:(1280-iw)/2:(720-ih)/2" \
-fpsmax 60 -preset ultrafast -c:a aac -b:a 128k -ac 1 -pix_fmt yuv420p -movflags +faststart -t 59 -y output.mp4
On some flags some details about what and why:
-c:v libx264 → You need to compress with Video codec: HEVC or H264, progressive scan, closed GOP, 4:2:0 chroma subsampling
--aspect and -vf "scale=iw*min(1280/iw\,720/ih):ih*min(1280/iw\,720/ih),pad=1280:720:(1280-iw)/2:(720-ih)/2" → As I want my video's always to be within 1280x720, padding added if needed.
fpsmax → Make sure you do not exceed the framerate of 60fps
-c:a aac -b:a 128k -ac 1 → For "AAC, 48khz sample rate maximum, 1 or 2 channels (mono or stereo)"
-t 59 → Limit to under 1 minute, as that is the max for a video!
I think the most important thing here is the -t 59 as the API only supports files up to one minute!
After this, everything worked 🎉
I'm trying to train some branch logos with haar_cascade. What I've done is, I've taken 2500 squared pictures of 500 x 500 to populate the samples for opencv_createsamples. Then I generate them as:
opencv_createsamples -info 'logo.info' -vec '../logo.vec' -bg '../Negatives/bg.txt' -w 24 -h 24 -num 2500
in my logo.info I've got lines which correspond to the relative path of every picture, with a 1 0 0 500 500 meaning "there's one object between (0,0) and (500, 500)"
then I train the cascade as:
opencv_traincascade -data 'cascade/' -vec '../logo.vec' -bg '../Negatives/bg.txt' -numPos 2500 -numNeg 3019 -numStages 25 -featureType LBP -w 24 -h 24
with these parameters:
PARAMETERS:
cascadeDirName: cascade/
vecFileName: ../logo.vec
bgFileName: ../Negatives/bg.txt
numPos: 2500
numNeg: 3019
numStages: 25
precalcValBufSize[Mb] : 256
precalcIdxBufSize[Mb] : 256
stageType: BOOST
featureType: LBP
sampleWidth: 24
sampleHeight: 24
boostType: GAB
minHitRate: 0.995
maxFalseAlarmRate: 0.5
weightTrimRate: 0.95
maxDepth: 1
maxWeakCount: 100
And I've got 2 kind of errors:
OpenCV Error: One of arguments' values is out of range (No components/input_variables is selected!) in cvPreprocessIndexArray, file /tmp/buildd/opencv-2.3.1/modules/ml/src/inner_functions.cpp, line 432
terminate called after throwing an instance of 'cv::Exception'
what(): /tmp/buildd/opencv-2.3.1/modules/ml/src/inner_functions.cpp:432: error: (-211) No components/input_variables is selected! in function cvPreprocessIndexArray
...
this errors uses to happen when you don't give a significant difference between your num of images and your -num parameter. So, let's try to give less 100!!
well, when I've adjusted the parameters to not to go out from the array, I get the same type of output than images, but I get this error:
OpenCV Error: Assertion failed (tempNode->left) in write, file /tmp/buildd/opencv-2.3.1/modules/traincascade/boost.cpp, line 628
terminate called after throwing an instance of 'cv::Exception'
what(): /tmp/buildd/opencv-2.3.1/modules/traincascade/boost.cpp:628: error: (-215) tempNode->left in function write
Aborted
I've tried:
Changing the destiny size of the images (24x24, 36x36...)
Changing the -mode parameter.
Trying to put a #positiveSamples < #negativeSamples and #positiveSamples > #negativeSamples
What I have to do, is training obligatory with LBP (not HAAR). Do anyone have any clue?
Thank you in advance.
Uninstalling and rebuilding OpenCV solved the problem.
I am trying to use the textcleaner script for cleaning up real life images that I am using with OCR. The issue I am having is that the images sent to me are rather large sometimes. (3.5mb - 5mb 12MP pics) The command I run with textcleaner ( textcleaner -g -e none -f <int # 10 - 100> -o 5 result1.jpg out1.jpg ) takes about 10 seconds at -f 10 and minutes or more on a -f 100.
To get around this I tried using ImageMagick to compress the image so it was much smaller. Using convert -strip -interlace Plane -gaussian-blur 0.05 -quality 50% main.jpg result1.jpg I was able to take a 3.5mb and convert it almost loss-lessly to ~400kb. However when I run textcleaner on this new file it STILL acts like its a 3.5mb file. (Times are almost exactly the same). I have tested these textcleaner settings against a file NOT compressed #400kb and it is almost instant while -f 100 takes about 12 seconds.
I am about out of ideas. I would like to follow the example here as I am in almost exactly the same situation. However, at the current speed of transformation an entire OCR process could take over 10 minutes when I need this to be around 30 seconds.
I have 30 positive images and 60 negatives images.
When I tried to execute the haartraining with 4GB of memory and Quadcore processor machine, I get this error message:
OpenCV ERROR: Insufficient memory (Out of memory)
in function cvAlloc, cxalloc.cpp(111)
Terminating the application...
called from cvUnregisterType, cxpersistence.cpp(4933)
The command is:
./opencv-haartraining -vec vector/myvector.vec -bg negatives.txt -npos 24 -nneg 55 -mem 2048 -mode ALL -w 86 -h 150
The computer has only 765 MB used, but the process exceeds the given limit, and uses a lot of memory in swap until the overflow occurs. Any suggestions of what can be done to solve this problem?
Regards
Maybe your "myvector.vec" is too big. All these pictures are loaded to RAM.
Try to resize the images.
I am trying to get rrdtool working to plot ifInOctets.
I created the database using:
rrdtool create bandwidth.rrd --start N DS:in:COUNTER:60:U:U RRA:AVERAGE:0.5:1:432
Once a minute I run:
/usr/bin/rrdupdate /srv/www/htdocs/rrdtool/bandwidth.rrd N:`/usr/bin/snmpget -v 2c -Oqv -c secret 192.168.1.1 ifInOctets.2`
If I run
/usr/bin/snmpget -v 2c -Oqv -c secret 192.168.1.1 ifInOctets.2
it is returning the correct result.
I then create the rrd graph using:
/usr/bin/rrdtool graph /srv/www/htdocs/mrtg/bandwidth.png -a PNG -w 785 -h 120 -s -129600 -v "Data Throughput" \
'DEF:in=/srv/www/htdocs/rrdtool/bandwidth.rrd:in:AVERAGE' \
'CDEF:kbin=in,1024,/' \
'AREA:in#00FF00:Bandwidth In' \
'GPRINT:kbin:LAST:Last Bandwidth In\: %3.2lf KBps' \
'GPRINT:kbin:AVERAGE:Average Bandwidth In\: %3.2lf KBps'
Is there something obvious I am missing?
If you are collecting the data every minute, then you need to set the RRD step to be 60s (the default is 300s) using --step=60
Also, you have the Heartbeat for the 'in' DS set to 60. Normally, you should set this to be twice the step size, else you need to update every 59 seconds... What is happening is that the updates are happening every 60s which is the heartbeat time, and so most are being set to unknown.
Change the heartbeat to 120 and the step to 60, and it should work:
rrdtool create bandwidth.rrd --step 60 --start N DS:in:COUNTER:120:U:U RRA:AVERAGE:0.5:1:432