OpenCV3.9训练级联分类器的代码
时间: 2024-05-12 12:15:42 浏览: 15
以下是使用OpenCV3.9训练级联分类器的代码:
1. 准备正样本和负样本图像,并将其存储在不同的文件夹中。
2. 创建一个文本文件,其中包含所有正样本图像的文件名和路径。
```
positive_images/file1.jpg
positive_images/file2.jpg
...
```
3. 创建一个文本文件,其中包含所有负样本图像的文件名和路径。
```
negative_images/file1.jpg
negative_images/file2.jpg
...
```
4. 使用opencv_createsamples命令创建正样本和负样本的vec文件。
```
opencv_createsamples -info positive_images.txt -vec positive_samples.vec -w 24 -h 24
opencv_createsamples -info negative_images.txt -vec negative_samples.vec -w 24 -h 24
```
5. 使用opencv_traincascade命令训练级联分类器。
```
opencv_traincascade -data classifier -vec positive_samples.vec -bg negative_images.txt -numPos 500 -numNeg 500 -numStages 10 -w 24 -h 24
```
这将在当前目录下创建一个名为“classifier”的文件夹,其中包含训练好的级联分类器文件。您可以将其用于检测新图像中的对象。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)