汽车颜色识别--更新版

本文介绍了一个基于OpenCV的汽车颜色识别程序,通过鼠标选择图片中的汽车区域进行颜色分析。程序识别8种颜色:黑、白、红、绿、蓝、黄、灰,并通过直方图比较计算颜色类型。代码包括颜色模板、直方图计算和颜色匹配过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值