资源简介
本项目是我用基于Opencv和C++实现的一整套车牌识别系统从定位、分割到字符识别的源代码,可直接运行使用,效果还不错。
代码片段和文件信息
#include “StdAfx.h“
#include “charseg_preprocess.h“
#include
extern bool Plate_flag;
namespace plate
{
/**
* make_border_zeros ------ mask the top two rows bottom two rows left two columns
* right two columns with zeros
*
* Parameters:
* @img ------------------- the input image which will be modified
*/
static void make_border_zeros(cv::Mat& img)
{
CV_Assert( img.depth() == CV_8UC1 );
CV_Assert( img.rows >= 2 );
CV_Assert( img.cols >= 2 );
img.rowRange( 0 2 ) = cv::Mat::zeros(2 img.cols CV_8UC1);
img.rowRange( img.rows - 2 img.rows ) =
cv::Mat::zeros(2 img.cols CV_8UC1);
img.colRange( 0 2 ) = cv::Mat::zeros(img.rows 2 CV_8UC1);
img.colRange( img.cols - 2 img.cols ) =
cv::Mat::zeros(img.rows 2 CV_8UC1);
return;
}
/**
* object_enhancement -------- enhance the seven characters in the plate
*
* Parameters:
* @img ---------------------- the input gray image characters in which will be enhanced
*/
static void object_enhancement(cv::Mat& img)
{
CV_Assert( img.channels() == 1 );
// transfer pixel value range from [0 255] to [0 100]
cv::Mat weaken_img;
img.convertTo( weaken_img CV_8UC1 0.40 0.0 );
// find the first top 40% pixel values
std::vector pixel_values;
for ( int r = 0; r < weaken_img.rows; r++ ) {
const unsigned char* prow = weaken_img.ptr(r);
for ( int c = 0; c < weaken_img.cols; c++ ) {
pixel_values.push_back( prow[c] );
}
}
std::sort( pixel_values.begin() pixel_values.end() );
std::size_t sentinel_index = cvRound( pixel_values.size() * 0.60 );
unsigned char sentinel_value = pixel_values[sentinel_index];
// only the pixels whose value are in the top 40% are enhanced
for ( int r = 0; r < weaken_img.rows; r++ ) {
const unsigned char* pweaken_img_row =
weaken_img.ptr(r);
unsigned char* pimg_row = img.ptr(r);
for ( int c = 0; c < weaken_img.cols; c++ ) {
if ( pweaken_img_row[c] >= sentinel_value ) {
pimg_row[c] = cv::saturate_cast(
pweaken_img_row[c] * 2.55 );
}
else {
pimg_row[c] = pweaken_img_row[c];
}
}
}
return;
}
/**
* img_threshold ---------- Apply a fixed-level threshold to each pixel of the image
*
* Parameters:
* @img ------------------- the input gray image
*/
static void img_threshold(cv::Mat& img)
{
CV_Assert( img
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 10625 2013-04-10 13:55 plate_recognition_20130410_beifen\charseg_preprocess.cpp
文件 645 2013-04-01 10:35 plate_recognition_20130410_beifen\charseg_preprocess.h
文件 24169 2013-04-10 13:42 plate_recognition_20130410_beifen\charseg_segment.cpp
文件 892 2013-04-01 10:33 plate_recognition_20130410_beifen\charseg_segment.h
文件 752 2013-04-10 11:38 plate_recognition_20130410_beifen\main.cpp
文件 36339 2013-07-05 12:01 plate_recognition_20130410_beifen\plate_recognition_20130410.cpp
目录 0 2013-09-01 09:37 plate_recognition_20130410_beifen\
- 上一篇:哈夫曼压缩解压算法-C语言
- 下一篇:C语言控制台窗口界面编程(修正版)
评论
共有 条评论