1、该程序是基于同事车牌定位接口上进行的;
2、为调试程序,程序中设定了鼠标选择图片中特定区域来进行识别;
3、程序针对汽车颜色,一共8种颜色
PS:相比刚接触opencv就接手的半死不活的行人检测,这个算是稍稍给了些安慰O(∩_∩)O,继续努力撒
// color recognition.cpp : 定义控制台应用程序的入口点。
#include "stdafx.h"
#include <opencv2/opencv.hpp>
#include <iostream>
#include <stdio.h>
#include "cv.h"
#include <math.h>
#include "color module.h"
using namespace cv;
using namespace std;
#define N 10 //颜色模板的个数
// 颜色模板
// 黑、白、红、绿、蓝、黄、灰
#define BLACK 0
#define WHITE 1
#define RED1 2
#define RED2 3
#define GREEN1 4
#define GREEN2 5
#define BLUE1 6
#define BLUE2 7
#define YELLOW1 8
#define YELLOW2 9
#define GRAY 10
int colorVelue[N][3] = {
{50,50,50}, //黑
{255,255,255}, //白
{240,80,80}, //红小
{240,160,160}, //红大
{60,180,60}, //绿小
{160,240,160}, //绿大
{80,80,240}, //蓝小
{160,160,240}, //蓝大
{240,190,80}, //黄小
{240,240,160}}; //黄大
Rect r; //存储车牌位置
CvPoint origin;
IplImage* image=NULL;
int mark = 0; //选择ROI标志
void on_mouse( int event, int x, int y, int flags, void* zhang )
{
if( !image )
return;
CvPoint pt;
if( event == CV_EVENT_LBUTTONDOWN ) //开始点击选择跟踪物体
{
origin = cvPoint( x,y );
r = cvRect( x,y,0,0 );//坐标
r.x = MIN( x,origin.x );
r.y = MIN( y,origin.y );
r.width = r.x + CV_IABS( x - origin.x );
r.height = r.y + CV_IABS( y - origin.y );
r.x = MAX( r.x, 0 );
r.y = MAX( r.y, 0 );
r.width = MIN( r.width, image->width );
r.height = MIN( r.height, image->height );
r.width -= r.x;
r.height -= r.y;
}
if( event == CV_EVENT_LBUTTONUP )
{
pt = cvPoint( x,y );
mark = -1;
r.width = pt.x - r.x;
&n