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]:"<