交通标识牌识别c++代码实例及运行结果

运行环境:vs2013+opencv2.4.9+win10

数据来源于GTSRB

模型训练的C++代码

#include<opencv2/opencv.hpp>
#include <iostream>    
#include <fstream>
#include <vector>  
#include <string>  
#include<time.h>

using namespace cv;
using namespace std;

int main()
{
	int imgWidht = 48;//重新定义图片大小48*48
	int imgHeight = 48;

	vector<string> imgTrainPath;//输入文件名变量   
	vector<int> imgTrainLabel;
	int nLine = 0;
	string buf;
	ifstream imagePath("E:\\vs2013\\opencv_code\\GTSRBtrafficSign\\train\\trainImgPath.txt");//训练数据位置
	unsigned long n;

	while (imagePath)//读取训练样本,imageName.txt一行为路径,一行为标签,循环    
	{
		if (getline(imagePath, buf))
		{
			nLine++;
			if (nLine % 2 == 0)
			{
				imgTrainLabel.push_back(atoi(buf.c_str()));//atoi将字符串转换成整型,图片标签    
			}
			else
			{
				imgTrainPath.push_back(buf);//图像路径    
			}
		}
	}
	
  • 3
    点赞
  • 36
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
根据提供的引用内容,可以得知OpenCV是一个跨平台计算机视觉库,可以实现图像处理和计算机视觉方面的很多通用算法。其中包括交通标志识别。以下是一个基于C++的OpenCV交通标志识别的示例代码: ```c++ #include <opencv2/opencv.hpp> #include <iostream> using namespace cv; using namespace std; int main(int argc, char** argv) { // 读取图像 Mat src = imread("test.jpg"); if (src.empty()) { cout << "Could not open or find the image!\n" << endl; return -1; } // 转换为灰度图像 Mat gray; cvtColor(src, gray, COLOR_BGR2GRAY); // 进行高斯滤波 Mat blur; GaussianBlur(gray, blur, Size(3, 3), 0, 0); // 进行Canny边缘检测 Mat edges; Canny(blur, edges, 50, 150); // 进行形态学操作 Mat kernel = getStructuringElement(MORPH_RECT, Size(3, 3)); Mat dilate; dilate(edges, dilate, kernel); // 进行轮廓检测 vector<vector<Point>> contours; vector<Vec4i> hierarchy; findContours(dilate, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE); // 绘制轮廓 Mat result = src.clone(); for (size_t i = 0; i < contours.size(); i++) { drawContours(result, contours, static_cast<int>(i), Scalar(0, 0, 255), 2, LINE_8, hierarchy); } // 显示结果 imshow("Result", result); waitKey(0); return 0; } ``` 以上代码实现了对一张名为test.jpg的交通标志图像进行了处理,包括转换为灰度图像、高斯滤波、Canny边缘检测、形态学操作和轮廓检测,并将检测结果绘制在原图上显示出来。
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值