资源简介
基于OpenCV的红绿灯识别系统,能通过图像识别裁剪出图片中的红绿灯状态。
代码片段和文件信息
#include “stdafx.h“
#include
#include
#include
#include
#include
using namespace cv;
using namespace std;
void mask(const cv::Mat& image double minHue double maxHue double minSat double maxSat cv::Mat& mask);
void kuang(IplImage*src IplImage*dst);
void main()
{
IplImage*src_image = cvLoadImage(“cc.jpg“);//原图
cvNamedWindow(“原图“);
cvShowImage(“原图“ src_image);
IplImage *hsv = cvCreateImage(cvGetSize(src_image) IPL_DEPTH_8U 3);//RGB转换成HSV
cvCvtColor(src_image hsv CV_BGR2HSV);
IplImage*gray = cvCreateImage(cvGetSize(src_image) IPL_DEPTH_8U 1);//灰度图像
cvCvtColor(src_image gray CV_BGR2GRAY);
//cvNamedWindow(“gray“);
//cvShowImage(“gray“ gray);
kuang(hsv gray);
IplImage*erzhi = cvCreateImage(cvGetSize(src_image) IPL_DEPTH_8U 1);//二值化
cvThreshold(gray erzhi 0 255 CV_THRESH_BINARY);
cvNamedWindow(“二值图像“);
cvShowImage(“二值图像“ erzhi);
IplImage*image = cvCreateImage(cvGetSize(src_image) IPL_DEPTH_8U 1);
cvCopy(erzhi image); //image已经变成处理后的图像
int count_height[2048] = { 0 };
int height = src_image->height;
int width = src_image->width;
CvScalar color;//表示颜色
for (int j = height - 1; j >= 0; j--)
{
for (int i = 0; i < width; i++)
{
color = cvGet2D(image j i);//(ij)的像素点值
if (color.val[0] != 0)
{
count_height[j]++;
}
}
}
int maxl = 0;
int minl = 0;
for (int j = height - 1; j >= 0; j--)
{
if (count_height[j] > 0)
{
minl = j;//最小行
}
}
for (int j = 0; j < height; j++)
{
if (count_height[j] > 0)
{
maxl = j;//最大行
}
}
int m_max_value = 0;
m_max_value = count_height[0];
m_max_value = maxl - minl + 1;
CvRect ROI_rect;//以左上角顶点和长宽设置一个矩形区域
ROI_rect.x = 0;
ROI_rect.y = minl;
ROI_rect.width = src_image->width;
ROI_rect.height = m_max_value;
cvSetImageROI(gray ROI_rect);//设置图像的感兴趣区域
IplImage*ROI = cvCreateImage(cvSize(ROI_rect.width m_max_value) IPL_DEPTH_8U 1);//裁剪红绿灯区域
cvCopy(gray ROI);
//显示出黑白的红绿灯区域:
cvNamedWindow(“上下裁剪“);
cvShowImage(“上下裁剪“ ROI);
int x_max = 0;
int x_min = 0;
int max_value_count_row = 0;
int count_row[2048] = { 0 };
////统计红绿灯的宽度
for (int i = width - 1; i >= 0; i--)
{
for (int j = 0; j < height; j++)
{
color = cvGet2D(image j i);//(ij)的像素点值
if (color.val[0] != 0)
{
count_row[i]++;
}
}
}
for (int i = width - 1; i >= 0; i--)
{
if (count_row[i] > 0)
{
x_min = i;//最小行
}
}
for (int i = 0; i < width; i++)
{
if (count_row[i] > 0)
{
x_max = i;//最大行
}
}
max_value_count_row = x_max - x_min + 1;
CvRect ROI_Plate;
ROI_Plate.x = x_min;
ROI_Plate.y = minl;
ROI_Plate.width = max_value_count_row;
ROI_Plate.height = m_max_value;
cvSetImageROI(src_image ROI_Plate);
IplImage*plate_image = cvCreateImage(cvSize(ROI_Plate.width ROI_Plate.height) src_image->depth src_
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2017-12-25 23:23 ConsoleApplication1\
目录 0 2017-12-25 20:57 ConsoleApplication1\ConsoleApplication1\
文件 60 2013-07-22 01:18 ConsoleApplication1\ConsoleApplication1\ClassDiagram.cd
文件 6086 2017-12-25 20:57 ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.cpp
文件 8447 2017-12-22 20:17 ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.vcxproj
文件 1326 2017-10-23 23:23 ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.vcxproj.filters
文件 165 2017-10-23 23:55 ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.vcxproj.user
目录 0 2017-12-25 20:57 ConsoleApplication1\ConsoleApplication1\Debug\
目录 0 2017-12-25 20:57 ConsoleApplication1\ConsoleApplication1\Debug\ConsoleA.58AFB739.tlog\
文件 10894 2017-12-25 20:57 ConsoleApplication1\ConsoleApplication1\Debug\ConsoleA.58AFB739.tlog\CL.read.1.tlog
文件 2050 2017-12-25 20:57 ConsoleApplication1\ConsoleApplication1\Debug\ConsoleA.58AFB739.tlog\CL.write.1.tlog
文件 206 2017-12-25 20:57 ConsoleApplication1\ConsoleApplication1\Debug\ConsoleA.58AFB739.tlog\ConsoleApplication1.lastbuildstate
文件 2058 2017-12-25 20:57 ConsoleApplication1\ConsoleApplication1\Debug\ConsoleA.58AFB739.tlog\cl.command.1.tlog
文件 2726 2017-12-25 20:57 ConsoleApplication1\ConsoleApplication1\Debug\ConsoleA.58AFB739.tlog\li
文件 5216 2017-12-25 20:57 ConsoleApplication1\ConsoleApplication1\Debug\ConsoleA.58AFB739.tlog\li
文件 1096 2017-12-25 20:57 ConsoleApplication1\ConsoleApplication1\Debug\ConsoleA.58AFB739.tlog\li
文件 2229 2017-12-25 20:57 ConsoleApplication1\ConsoleApplication1\Debug\ConsoleApplication1.log
文件 276597 2017-12-25 20:57 ConsoleApplication1\ConsoleApplication1\Debug\ConsoleApplication1.obj
文件 1638400 2017-12-22 20:07 ConsoleApplication1\ConsoleApplication1\Debug\ConsoleApplication1.pch
文件 11811 2017-12-22 20:07 ConsoleApplication1\ConsoleApplication1\Debug\stdafx.obj
文件 584704 2017-12-25 20:57 ConsoleApplication1\ConsoleApplication1\Debug\vc120.idb
文件 1470464 2017-12-25 20:57 ConsoleApplication1\ConsoleApplication1\Debug\vc120.pdb
文件 1173 2017-12-22 20:22 ConsoleApplication1\ConsoleApplication1\OpencvDebugeconfig.props
文件 1088 2017-10-23 23:45 ConsoleApplication1\ConsoleApplication1\OpencvReleaseconfig.props
文件 1594 2017-10-23 23:23 ConsoleApplication1\ConsoleApplication1\ReadMe.txt
文件 105641 2017-12-21 18:12 ConsoleApplication1\ConsoleApplication1\aa.jpg
文件 17544 2017-12-21 18:15 ConsoleApplication1\ConsoleApplication1\bb.jpg
文件 167941 2017-12-21 16:46 ConsoleApplication1\ConsoleApplication1\cc.jpg
文件 10373 2017-12-23 14:47 ConsoleApplication1\ConsoleApplication1\dd.jpg
文件 225 2017-10-23 23:23 ConsoleApplication1\ConsoleApplication1\stdafx.cpp
文件 234 2017-10-23 23:23 ConsoleApplication1\ConsoleApplication1\stdafx.h
............此处省略31个文件信息
相关资源
- opencv手写英文字符识别
- qt-vsaddin-msvc2017 插件
- OpenCV测试工程
- 基于Opencv3.0生成的dll
- Windows下VS2015编译并使用libcurl.lib静态
- arm版opencv-2.4.9
- GBVS视觉显著性代码
- qt-vsaddin-msvc2017-2.2.0.vsix
- 算法竞赛入门经典第2版.刘汝佳(带书
- opencv3 图片外接矩形框
- OPENCV 合成两张焦点不同,图像相同的
- OPENCV 找出图片焦点
- EVs101-11-13-09(web).ppt
- kinect2_SDK_深度图到RGB的映射
- 《视觉系统设计》
- opencv1.0.0版本
- arm架构下的boost库文件
- 相机标定完整工程
- DevComponents.DotNetBar2源码 VS2013全工程
- VIBE算法原理及openCV源程序
- cximage600_full在VS2013编译的库
- 串口通信编程实践 串口编程最好的书
- Boost-1.47.0-vs2008-x64.exe
- 线性表的基本操作vs2017
- opencv+zbar实现摄像头二维码识别
- Ceph分布式存储实战高清最新版
- 信息隐藏隐写与分析
- opencv学习---运动目标前景检测
- 新手学习opencv--基于Hog的视频行人检测
- 使用vs2008做的影院售票系统
评论
共有 条评论