diff 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
line wrap: on
line diff
--- a/scripts/compute-homography.py	Tue Mar 25 19:43:47 2014 -0400
+++ b/scripts/compute-homography.py	Thu Mar 27 11:40:28 2014 -0400
@@ -96,16 +96,21 @@
     np.savetxt('homography.txt',homography)
 
 if args.displayPoints and args.videoFrameFilename != None and args.worldFilename != None and homography.size>0:
-    worldImg = plt.imread(args.worldFilename)
-    videoImg = plt.imread(args.videoFrameFilename)
+    worldImg = cv2.imread(args.worldFilename)
+    videoImg = cv2.imread(args.videoFrameFilename)
     invHomography = np.linalg.inv(homography)
     projectedWorldPts = cvutils.projectArray(invHomography, worldPts.T).T
-    projectedVideoPts = cvutils.projectArray(invHomography, videoPts.T).T
+    projectedVideoPts = cvutils.projectArray(homography, videoPts.T).T
     for i in range(worldPts.shape[0]):
-        cv2.circle(worldImg,tuple(np.int32(np.round(worldPts[i]/args.unitsPerPixel))),2,cvutils.cvRed)
+        # world image
+        cv2.circle(worldImg,tuple(np.int32(np.round(worldPts[i]/args.unitsPerPixel))),2,cvutils.cvBlue)
         cv2.circle(worldImg,tuple(np.int32(np.round(projectedVideoPts[i]/args.unitsPerPixel))),2,cvutils.cvRed)
-        # TODO print numbers and in image space
+        cv2.putText(worldImg, str(i+1), tuple(np.int32(np.round(worldPts[i]/args.unitsPerPixel))+5), cv2.FONT_HERSHEY_PLAIN, 2., cvutils.cvBlue, 2)
+        # video image
+        cv2.circle(videoImg,tuple(np.int32(np.round(videoPts[i]))),2,cvutils.cvBlue)
+        cv2.circle(videoImg,tuple(np.int32(np.round(projectedWorldPts[i]))),2,cvutils.cvRed)
+        cv2.putText(videoImg, str(i+1), tuple(np.int32(np.round(videoPts[i])+5)), cv2.FONT_HERSHEY_PLAIN, 2., cvutils.cvBlue, 2)
     cv2.imshow('video frame',videoImg)
-    #cv2.imshow('world image',worldImg)
+    cv2.imshow('world image',worldImg)
     cv2.waitKey()
     cv2.destroyAllWindows()