//not using hole traffic ligh as samples,just use the square light int RecognizeLight(IplImage* srcImg,CvRect iRect) { CvSize cutSize; cutSize.width=iRect.width; cutSize.height=iRect.height; IplImage *tmpCutImg=cvCreateImage(cutSize,srcImg->depth,srcImg->nChannels); GetImageRect(srcImg,iRect,tmpCutImg); #if IS_CUTIMG cvShowImage("tmpCutImg",tmpCutImg); cvWaitKey(1); char tmpName[100]; static int ppp=0; ppp++; sprintf_s(tmpName,"ImgCut//%d.jpg",ppp); cvSaveImage(tmpName,tmpCutImg); #endif Mat cutMat(tmpCutImg); Mat tmpTLRec; vector<float> descriptor; //识别信号灯类别 resize(cutMat,tmpTLRec,Size(TLREC_WIDTH,TLREC_HEIGHT)); TLRecHOG.compute(tmpTLRec,descriptor,Size(8,8)); int DescriptorDim=descriptor.size(); Mat SVMTLRecMat(1,DescriptorDim,CV_32FC1); for(int i=0; i<DescriptorDim; i++) SVMTLRecMat.at<float>(0,i) = descriptor[i]; int result=TLRecSVM.predict(SVMTLRecMat); cvReleaseImage(&tmpCutImg); return result; }
int isTL(IplImage* srcImg,CvRect iRect,bool isVertical) { CvSize cutSize; cutSize.width=iRect.width; cutSize.height=iRect.height; IplImage *tmpCutImg=cvCreateImage(cutSize,srcImg->depth,srcImg->nChannels); GetImageRect(srcImg,iRect,tmpCutImg); Mat cutMat(tmpCutImg); Mat tmpIsTL; vector<float> descriptor; //识别信号灯类别 if (isVertical){ resize(cutMat, tmpIsTL, Size(HOG_TLVertical_Width, HOG_TLVertical_Height)); myHOG_vertical.compute(tmpIsTL, descriptor, Size(8, 8)); } else{ resize(cutMat, tmpIsTL, Size(HOG_TLHorz_Width, HOG_TLHorz_Height)); myHOG_horz.compute(tmpIsTL, descriptor, Size(8, 8)); } int DescriptorDim=descriptor.size(); Mat SVMTLRecMat(1,DescriptorDim,CV_32FC1); for(int i=0; i<DescriptorDim; i++) SVMTLRecMat.at<float>(0,i) = descriptor[i]; //int result=isTLSVM.predict(SVMTLRecMat); int result = 0; if (isVertical) result = isVerticalTLSVM.predict(SVMTLRecMat); else { result = isHorzTLSVM.predict(SVMTLRecMat); } cvReleaseImage(&tmpCutImg); return result; }