Mercurial Hosting > traffic-intelligence
comparison scripts/compute-homography.py @ 478:d337bffd7283
Display of points in compute homography and step option to replay videos
A bug seems to remain with respect to trajectory bounds, to check
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Thu, 27 Mar 2014 11:40:28 -0400 |
parents | 6551a3cf1750 |
children | b0dac840c24f |
comparison
equal
deleted
inserted
replaced
477:ed4166b0ba9d | 478:d337bffd7283 |
---|---|
94 | 94 |
95 if homography.size>0: | 95 if homography.size>0: |
96 np.savetxt('homography.txt',homography) | 96 np.savetxt('homography.txt',homography) |
97 | 97 |
98 if args.displayPoints and args.videoFrameFilename != None and args.worldFilename != None and homography.size>0: | 98 if args.displayPoints and args.videoFrameFilename != None and args.worldFilename != None and homography.size>0: |
99 worldImg = plt.imread(args.worldFilename) | 99 worldImg = cv2.imread(args.worldFilename) |
100 videoImg = plt.imread(args.videoFrameFilename) | 100 videoImg = cv2.imread(args.videoFrameFilename) |
101 invHomography = np.linalg.inv(homography) | 101 invHomography = np.linalg.inv(homography) |
102 projectedWorldPts = cvutils.projectArray(invHomography, worldPts.T).T | 102 projectedWorldPts = cvutils.projectArray(invHomography, worldPts.T).T |
103 projectedVideoPts = cvutils.projectArray(invHomography, videoPts.T).T | 103 projectedVideoPts = cvutils.projectArray(homography, videoPts.T).T |
104 for i in range(worldPts.shape[0]): | 104 for i in range(worldPts.shape[0]): |
105 cv2.circle(worldImg,tuple(np.int32(np.round(worldPts[i]/args.unitsPerPixel))),2,cvutils.cvRed) | 105 # world image |
106 cv2.circle(worldImg,tuple(np.int32(np.round(worldPts[i]/args.unitsPerPixel))),2,cvutils.cvBlue) | |
106 cv2.circle(worldImg,tuple(np.int32(np.round(projectedVideoPts[i]/args.unitsPerPixel))),2,cvutils.cvRed) | 107 cv2.circle(worldImg,tuple(np.int32(np.round(projectedVideoPts[i]/args.unitsPerPixel))),2,cvutils.cvRed) |
107 # TODO print numbers and in image space | 108 cv2.putText(worldImg, str(i+1), tuple(np.int32(np.round(worldPts[i]/args.unitsPerPixel))+5), cv2.FONT_HERSHEY_PLAIN, 2., cvutils.cvBlue, 2) |
109 # video image | |
110 cv2.circle(videoImg,tuple(np.int32(np.round(videoPts[i]))),2,cvutils.cvBlue) | |
111 cv2.circle(videoImg,tuple(np.int32(np.round(projectedWorldPts[i]))),2,cvutils.cvRed) | |
112 cv2.putText(videoImg, str(i+1), tuple(np.int32(np.round(videoPts[i])+5)), cv2.FONT_HERSHEY_PLAIN, 2., cvutils.cvBlue, 2) | |
108 cv2.imshow('video frame',videoImg) | 113 cv2.imshow('video frame',videoImg) |
109 #cv2.imshow('world image',worldImg) | 114 cv2.imshow('world image',worldImg) |
110 cv2.waitKey() | 115 cv2.waitKey() |
111 cv2.destroyAllWindows() | 116 cv2.destroyAllWindows() |