Mercurial > hg > nsaunier > traffic-intelligence
comparison samples/TTC/ttcCompare.py @ 464:dcc821b98efc
integrated and reorganized Sohail s work on exact ttc computation
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Sun, 23 Feb 2014 23:18:08 -0500 |
| parents | TTC Sample/ttcCompare.py@af2222c0c9c0 |
| children |
comparison
equal
deleted
inserted
replaced
| 463:cb9683f9efe7 | 464:dcc821b98efc |
|---|---|
| 1 import matplotlib.image as mpimg | |
| 2 from numpy.linalg.linalg import inv | |
| 3 from numpy import loadtxt | |
| 4 import computeTTC | |
| 5 import numpy as np | |
| 6 import glob | |
| 7 | |
| 8 #databaseName = ['11.sqlite'] | |
| 9 databaseName = glob.glob("*.sqlite") | |
| 10 | |
| 11 bikOri = mpimg.imread('bikeOri.png') | |
| 12 bikAreaOri = bikOri[:,:,0] | |
| 13 bikDes = mpimg.imread('bikeDes.png') | |
| 14 bikAreaDes = bikDes[:,:,0] | |
| 15 carOri = mpimg.imread('carOri.png') | |
| 16 carAreaOri = carOri[:,:,0] | |
| 17 carDes = mpimg.imread('carDes.png') | |
| 18 carAreaDes = carDes[:,:,0] | |
| 19 | |
| 20 videoY = bikOri.shape[0] | |
| 21 videoX = bikOri.shape[1] | |
| 22 | |
| 23 homography=inv(loadtxt('homography.txt')) | |
| 24 framePerSecond=15 | |
| 25 collisionDistanceThreshold=10 | |
| 26 | |
| 27 bikCount=0 | |
| 28 carCount=0 | |
| 29 bikSpeed=[] | |
| 30 carSpeed=[] | |
| 31 ttcDist=[] | |
| 32 potentioalCollision=0 | |
| 33 | |
| 34 for d in databaseName: | |
| 35 print d | |
| 36 bc,cc,bs,cs,ttcdist,potCollision = computeTTC.computeTTC(d,homography,framePerSecond,videoX,videoY,collisionDistanceThreshold,bikAreaOri,bikAreaDes,carAreaOri,carAreaDes) | |
| 37 bikCount += bc | |
| 38 carCount += cc | |
| 39 bikSpeed.extend(bs) | |
| 40 carSpeed.extend(cs) | |
| 41 ttcDist.extend(ttcdist) | |
| 42 potentioalCollision += potCollision | |
| 43 | |
| 44 print 'bikCount :', bikCount | |
| 45 print 'carCount :', carCount | |
| 46 print 'Number of Potential Collisions :', potentioalCollision | |
| 47 np.savetxt('ttc.txt',ttcDist,fmt='%1.2f') | |
| 48 np.savetxt('freq.txt',[bikCount,carCount,potentioalCollision],fmt='%i') | |
| 49 np.savetxt('bikSpeed.txt',bikSpeed,fmt='%1.2f') | |
| 50 np.savetxt('carSpeed.txt',carSpeed,fmt='%1.2f') | |
| 51 |
