正样本2343,负样本5883,直接计算等价模式LBP特征图,再使用SVM训练一个分类器。
CvTermCriteria criteria = cvTermCriteria(CV_TERMCRIT_ITER, 1000, FLT_EPSILON);
CvSVMParams param(CvSVM::C_SVC, CvSVM::LINEAR, 0, 0.5, 0, 0.01, 0, 0, 0, criteria);
GaussianBlur(inputImg, inputImg, Size(3,3), 0);
结论:加入高斯滤波,由于可去除噪声干扰;车道线检出率提高,多检率降低。
// LBP特征的实现及LBP+SVM分类 https://blog.csdn.net/qianqing13579/article/details/49406563
// 计算等价模式LBP特征图,为了方便表示特征图,58种等价模式表示为1~58,第59种混合模式表示为0
static void ComputeLBPImage_Uniform(const Mat &srcImage, Mat &LBPImage)
{
// 参数检查,内存分配
CV_Assert(srcImage.depth() == CV_8U&&srcImage.channels() == 1);
LBPImage.create(srcImage.size(), srcImage.type());
// 计算LBP图
// 扩充原图像边界,便于边界处理
Mat extendedImage;
copyMakeBorder(srcImage, extendedImage, 1, 1, 1, 1, BORDER_DEFAULT);
// 构建LBP 等价模式查找表
//int table[256];
//BuildUniformPatternTable(table);
// LUT(256种每一种模式对应的等价模式)
static const int table[256] = { 1, 2, 3, 4, 5, 0, 6, 7, 8, 0, 0, 0, 9, 0, 10, 11, 12, 0, 0, 0, 0, 0, 0, 0, 13, 0, 0, 0, 14, 0, 15, 16, 17, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 0, 0, 0, 0, 19, 0, 0, 0, 20, 0, 21, 22, 23, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
0, 0, 0, 0, 0, 0, 0, 26, 0, 0, 0, 27, 0, 28, 29, 30, 31, 0, 32, 0, 0, 0, 33, 0, 0, 0, 0, 0, 0, 0, 34, 0, 0, 0, 0
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 35, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 36, 37, 38, 0, 39, 0, 0, 0, 40, 0, 0, 0, 0, 0, 0, 0, 41, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42
, 43, 44, 0, 45, 0, 0, 0, 46, 0, 0, 0, 0, 0, 0, 0, 47, 48, 49, 0, 50, 0, 0, 0, 51, 52, 53, 0, 54, 55, 56, 57, 58 };
// 计算LBP
int heightOfExtendedImage = extendedImage.rows;
int widthOfExtendedImage = extendedImage.cols;
int widthOfLBP=LBPImage.cols;
uchar *rowOfExtendedImage = extendedImage.data+widthOfExtendedImage+1;
uchar *rowOfLBPImage = LBPImage.data;
int pixelDiff = 5;
for (int y = 1; y <= heightOfExtendedImage - 2; ++y,rowOfExtendedImage += widthOfExtendedImage, rowOfLBPImage += widthOfLBP)
{
// 列
uchar *colOfExtendedImage = rowOfExtendedImage;
uchar *colOfLBPImage = rowOfLBPImage;
for (int x = 1; x <= widthOfExtendedImage - 2; ++x, ++colOfExtendedImage, ++colOfLBPImage)
{
// 计算LBP值
int LBPValue = 0;
if (colOfExtendedImage[0 - widthOfExtendedImage - 1] >= colOfExtendedImage[0]+pixelDiff)
LBPValue += 128;
if (colOfExtendedImage[0 - widthOfExtendedImage] >= colOfExtendedImage[0]+pixelDiff)
LBPValue += 64;
if (colOfExtendedImage[0 - widthOfExtendedImage + 1] >= colOfExtendedImage[0]+pixelDiff)
LBPValue += 32;
if (colOfExtendedImage[0 + 1] >= colOfExtendedImage[0]+pixelDiff)
LBPValue += 16;
if (colOfExtendedImage[0 + widthOfExtendedImage + 1] >= colOfExtendedImage[0]+pixelDiff)
LBPValue += 8;
if (colOfExtendedImage[0 + widthOfExtendedImage] >= colOfExtendedImage[0]+pixelDiff)
LBPValue += 4;
if (colOfExtendedImage[0 + widthOfExtendedImage - 1] >= colOfExtendedImage[0]+pixelDiff)
LBPValue += 2;
if (colOfExtendedImage[0 - 1] >= colOfExtendedImage[0]+pixelDiff)
LBPValue += 1;
colOfLBPImage[0] = table[LBPValue];
} // x
}// y
}
结论:计算LBP编码值,像素差值取5,可以减少背景细微差异而又满足车道线特征分布带来的多检,整体而言检测结果更加准确。