From 7179d22185be500656a146df70681da96de1e3f0 Mon Sep 17 00:00:00 2001 From: Jayn <694728662@qq.com> Date: Sun, 15 Nov 2015 03:39:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=AC=AC=E4=BA=8C=E5=B1=82?= =?UTF-8?q?=E6=BB=A4=E6=B3=A2=EF=BC=8C=E4=BF=AE=E6=94=B9=E4=B9=8B=E5=89=8D?= =?UTF-8?q?=E7=9A=84=E6=BB=A4=E6=B3=A2bug=EF=BC=88=E4=B9=8B=E5=89=8D?= =?UTF-8?q?=E7=9A=84if=E5=88=A4=E6=96=AD=E6=BC=8F=E6=8E=89=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=E6=83=85=E5=86=B5=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 如果这一帧检测到信号灯,如果下面10帧中有未检测到信号灯,则计数器加1,若计数器值大于阈值,认为信号灯不存在了,反之则认为存在,同时,如果检测到红灯,计数器清零 --- Main_TrafficSignRecognition.cpp | 22 +-- TrafficLightDetection/RectangleDetection.cpp | 4 +- .../componentExtrationTL.cpp | 148 ++++++++++++++++-- 3 files changed, 154 insertions(+), 20 deletions(-) diff --git a/Main_TrafficSignRecognition.cpp b/Main_TrafficSignRecognition.cpp index 6a3ad0b..b89e436 100644 --- a/Main_TrafficSignRecognition.cpp +++ b/Main_TrafficSignRecognition.cpp @@ -44,6 +44,8 @@ CvANN_MLP nnetwork,nnetwork_RoundRim,nnetwork_RectBlue;//neural networks for thr PCA pca,pca_RoundRim,pca_RectBlue; deque signFilters[5]; deque TLFilters[3]; +int TLCount[3]={0,0,0};//用来进行结果的稳定 +int TLCountThreshold=10;//如果丢失10帧以上,则认为没有检测到了 //test function void testCamera(PCA &pca,PCA &pca_RoundRim,PCA &pca_RectBlue,CvANN_MLP &nnetwork, @@ -198,13 +200,15 @@ void TLDetectionPerFrame(IplImage *frame,float *TLDSend) IplConvKernel *t=cvCreateStructuringElementEx(7,7,3,3,CV_SHAPE_ELLIPSE); cvMorphologyEx(imageSeg,closeImg,NULL,t,CV_MOP_CLOSE); //cvShowImage("closeImg",closeImg); - //imageNoiseRem=noiseRemoval(imageSeg); + //cvWaitKey(5); + #if ISDEBUG_TL + //imageNoiseRem=noiseRemoval(imageSeg); cvNamedWindow("imgseg"); cvShowImage("imgseg",imageSeg); cvWaitKey(5); - cvShowImage("imageNoiseRem",imageNoiseRem); - cvWaitKey(5); + //cvShowImage("imageNoiseRem",imageNoiseRem); + //cvWaitKey(5); #endif //componentExtraction(imageNoiseRem,resize_TLR,TLDSend,found_TL); componentExtractionTL(closeImg,resize_TLR,TLDSend); @@ -653,8 +657,8 @@ void openMP_MultiThreadVideo() bool saveFlag=false; IplImage * frame,*copyFrame; float connectResult[8]={0,0,0,0,0,0,0,0}; - CvCapture * cap=cvCreateFileCapture("D:\\JY\\JY_TrainingSamples\\changshu data\\TL\\RedFalsePositive.avi"); - //CvCapture * cap=cvCreateFileCapture("D:\\JY\\JY_TrainingSamples\\2014.11.16\\1_clip.mp4"); + //CvCapture * cap=cvCreateFileCapture("D:\\JY\\JY_TrainingSamples\\changshu data\\TL\\RedFalsePositive.avi"); + CvCapture * cap=cvCreateFileCapture("CamraVideo\\Video_20151114103311.avi"); float startTime=1000*(float)getTickCount()/getTickFrequency(); CvVideoWriter * writer=NULL; //findColorRange(); @@ -664,7 +668,7 @@ void openMP_MultiThreadVideo() SYSTEMTIME stTime; GetLocalTime(&stTime); char *videoPath = new char[100];// "D:/123.dat"; - sprintf(videoPath, "ResultVideo//Video_%04d%02d%02d%02d%02d%02d.avi", stTime.wYear, stTime.wMonth, stTime.wDay, stTime.wHour, stTime.wMinute, stTime.wSecond); + sprintf(videoPath, "ResultVideo//Video_%04d.%02d.%02d_%02d.%02d.%02d.avi", stTime.wYear, stTime.wMonth, stTime.wDay, stTime.wHour, stTime.wMinute, stTime.wSecond); writer=cvCreateVideoWriter(videoPath,CV_FOURCC('X', 'V', 'I', 'D'), 20, cvGetSize(resize_TLR), 1); } @@ -710,9 +714,9 @@ void openMP_MultiThreadVideo() cvShowImage("TL",resize_TLR); cvWaitKey(5); //show the detection result of TSR - namedWindow("TSR"); - imshow("TSR",re_src); - waitKey(5); + //namedWindow("TSR"); + //imshow("TSR",re_src); + //waitKey(5); #endif if (saveFlag) { diff --git a/TrafficLightDetection/RectangleDetection.cpp b/TrafficLightDetection/RectangleDetection.cpp index 78d75e6..fa0eeaa 100644 --- a/TrafficLightDetection/RectangleDetection.cpp +++ b/TrafficLightDetection/RectangleDetection.cpp @@ -181,8 +181,8 @@ bool isLighInBox(Mat src) #if ISDEBUG_TL ofstream outfile; outfile.open(debugTLPath,ios::app);//ios::app ׷ӵķʽļ - outfile<<"===black ratio===:"< TLFilters[3]; +extern int TLCount[3]; +extern int TLCountThreshold; //ʶnhlsͼоοڵɫ int RecColor(Mat img) @@ -85,7 +87,7 @@ void componentExtractionTL(IplImage* inputImage,IplImage* srcImage,float* TLDSen int containCount=0;//ЧĿ //˲ - if(p1==0&&p2==0)//δ⵽źŵ +/* if(p1==0&&p2==0)//δ⵽źŵ { for (int i=0;i<3;i++) { @@ -105,12 +107,33 @@ void componentExtractionTL(IplImage* inputImage,IplImage* srcImage,float* TLDSen if (i==0) cout<<"TSContainCount:"<=0.4) + if((float)(TSContainCount)/(float)TLFilters[i].size()>=0.39) + { TLDSend[i]=1.0; + TLCount[i]=0;//⵽ + } + else - TLDSend[i]=0; + { + //TLDSend[i]=0; + if(TLCount[i]TLCountThreshold)//ʧֵ֡Ϊûźŵ + { + TLDSend[i]=0; + }else + {//ʧֵ֡ΧڣΪźŵ + TLDSend[i]=1.0; + } + } + } - }else{ + }*/ + +// else{ if (p1==1)//ǰнֹ { TLFilters[0].push_back(1.0);//red @@ -123,13 +146,66 @@ void componentExtractionTL(IplImage* inputImage,IplImage* srcImage,float* TLDSen if(*it==1.0)containCount++; it++; } - if ((float)(containCount)/(float)TLFilters[0].size()>=0.4) + if ((float)(containCount)/(float)TLFilters[0].size()>=0.39) + { TLDSend[0]=1.0;//ʾ⵽ + TLCount[0]=0;//⵽ + } else - TLDSend[0]=0; + { + if(TLCount[0]TLCountThreshold)//ʧֵ֡Ϊûźŵ + { + TLDSend[0]=0; + }else + {//ʧֵ֡ΧڣΪźŵ + TLDSend[0]=1.0; + } + } containCount=0; + }else{ + TLFilters[0].push_back(0); + if (TLFilters[0].size()>5) + TLFilters[0].pop_front(); + + deque::iterator it; + int TSContainCount=0; + it=TLFilters[0].begin(); + while(it=0.39) + { + TLDSend[0]=1.0; + TLCount[0]=0;//⵽ + } + + else + { + //TLDSend[0]=0; + if(TLCount[0]TLCountThreshold)//ʧֵ֡Ϊûźŵ + { + TLDSend[0]=0; + }else + {//ʧֵ֡ΧڣΪźŵ + TLDSend[0]=1.0; + } + } } + if(p2==1)//תֹ { TLFilters[1].push_back(1.0);//green @@ -143,11 +219,65 @@ void componentExtractionTL(IplImage* inputImage,IplImage* srcImage,float* TLDSen it++; } if ((float)(containCount)/(float)TLFilters[1].size()>=0.4) + { + TLCount[1]=0;//⵽ TLDSend[1]=1.0; + } + else - TLDSend[1]=0; + { + if(TLCount[1]TLCountThreshold)//ʧֵ֡Ϊûźŵ + { + TLDSend[1]=0; + }else + {//ʧֵ֡ΧڣΪźŵ + TLDSend[1]=1.0; + } + } containCount=0; + }else{ + TLFilters[1].push_back(0); + if (TLFilters[1].size()>5) + TLFilters[1].pop_front(); + + deque::iterator it; + int TSContainCount=0; + it=TLFilters[1].begin(); + while(it=0.39) + { + TLDSend[1]=1.0; + TLCount[1]=0;//⵽ + } + + else + { + //TLDSend[0]=0; + if(TLCount[1]TLCountThreshold)//ʧֵ֡Ϊûźŵ + { + TLDSend[1]=0; + }else + {//ʧֵ֡ΧڣΪźŵ + TLDSend[1]=1.0; + } + } } + /*ʱȥת if(p3==1)//תֹ { @@ -167,9 +297,9 @@ void componentExtractionTL(IplImage* inputImage,IplImage* srcImage,float* TLDSen TLDSend[2]=0; containCount=0; }*/ - } +// } - + //cout<<"count[0]:"<