请从opencv_share@163.com 密码:download 下载完整格式的文档与代码。
使用harrTraining进行电池的识别实验
by hardy
http://blog.csdn.net/hardvb
提取训练数据
在OpenCV_ObjectDetection_HowTo.pdf 提到的objectmaker.exe,实际中没有找到,只好
自己写了一个。
该小程序完成从摄像头中选定小图像的功能。
使用方法:
使用m按键切换模式
然后按键s 使画面暂停,
用鼠标点击移动选取检测物体的位置。
再按s按键存储数据。
数据提取模式分别为
• 创建正向训练数据,
• 创建背景图像
• 创建测试数据
其中正向训练数据在目录posdata/sample.txt下,格式为:
1100.bmp 3 20 80 21 58 142 69 18 58 255 94 22 74
1243.bmp 3 17 78 27 62 142 68 19 61 251 94 25 77
1470.bmp 3 16 88 32 72 137 83 23 74 273 100 28 79
背景图像为抓取图像,在目录negdata/sample.txt下,格式为:
01NFW-Large.bmp
01NFW-Small.bmp
02Block-Large.bmp
(这里的背景图像也可以从硬盘中文件中搜索的,大小可以与正向训练数据不同)
其中测试训练数据在目录testdata/sample.txt下,格式为:
1100.bmp 3 20 80 21 58 142 69 18 58 255 94 22 74
与正向训练数据一样。
新的objectmaker.exe 代码如下:
#include "stdafx.h"
#include <iostream>
#include <string.h>
#include <cxcore.h>
#include <cv.h>
#include <highgui.h>
#include <fstream>
IplImage *image = 0,*image_show = 0, *grey = 0, *prev_grey = 0;
struct PicRECT
{
PicRECT(){count=0;IsDrawing= false;IsStop=false;mode= 0;}
CvRect *prect()
{
return &rect[count];
}
CvRect rect[100];