资源简介
适用于初接触交通灯识别的初学者!根据颜色分割、图像滤波进行图像预处理,之后根据像素特点(长宽比、像素个数等)进行精确提取特征区域,最后利用匹配进行识别。
代码片段和文件信息
#include “../header/TrafficSignRecognition.h“
//Traffic sign recognition from 640x480 RGB images
//Images are converted to grayscale then filtered and then processed to identify and recognize the sign.
int main()
{
char first[255];
char last[255];
char full[255];
//number of images to check
int num =55;
//result r[10];
//setting string to receive all the names in the form: “(Test)(number)(.jpg)“
//sprintf_s(first “data“);
sprintf_s(last “.jpg“);
//sprintf_s(full “%d%s“ num last);
for (int k=1; k {
sprintf_s(full “%d%s“ k last);
IplImage* image = cvLoadImage(full CV_LOAD_IMAGE_GRAYSCALE);
//Gaussian filter
cvSmooth(image image CV_GAUSSIAN33);
cvDilate(imageimageNULL 1);
cvCvtColor(image image CV_GRAY2RGB);
IplImage* hsv = cvCreateImage( cvGetSize(image) IPL_DEPTH_8U 3 );
IplImage *gray = cvCreateImage(cvGetSize(image)IPL_DEPTH_8U1);
hsv = convertPixeltoHSV(image);
CvMemStorage* storage = cvCreateMemStorage(0);
cvCvtColor(image gray CV_RGB2GRAY);
//Separate RGB Colors
IplImage* image_red = cvCreateImage( cvGetSize(image) IPL_DEPTH_8U 1 );
IplImage* image_blue = cvCreateImage( cvGetSize(image) IPL_DEPTH_8U 1 );
IplImage* image_yellow = cvCreateImage( cvGetSize(image) IPL_DEPTH_8U 1 );
IplImage *image_gray = cvCreateImage(cvGetSize(image)IPL_DEPTH_8U1);
cvSmooth(hsv hsv CV_GAUSSIAN33);
detectRed(hsv image_red);
detectBlue(hsv image_blue);
detectYellow(hsv image_yellow);
// Add the tracking image and the frame
cvAdd(image_red image_blue image_gray);
cvAdd(image_gray image_yellow image_gray);
cvDilate(image_grayimage_grayNULL 1);
cvDilate(image_grayimage_grayNULL 1);
cvDilate(image_grayimage_grayNULL 1);
cvDilate(image_grayimage_grayNULL 1);
//cvErode(image_grayimage_grayNULL 1);
cvNamedWindow( “viewer_gray“ 1);
cvShowImage( “viewer_gray“ image_gray); // show image
cvWaitKey(0);
IplImage* image_cluster = cvCreateImage( cvGetSize(image) IPL_DEPTH_8U 1 );
mean_var candidates[50];
int can=0;
can = clustering(image_gray image_cluster candidates);
cvNamedWindow( “viewer_2“ 1);
cvShowImage( “viewer_2“ image_cluster); // show image
cvWaitKey(0);
CvRect region;
for(int i=0; i<5; i++){
//Apply the color threshold for each specific color
//region = cvRect( candidates[i].x_mean-(candidates[i].x_mean/2) candidates[i].y_mean-(candidates[i].y_mean/2) candidates[i].x_mean candidates[i].y_mean );
if( (candidates[i].x_mean-75)>0 && (candidates[i].y_mean-75)>0){region= cvRect( candidates[i].x_mean-75 candidates[i].y_mean-75 180 180 );}
else{
if((candidates[i].y_mean-75)<0 && (candidates[i].x_mean-75)<0){region= cvRect( 0 0 180 180 );}
else{
if((candidates[i].y_mean-75)<0 && (candidates[i].y_mean-75)!=0) {region= cvRect( candidates[i].x_mea
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2017-01-17 09:23 traffic_recognition-master\
文件 378 2017-01-17 09:23 traffic_recognition-master\.gitattributes
文件 649 2017-01-17 09:23 traffic_recognition-master\.gitignore
文件 11981 2017-01-17 09:23 traffic_recognition-master\TrafficSignRecognition.cpp
文件 1206 2017-01-17 09:23 traffic_recognition-master\TrafficSignRecognition.h
- 上一篇:studio one4应用程序
- 下一篇:滴滴出行空白模板
评论
共有 条评论