我在使用 opencv_traincascade
时遇到了一些问题,这可能会追溯到早期的方法调用,但我不是 100% 确定。
opencv_traincascade -data classifier -vec samples.vec -bg
negatives.txt -numStages 20 -minHitRate - 0.999 -maxFalseAlarmRate 0.5
-numPos 4000 -numNeg 200000 -w 17 -h 23 -mode ALL
-precalcValBufSize 1024 -precalcIdxBufSize 1024
error:
terminate called after throwing an instance of 'std::logic_error'
what(): basic_string::_M_construct null not valid
Aborted (core dumped)
我正在关注这个 tutorial .但是,我有 5000 张正面图像和 200000 张负面图像可供处理。所以,相反,我遵循了这个 link我正在使用该方法从一些图像中创建训练样本,而不是扭曲单个图像。
创建示例:
opencv_createsamples -info positives.dat -vec samples.vec -w 17 -h 23
-num 5000
Output:
Info file name: positives.dat
Img file name: (NULL)
Vec file name: samples.vec
BG file name: (NULL)
Num: 5000
BG color: 0
BG threshold: 80
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: 17
Height: 23
Max Scale: -1
我已经通过 vec 文件查看了示例图像
opencv_createsamples -vec samples.vec -w 17 -h 23
如果需要,部分捕获 positives.dat
positive_images/0/18693.png 1 0 0 17 23
positive_images/0/18501.png 1 0 0 17 23
positive_images/0/19998.png 1 0 0 17 23
positive_images/0/18224.png 1 0 0 17 23
positive_images/0/19527.png 1 0 0 17 23
positive_images/0/18739.png 1 0 0 17 23
positive_images/0/6926.png 1 0 0 17 23
positive_images/0/19520.png 1 0 0 17 23
positive_images/0/7982.png 1 0 0 17 23
positive_images/0/17458.png 1 0 0 17 23
positive_images/0/17312.png 1 0 0 17 23
positive_images/0/8497.png 1 0 0 17 23
我在 Stack Overflow 上搜索了一些不同的帖子,但问题与我的略有不同。
我将我的 Windows 机器转移到运行最新的 Ubuntu lts 发行版的双引导。
最佳答案
我的问题解决了!我错误地创建了我的 negatives.dat 文件,所以 1 个问题是找不到负片文件。我还使用 opencv_traincascade
实现重新运行 here .仅调整样本量和图像的宽度和高度。
来自链接的代码
opencv_traincascade -data classifier -vec samples.vec -bg negatives.txt\
-numStages 20 -minHitRate 0.999 -maxFalseAlarmRate 0.5 -numPos 4500\
-numNeg 600 -w 17 -h 23 -mode ALL -precalcValBufSize 1024\
-precalcIdxBufSize 1024
当我输入这个时,我刚刚弹出一条消息说
Required leaf false alarm rate achieved. Branch training terminated.
是时候弄清楚了。哦,这不是错误,它说它按照我的要求做了。是时候对此进行测试了。
关于python-3.x - 如何运行 opencv_traincascade?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51970297/