好文档 - 专业文书写作范文服务资料分享网站

系统详细设计

天下 分享 时间: 加入收藏 我要投稿 点赞

continue;

center = cvPoint( (comp_rect.x + comp_rect.width/2),

(comp_rect.y + comp_rect.height/2) );

cvCircle( dst, center, cvRound(magnitude*1.2), color, 3, CV_AA, 0 ); cvLine( dst, center, cvPoint( cvRound( center.x + magnitude*cos(angle*CV_PI/180)),

cvRound( center.y - magnitude*sin(angle*CV_PI/180))), color, 3, CV_AA, 0 ); }?

/////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////// 结束 ///////////////////////// }:

夜间车流量统计:

void CCarTrackSystemDlg::update_mhi( IplImage* img, IplImage* dst, int diff_threshold ) {

double timestamp = clock()/100.; // get current time in seconds 时间戳

CvSize size = cvSize(img->width,img->height); CvPoint pt3,pt4;

?CvRect bndRect=cvRect(0,0,0,0);//用cvBoundingRect画出外接矩形时需要的矩形

?CvFont font1;//初始化字体格式 int linetype=CV_AA; ?

// get current frame size,得到当前帧的尺寸 int idx1, idx2; IplImage* silh;

IplImage* pyr = cvCreateImage( cvSize((size.width & -2)/2, (size.height & -2)/2), 8, 1 ); CvMemStorage *stor; CvSeq *cont;

/*先进行数据的初始化*/

if( !mhi || mhi->width != size.width || mhi->height != size.height )

{

if( buf == 0 ) //若尚没有初始化则分配内存给他 {

buf = (IplImage**)malloc(N*sizeof(buf[0])); memset( buf, 0, N*sizeof(buf[0])); }

for(int i = 0; i < N; i++ ) {

cvReleaseImage( &buf[i] );

buf[i] = cvCreateImage( size, IPL_DEPTH_8U, 1 );

cvZero( buf[i] );// clear Buffer Frame at the beginning }

cvReleaseImage( &mhi );

mhi = cvCreateImage( size, IPL_DEPTH_32F, 1 ); cvZero( mhi ); // clear MHI at the beginning } // end of if(mhi)

/*将当前要处理的帧转化为灰度放到buffer的最后一帧中*/

cvCvtColor( img, buf[last], CV_BGR2GRAY ); // convert frame to grayscale

idx1 = last;

idx2 = (last + 1) % N; // index of (last - (N-1))th frame last = idx2; // 做帧差

silh = buf[idx2];//差值的指向idx2 |idx2-idx1|-->idx2(<-silh) cvAbsDiff( buf[idx1], buf[idx2], silh ); // get difference between frames

// 对差图像做二值化

cvThreshold( silh, silh, 30, 255, CV_THRESH_BINARY ); //threshold it,二值化

cvUpdateMotionHistory( silh, mhi, timestamp, MHI_DURATION ); // update MHI

cvConvert( mhi, dst );//将mhi转化为dst,dst=mhi

// 中值滤波,消除小的噪声

cvSmooth( dst, dst, CV_MEDIAN, 3, 0, 0, 0);

cvPyrDown( dst, pyr, CV_GAUSSIAN_5x5 );// 向下采样,去掉噪声,图像是

原图像的四分之一

cvDilate( pyr, pyr, 0, 1 ); // 做膨胀操作,消除目标的不连续空洞 cvPyrUp( pyr, dst, CV_GAUSSIAN_5x5 );// 向上采样,恢复图像,图像是原图像的四倍 //

// 下面的程序段用来找到轮廓 //

// Create dynamic structure and sequence. stor = cvCreateMemStorage(0);

cont = cvCreateSeq(CV_SEQ_ELTYPE_POINT, sizeof(CvSeq), sizeof(CvPoint) , stor);

// 找到所有轮廓

cvFindContours( dst, stor, &cont, sizeof(CvContour),

CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0));

// 直接使用CONTOUR中的矩形来画轮廓 for(;cont;cont = cont->h_next) {

CvRect r = ((CvContour*)cont)->rect;

if(r.height * r.width > 1500) // 面积小的方形抛弃掉 { ? ? bndRect = cvBoundingRect(cont, 0); ? //Get an average X position of the moving contour. ? ? avgX = (bndRect.x + bndRect.x + bndRect.width) / 2; ??? avgY = (bndRect.y + bndRect.y + bndRect.height) / 2; ? if(avgX > (m_tangle1.x>m_tangle2.x?m_tangle2.x:m_tangle1.x ) && avgX < (m_tangle1.x>m_tangle2.x?m_tangle1.x:m_tangle2.x )

? ? && avgY < (m_tangle1.y>m_tangle2.y?m_tangle1.y:m_tangle2.y) && avgY > (m_tangle1.y>m_tangle2.y?m_tangle2.y:m_tangle1.y )) { ?? ?? ? ? cvRectangle( img, cvPoint(r.x,r.y), ?? cvPoint(r.x + r.width, r.y + r.height),

CV_RGB(255,0,0), 1, CV_AA,0); ?? pt3.x = bndRect.x; ? ? pt3.y = bndRect.y;

?? ? pt4.x = bndRect.x + bndRect.width; pt4.y = bndRect.y + bndRect.height; ???

? ??cvInitFont(&font1, CV_FONT_HERSHEY_DUPLEX, 0.5, 0.5, 0, 2, 8);

?? for(int i=0;i<30;i++) ?? { ?? if(TrackBlock[i]->avgX !=0 && fabs((double)(avgX-TrackBlock[i]->avgX))<20 && fabs((double)(avgY-TrackBlock[i]->avgY))<50) ? {

? ? ?? cvPutText(img,msg[i], cvPoint(pt3.x,pt4.y), &font1, cvScalar(255,255,255)); ? ? ? TrackBlock[i]->FramesTracked=nFrmNum; ?? ? TrackBlock[i]->avgX=avgX; ? ??? TrackBlock[i]->avgY=avgY;

? ? ? //记录运动轨迹 ? ??? TrackBlock[i]->guiji_index=TrackBlock[i]->guiji_index+1; ? ? int index_g=TrackBlock[i]->guiji_index; ??? TrackBlock[i]->guiji[index_g].x=avgX; ? TrackBlock[i]->guiji[index_g].y=avgY; ? ???? for (int k=1;k< index_g;k++) ? ??? { ? ? ? cvLine(img, cvPoint(TrackBlock[i]->guiji[k].x , ? ? ?? TrackBlock[i]->guiji[k].y), ?? ? cvPoint(TrackBlock[i]->guiji[k+1].x, ? ? TrackBlock[i]->guiji[k+1].y), CV_RGB(0,191,255), 2, 8, 0 ); ? ?? } ? //取轨迹中三点,判断其在被监控车道的运动趋势来得到是否为逆行 ? ?? if (index_g >= 4) ???? { ?? if (TrackBlock[i]->guiji[1].yguiji[index_g/2].y&&TrackBlock[i]->guiji[index_g/2].y<TrackBlock[i]->guiji[index_g-1].y) ? ?? ?? { ?????? ?//在框内输出顺行 ??? cvPutText(img,\cvPoint(pt3.x+30,pt4.y), &font1, cvScalar(255,0,255)); ??? } else ?? ? ? { ? ? cvPutText(img,\gression\, cvPoint(pt3.x+20,pt4.y), &font1, cvScalar(255,0,0)); ? ? ?} ?? } ?????

????? ? ? ???? Findcar=true; ? ? break;//使跳出for循环 ? ? } ? }

??? if(Findcar!=true&& avgY<160)//表示没有找到车辆 ? ? { ? TrackBlock[No]->Direction=1; ????? TrackBlock[No]->FramesTracked=nFrmNum; ? ? ? TrackBlock[No]->avgX=avgX; ? TrackBlock[No]->avgY=avgY; ? if(No==29){ ? ? No=0; ? ? } ? else{ ? ?? ? No++; ? ? ? m_totalcar++; ????? CString str; ??? str.Format(\_totalcar); ???? GetDlgItem(IDC_NUM)->SetWindowText(str); ? } ? ?}? ? ??Findcar=false; ? ??? } ??? }

} //end of for

?//对于没有匹配的车辆,表示已经出了边界,清空数组 ?for(int j=0;j<30;j++) { if(TrackBlock[j]->FramesTracked != nFrmNum) ? { ??//虽然置为零,但是可能零和当前中心的值在设定的范围内,所以不行。 ???//TrackBlock[j]=NULL;为何用NULL不行。 ?TrackBlock[j]->Direction=0; ???TrackBlock[j]->FramesTracked=0; ? TrackBlock[j]->avgX=0; ?? TrackBlock[j]->avgY=0; } ?}

// free memory

cvReleaseMemStorage(&stor); cvReleaseImage( &pyr );

系统详细设计

continue;center=cvPoint((comp_rect.x+comp_rect.width/2),(comp_rect.y+comp_rect.height/2));cvC
推荐度:
点击下载文档文档为doc格式
0e4np1vq4s79ew80o94h77xpo584e200qwl
领取福利

微信扫码领取福利

微信扫码分享