Applications
Detecting stationary and moving objects in dense fog.
| Frame No. and Description | Screen Shots |
|---|---|
| source code in C\C++ | void fITS06NOV(int nCh) { int i; int nClrs = 1; ///3--if we want to use color image as the background, this is virtually unnecessary because color information is too difficult to handel in real cameras. ///1a. let us set all inner parameters for the TrafGo SDK at every frame. setParameters(); tgPauseLogWriting(); ///we need to put the writting to the log file to a halt, otherwise it will make log file too big to handel. ///2a. Get the raw data from the current avi frame. TgImage oImg; int err = tgGetCurrentAVIFrame(oImg); if( err!=0 ) return; ///a test to set the display window to the user's defined ploting window. ///tgSetImageWnd(g_pBtn, nCh); ///tgSetImageWnd(NULL, nCh); ///a test to set the output window to the user's defined ploting window. ///tgSetOutputWnd(g_pBtn, nCh); ///2b. preprocessing the image frame ///tgSetAutoBkThreshold(true, nCh); ///to turn on the auto-BkThreshold apdating, if you want to manualy choose the threahold, using tgSetAutoBkThreshold(false, nCh); err = tgProcessingCardDataTgImage(&oImg, nClrs, nCh); ///the auto-lane learning for this channel. We assume the usage of this function must seperated from measurements and detection. /// tgLnLearningTgImage(&oImg, nClrs, nCh); ///2c. get the counts of vehicles for each lane in the mainlane. ///NOTE: _MAX_nLANES is the maximun number of lanes that allowed. Increase it or, use a dynamic array for g_CM_Count_EachLane. int nChsAllowed = tgGetLaneNum(nCh)< _MAX_nLANES?tgGetLaneNum(nCh):_MAX_nLANES; for(i=0; i< nChsAllowed; i++) { g_CM_Count_EachLane[i] = tgGetCountsPerLane(i, nCh); } ///2d. get the statistics of the headway distances for each individual lane. { ///2d.1. we first calculate the pixel-to-physic-normalized headway distance for each lane, the history of the distant data is now in the buffer for each lane and the next steps will make good use of these data. tgCalculateHeadwayDistAllLane( nCh); ///2d.2. then we get the medium-value from the histgram as the headway dist for lane 3. for(i=0; i< nChsAllowed; i++) { ///display this distance. g_CM_DistAve[i] = tgGetHdwyDist4LaneMedium(i, nCh); } } ///2e. get the statistics of the speed for each individual lane. { ///2e.1. we first calculate the pixel-to-physic-normalized speed for each lane, the history of the distant data is now in the buffer for each lane and the next steps will make good use of these data. #ifdef BEFORE_1110 tgCalculateSpeedAllLane( nCh); for(i=0; i< nChsAllowed; i++) {///2e.2. then we get the medium speed of the traffic flow of a given lane in a given video channel. ///g_CM_SpeedAve[i] = tgGetSpeed4LaneMedium(i, nCh); } ///2e.3. we can also get the latest speed recorder for a given channel. NOTE: since the kernel doesn't update the record index and speed if there is no new speed record, the user must make sure if this latest speed is a new one or just a dead record for the latest one already visited since longtime ago. for(i=0; i< nChsAllowed; i++) { long aRecordIdx; double aSpeed; tgGetLastSpeed4Lane(i, aRecordIdx, aSpeed, nCh); if(aSpeed>0){///speed==-1 is a useless record. int myIndex = aRecordIdx; ///TODO: add your own code to make sure your get a new data entry by using something like the following: ///if(aRecordIdx!=g_oldIdx){g_oldIdx=aRecordIdx; newSpeed = aSpeed; ///} else {;} } } ///2e.4. we can also get the latest facing speed for each lane: this speed is only accurate when a vehicle approach from far end. for(i=0; i< nChsAllowed; i++) { double aSpeed; ///to measure the speed when the vehicle approaching the camera. ///tgGetLastFaceSpeed4Lane(i, aSpeed, nCh); ///if we want to measure the speed when the vehicle leaving the camera. tgGetLastBackSpeed4Lane(i, aSpeed, nCh); if(aSpeed > 0){///speed==-1 is a useless record. The latest speed will hold untill the next vehile entering the lane. ///TODO: add your own code to make use of aSpeed. g_CM_SpeedAve[i] = aSpeed; ///only for display } } #else for(i=0; i< nChsAllowed; i++) { long aRecordIdx; double aSpeed; tgGetLastSpeed4Lane(i, aRecordIdx, aSpeed, nCh); if(aSpeed > 0){///speed==-1 is a useless record. The latest speed will hold untill the next vehile entering the lane. ///TODO: add your own code to make use of aSpeed. g_CM_SpeedAve[i] = aSpeed; ///only for display } } #endif } ///2f. get the reverse driving event trigger { for(i=0; i< nChsAllowed; i++) { g_CM_bRevDriveEvent[i] = tgChkReverseDriving(i, nCh); if(g_CM_bRevDriveEvent[i]){ g_CM_Count++; ///MessageBox(NULL,"Reverse Driving", "YangSky:Alarm",0); } } } ///2g. find all moving pedestrains. {///if we need to post-processing the detection of pedestrains. int oTotal; TgRect* rect = tgFindAllMovingPedestrains(&g_TgHumanAttrVals, g_PED_degree, oTotal, nCh); if(oTotal>0){///if we found some peds. ///TODO:put your user specific action for moving pedestrain here. int iiii = 0; } } } |


