资源简介
标志识别
代码片段和文件信息
#include
#include
#include
#include
#include
#include
#include
#include
#include “opencv2/highgui/highgui.hpp“
#include “opencv2/imgproc/imgproc.hpp“
using namespace std;
using namespace cv;
/**定义全局变量**/
float t;
double k;
double rhotheta;
int fd;
CvSeq *lines = 0;
double minValue2 maxValue2;
double minValue maxValue;
CvMemStorage *storage;
/**载入原图像和模板块**/
CvCapture *capture = cvCreateCameraCapture(0);
IplImage *img = cvQueryframe(capture);//申请读取下一帧内存
IplImage *templateImage;
IplImage *template1;
IplImage *template11;
IplImage *template12;
IplImage *template3;
IplImage *template4;
IplImage *templateImage1;
IplImage *result;
IplImage *result2;
IplImage *ImageSign;
IplImage *src;
IplImage *src1;
IplImage *src2;
IplImage *template2;
/**车道线所申请内存**/
IplImage *Line;
IplImage *ImageIPM;
IplImage *ImageCanny;
IplImage *ImageHough ;
/**函数**/
int ImageTracfficSign();//交通标志识别函数
int LaneLine();//车道线识别函数
/**@主函数**/
int main()
{
if(wiringPiSetup() < 0);
if((fd = serialOpen(“/dev/ttyUSB0“115200)) < 0);
printf(“serial test start ...\n“);
int frame=0frame1;//当前帧数
while (img!=NULL)//当读取到空的时候,即视频播放完毕则停止处理
{
img = cvQueryframe(capture);//不断读取下一帧
frame++;
cout<ame< //cvShowImage(“img“img);
LaneLine();
cout<total< if(lines->total==0)
{
frame1=frame;
if(frame>frame1+3)
{
ImageTracfficSign();//交通标志识别
if(minValue2 {
printf(“minValue2= %lf\n“minValue2);
serialPuts(fd“c“);
//serialPuts(fd“a“);
}
if(minValue {
printf(“minValue= %lf\n“minValue);
serialPuts(fd“b“);
//serialPuts(fd“a“);
}
}
for (int i=0;itotal;i++)
{
CvPoint2D32f *line = (CvPoint2D32f *)cvGetSeqElem(linesi);
rho = line[i].x theta = line[i].y;
//printf(“rho= %lf\n“rho);
//printf(“theta = %lf\n“theta);
//printf(“t=%lf\n“t);
CvPoint pt1 pt2;
double a = cos(theta) b = sin(theta);
double x0 = a*rhoy0 = b*rho;
pt1.x = cvRound(x0 + 1000*(-b));
pt1.y = cvRound(y0 + 1000*(a));
pt2.x = cvRound(x0 - 1000*(-b));
pt2.y = cvRound(y0 - 1000*(a));
t=theta*180/3.14;
k=-a/b;
//printf(“k= %lf\n“k);
printf(“t=%lf\n“t);
if(t<60&&t>35)
{
serialPuts(fd“c“);
}
else if(t>130&&t<150)
{
serialPuts(fd“b“);
}
else if((t>=16&&t<=35)||(t>=150&&t<=180)||(t>89&&t<92))
{
serialPuts(fd“a“);
}
//cvLine(ImageHoughpt1pt2CvScalar(02550)1CV_AA);
}
//cvShowImage(“HoughShow“ImageHough);
cvReleaseImage(&ImageHough);
cvReleaseMemStorage(&s
- 上一篇:C语言的读取GPS源码
- 下一篇:c++课程设计 职工工资管理系统
评论
共有 条评论