Mercurial Hosting > traffic-intelligence
annotate scripts/compute-homography.py @ 1243:88eedf79f16a
correct classifier.cfg and info classification
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Wed, 07 Feb 2024 11:53:00 -0500 |
parents | 6a6a4d5958f7 |
children |
rev | line source |
---|---|
998
933670761a57
updated code to python 3 (tests pass and scripts run, but non-executed parts of code are probably still not correct)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
960
diff
changeset
|
1 #! /usr/bin/env python3 |
151
4af774bb186d
wrote a simple script to compute homography from point correspondences and display the reprojection for visual verification
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
2 |
476
6551a3cf1750
modified compute-homography to work with argparse
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
443
diff
changeset
|
3 import sys, argparse |
151
4af774bb186d
wrote a simple script to compute homography from point correspondences and display the reprojection for visual verification
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
4 |
1199
6a6a4d5958f7
adding explicit choice of matplotlib backend
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1166
diff
changeset
|
5 import matplotlib |
6a6a4d5958f7
adding explicit choice of matplotlib backend
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1166
diff
changeset
|
6 matplotlib.use('TkAgg') |
6a6a4d5958f7
adding explicit choice of matplotlib backend
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1166
diff
changeset
|
7 |
238
be3761a09b20
added functions to input point correspondences
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
237
diff
changeset
|
8 import matplotlib.pyplot as plt |
151
4af774bb186d
wrote a simple script to compute homography from point correspondences and display the reprojection for visual verification
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
9 import numpy as np |
4af774bb186d
wrote a simple script to compute homography from point correspondences and display the reprojection for visual verification
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
10 import cv2 |
4af774bb186d
wrote a simple script to compute homography from point correspondences and display the reprojection for visual verification
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
11 |
1028
cc5cb04b04b0
major update using the trafficintelligence package name and install through pip
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
998
diff
changeset
|
12 from trafficintelligence import cvutils, utils, storage |
638
852f5de42d01
added functionality to read Aliaksei Tsai camera model data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
13 |
852f5de42d01
added functionality to read Aliaksei Tsai camera model data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
14 # TODO add option to use RANSAC or other robust homography estimation method? |
151
4af774bb186d
wrote a simple script to compute homography from point correspondences and display the reprojection for visual verification
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
15 |
476
6551a3cf1750
modified compute-homography to work with argparse
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
443
diff
changeset
|
16 parser = argparse.ArgumentParser(description='The program computes the homography matrix from at least 4 non-colinear point correspondences inputed in the same order in a video frame and a aerial photo/ground map, or from the list of corresponding points in the two planes.', epilog = '''The point correspondence file contains at least 4 non-colinear point coordinates |
6551a3cf1750
modified compute-homography to work with argparse
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
443
diff
changeset
|
17 with the following format: |
6551a3cf1750
modified compute-homography to work with argparse
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
443
diff
changeset
|
18 - the first two lines are the x and y coordinates in the projected space (usually world space) |
6551a3cf1750
modified compute-homography to work with argparse
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
443
diff
changeset
|
19 - the last two lines are the x and y coordinates in the origin space (usually image space) |
6551a3cf1750
modified compute-homography to work with argparse
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
443
diff
changeset
|
20 |
1166
7b4d732f82b3
adding an option to use image coordinates in point-correspondence file when undistorting
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1061
diff
changeset
|
21 Image space is in ideal point space (no camera) if undistorting the camera |
7b4d732f82b3
adding an option to use image coordinates in point-correspondence file when undistorting
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1061
diff
changeset
|
22 |
476
6551a3cf1750
modified compute-homography to work with argparse
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
443
diff
changeset
|
23 If providing video and world images, with a number of points to input |
1166
7b4d732f82b3
adding an option to use image coordinates in point-correspondence file when undistorting
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1061
diff
changeset
|
24 and a ratio to convert pixels to world distance unit (eg meters per pixel), |
476
6551a3cf1750
modified compute-homography to work with argparse
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
443
diff
changeset
|
25 the images will be shown in turn and the user should click |
591
aded6c1c2ebd
added framework script and function to compute matchings
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
572
diff
changeset
|
26 in the same order the corresponding points in world and image spaces.''', formatter_class=argparse.RawDescriptionHelpFormatter) |
476
6551a3cf1750
modified compute-homography to work with argparse
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
443
diff
changeset
|
27 |
6551a3cf1750
modified compute-homography to work with argparse
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
443
diff
changeset
|
28 parser.add_argument('-p', dest = 'pointCorrespondencesFilename', help = 'name of the text file containing the point correspondences') |
638
852f5de42d01
added functionality to read Aliaksei Tsai camera model data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
29 parser.add_argument('--tsai', dest = 'tsaiCameraFilename', help = 'name of the text file containing the camera parameter following the pinhole camera model (Lund format)') # caution, this is Aliaksei's format |
476
6551a3cf1750
modified compute-homography to work with argparse
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
443
diff
changeset
|
30 parser.add_argument('-i', dest = 'videoFrameFilename', help = 'filename of the video frame') |
6551a3cf1750
modified compute-homography to work with argparse
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
443
diff
changeset
|
31 parser.add_argument('-w', dest = 'worldFilename', help = 'filename of the aerial photo/ground map') |
6551a3cf1750
modified compute-homography to work with argparse
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
443
diff
changeset
|
32 parser.add_argument('-n', dest = 'nPoints', help = 'number of corresponding points to input', default = 4, type = int) |
6551a3cf1750
modified compute-homography to work with argparse
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
443
diff
changeset
|
33 parser.add_argument('-u', dest = 'unitsPerPixel', help = 'number of units per pixel', default = 1., type = float) |
697
0421a5a0072c
improvemend by Adrien Lessard to choose output homography filename
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
640
diff
changeset
|
34 parser.add_argument('-o', dest = 'homographyFilename', help = 'filename of the homography matrix', default = 'homography.txt') |
476
6551a3cf1750
modified compute-homography to work with argparse
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
443
diff
changeset
|
35 parser.add_argument('--display', dest = 'displayPoints', help = 'display original and projected points on both images', action = 'store_true') |
510
b0dac840c24f
compute homography works with undistortion
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
478
diff
changeset
|
36 parser.add_argument('--intrinsic', dest = 'intrinsicCameraMatrixFilename', help = 'name of the intrinsic camera file') |
b0dac840c24f
compute homography works with undistortion
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
478
diff
changeset
|
37 parser.add_argument('--distortion-coefficients', dest = 'distortionCoefficients', help = 'distortion coefficients', nargs = '*', type = float) |
1061 | 38 parser.add_argument('--undistorted-multiplication', dest = 'undistortedImageMultiplication', help = 'undistorted image multiplication', type = float, default = 1.) |
1166
7b4d732f82b3
adding an option to use image coordinates in point-correspondence file when undistorting
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1061
diff
changeset
|
39 parser.add_argument('--undistort', dest = 'undistort', help = 'undistort the video (because features have been extracted that way)', action = 'store_true') |
7b4d732f82b3
adding an option to use image coordinates in point-correspondence file when undistorting
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1061
diff
changeset
|
40 parser.add_argument('--correspondences-imagepoints-in-image-space', dest = 'correspondencesImagePointsInImageSpace', help = 'if image points are provided in the actual image space (before undistortion)', action = 'store_true') |
538
bd1ad468e928
corrected bug and added capability to save undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
510
diff
changeset
|
41 parser.add_argument('--save', dest = 'saveImages', help = 'save the undistorted video frame (display option must be chosen)', action = 'store_true') |
476
6551a3cf1750
modified compute-homography to work with argparse
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
443
diff
changeset
|
42 |
6551a3cf1750
modified compute-homography to work with argparse
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
443
diff
changeset
|
43 args = parser.parse_args() |
151
4af774bb186d
wrote a simple script to compute homography from point correspondences and display the reprojection for visual verification
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
44 |
238
be3761a09b20
added functions to input point correspondences
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
237
diff
changeset
|
45 homography = np.array([]) |
636
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
591
diff
changeset
|
46 if args.pointCorrespondencesFilename is not None: |
476
6551a3cf1750
modified compute-homography to work with argparse
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
443
diff
changeset
|
47 worldPts, videoPts = cvutils.loadPointCorrespondences(args.pointCorrespondencesFilename) |
1166
7b4d732f82b3
adding an option to use image coordinates in point-correspondence file when undistorting
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1061
diff
changeset
|
48 if args.correspondencesImagePointsInImageSpace: |
7b4d732f82b3
adding an option to use image coordinates in point-correspondence file when undistorting
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1061
diff
changeset
|
49 videoPts = cv2.undistortPoints(videoPts.T, np.loadtxt(args.intrinsicCameraMatrixFilename), np.array(args.distortionCoefficients)).reshape(-1,2) |
238
be3761a09b20
added functions to input point correspondences
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
237
diff
changeset
|
50 homography, mask = cv2.findHomography(videoPts, worldPts) # method=0, ransacReprojThreshold=3 |
638
852f5de42d01
added functionality to read Aliaksei Tsai camera model data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
51 elif args.tsaiCameraFilename is not None: # hack using PDTV |
639
4e7925cb4f8f
modified tsai camera homography computation to avoid using os dependent temporary files
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
638
diff
changeset
|
52 from pdtv import TsaiCamera |
895
739acd338cc0
added script to extract camera info from tacal file by Lund University (T analyst)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
868
diff
changeset
|
53 cameraData = storage.loadPinholeCameraModel(args.tsaiCameraFilename) |
639
4e7925cb4f8f
modified tsai camera homography computation to avoid using os dependent temporary files
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
638
diff
changeset
|
54 camera = TsaiCamera(Cx=cameraData['Cx'], Cy=cameraData['Cy'], Sx=cameraData['Sx'], Tx=cameraData['Tx'], Ty=cameraData['Ty'], Tz=cameraData['Tz'], dx=cameraData['dx'], dy=cameraData['dy'], f=cameraData['f'], k=cameraData['k'], r1=cameraData['r1'], r2=cameraData['r2'], r3=cameraData['r3'], r4=cameraData['r4'], r5=cameraData['r5'], r6=cameraData['r6'], r7=cameraData['r7'], r8=cameraData['r8'], r9=cameraData['r9']) |
4e7925cb4f8f
modified tsai camera homography computation to avoid using os dependent temporary files
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
638
diff
changeset
|
55 homography = cvutils.computeHomographyFromPDTV(camera) |
636
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
591
diff
changeset
|
56 elif args.videoFrameFilename is not None and args.worldFilename is not None: |
476
6551a3cf1750
modified compute-homography to work with argparse
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
443
diff
changeset
|
57 worldImg = plt.imread(args.worldFilename) |
6551a3cf1750
modified compute-homography to work with argparse
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
443
diff
changeset
|
58 videoImg = plt.imread(args.videoFrameFilename) |
510
b0dac840c24f
compute homography works with undistortion
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
478
diff
changeset
|
59 if args.undistort: |
933
8ac7f61c6e4f
major rework of homography calibration, no in ideal points if correcting for distortion
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
897
diff
changeset
|
60 [map1, map2], newCameraMatrix = cvutils.computeUndistortMaps(videoImg.shape[1], videoImg.shape[0], args.undistortedImageMultiplication, np.loadtxt(args.intrinsicCameraMatrixFilename), args.distortionCoefficients) |
510
b0dac840c24f
compute homography works with undistortion
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
478
diff
changeset
|
61 videoImg = cv2.remap(videoImg, map1, map2, interpolation=cv2.INTER_LINEAR) |
897 | 62 print('Click on {} points in the video frame'.format(args.nPoints)) |
960
0c1d1eeef544
corrected bug on new computer
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
934
diff
changeset
|
63 plt.ion() |
238
be3761a09b20
added functions to input point correspondences
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
237
diff
changeset
|
64 plt.figure() |
be3761a09b20
added functions to input point correspondences
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
237
diff
changeset
|
65 plt.imshow(videoImg) |
773
bf4a1790cfac
minor bug and improvements
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
697
diff
changeset
|
66 plt.tight_layout() |
476
6551a3cf1750
modified compute-homography to work with argparse
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
443
diff
changeset
|
67 videoPts = np.array(plt.ginput(args.nPoints, timeout=3000)) |
933
8ac7f61c6e4f
major rework of homography calibration, no in ideal points if correcting for distortion
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
897
diff
changeset
|
68 if args.undistort: |
934
39691b460fca
bug correction
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
933
diff
changeset
|
69 videoPts = cvutils.newCameraProject(videoPts.T, np.linalg.inv(newCameraMatrix)).T |
897 | 70 print('Click on {} points in the world image'.format(args.nPoints)) |
238
be3761a09b20
added functions to input point correspondences
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
237
diff
changeset
|
71 plt.figure() |
be3761a09b20
added functions to input point correspondences
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
237
diff
changeset
|
72 plt.imshow(worldImg) |
773
bf4a1790cfac
minor bug and improvements
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
697
diff
changeset
|
73 plt.tight_layout() |
476
6551a3cf1750
modified compute-homography to work with argparse
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
443
diff
changeset
|
74 worldPts = args.unitsPerPixel*np.array(plt.ginput(args.nPoints, timeout=3000)) |
238
be3761a09b20
added functions to input point correspondences
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
237
diff
changeset
|
75 plt.close('all') |
be3761a09b20
added functions to input point correspondences
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
237
diff
changeset
|
76 homography, mask = cv2.findHomography(videoPts, worldPts) |
be3761a09b20
added functions to input point correspondences
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
237
diff
changeset
|
77 # save the points in file |
be3761a09b20
added functions to input point correspondences
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
237
diff
changeset
|
78 f = open('point-correspondences.txt', 'a') |
be3761a09b20
added functions to input point correspondences
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
237
diff
changeset
|
79 np.savetxt(f, worldPts.T) |
be3761a09b20
added functions to input point correspondences
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
237
diff
changeset
|
80 np.savetxt(f, videoPts.T) |
be3761a09b20
added functions to input point correspondences
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
237
diff
changeset
|
81 f.close() |
151
4af774bb186d
wrote a simple script to compute homography from point correspondences and display the reprojection for visual verification
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
82 |
238
be3761a09b20
added functions to input point correspondences
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
237
diff
changeset
|
83 if homography.size>0: |
697
0421a5a0072c
improvemend by Adrien Lessard to choose output homography filename
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
640
diff
changeset
|
84 np.savetxt(args.homographyFilename,homography) |
238
be3761a09b20
added functions to input point correspondences
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
237
diff
changeset
|
85 |
638
852f5de42d01
added functionality to read Aliaksei Tsai camera model data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
86 if args.displayPoints and args.videoFrameFilename is not None and args.worldFilename is not None and homography.size>0 and args.tsaiCameraFilename is None: |
478
d337bffd7283
Display of points in compute homography and step option to replay videos
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
476
diff
changeset
|
87 worldImg = cv2.imread(args.worldFilename) |
d337bffd7283
Display of points in compute homography and step option to replay videos
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
476
diff
changeset
|
88 videoImg = cv2.imread(args.videoFrameFilename) |
572
9c429c7efe89
added script to generate undistorted images from video
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
538
diff
changeset
|
89 if args.undistort: |
933
8ac7f61c6e4f
major rework of homography calibration, no in ideal points if correcting for distortion
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
897
diff
changeset
|
90 [map1, map2], newCameraMatrix = cvutils.computeUndistortMaps(videoImg.shape[1], videoImg.shape[0], args.undistortedImageMultiplication, np.loadtxt(args.intrinsicCameraMatrixFilename), args.distortionCoefficients) |
510
b0dac840c24f
compute homography works with undistortion
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
478
diff
changeset
|
91 videoImg = cv2.remap(videoImg, map1, map2, interpolation=cv2.INTER_LINEAR) |
538
bd1ad468e928
corrected bug and added capability to save undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
510
diff
changeset
|
92 if args.saveImages: |
bd1ad468e928
corrected bug and added capability to save undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
510
diff
changeset
|
93 cv2.imwrite(utils.removeExtension(args.videoFrameFilename)+'-undistorted.png', videoImg) |
151
4af774bb186d
wrote a simple script to compute homography from point correspondences and display the reprojection for visual verification
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
94 invHomography = np.linalg.inv(homography) |
933
8ac7f61c6e4f
major rework of homography calibration, no in ideal points if correcting for distortion
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
897
diff
changeset
|
95 projectedWorldPts = cvutils.homographyProject(worldPts.T, invHomography).T |
8ac7f61c6e4f
major rework of homography calibration, no in ideal points if correcting for distortion
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
897
diff
changeset
|
96 projectedVideoPts = cvutils.homographyProject(videoPts.T, homography).T |
8ac7f61c6e4f
major rework of homography calibration, no in ideal points if correcting for distortion
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
897
diff
changeset
|
97 if args.undistort: |
8ac7f61c6e4f
major rework of homography calibration, no in ideal points if correcting for distortion
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
897
diff
changeset
|
98 projectedWorldPts = cvutils.newCameraProject(projectedWorldPts.T, newCameraMatrix).T |
8ac7f61c6e4f
major rework of homography calibration, no in ideal points if correcting for distortion
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
897
diff
changeset
|
99 videoPts = cvutils.newCameraProject(videoPts.T, newCameraMatrix).T |
238
be3761a09b20
added functions to input point correspondences
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
237
diff
changeset
|
100 for i in range(worldPts.shape[0]): |
478
d337bffd7283
Display of points in compute homography and step option to replay videos
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
476
diff
changeset
|
101 # world image |
868
1fdafa9f6bf4
added colors more friendly for color blind people (thanks Ryan Louie!)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
773
diff
changeset
|
102 cv2.circle(worldImg,tuple(np.int32(np.round(worldPts[i]/args.unitsPerPixel))),2,cvutils.cvBlue['default']) |
1fdafa9f6bf4
added colors more friendly for color blind people (thanks Ryan Louie!)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
773
diff
changeset
|
103 cv2.circle(worldImg,tuple(np.int32(np.round(projectedVideoPts[i]/args.unitsPerPixel))),2,cvutils.cvRed['default']) |
1fdafa9f6bf4
added colors more friendly for color blind people (thanks Ryan Louie!)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
773
diff
changeset
|
104 cv2.putText(worldImg, str(i+1), tuple(np.int32(np.round(worldPts[i]/args.unitsPerPixel))+5), cv2.FONT_HERSHEY_PLAIN, 2., cvutils.cvBlue['default'], 2) |
478
d337bffd7283
Display of points in compute homography and step option to replay videos
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
476
diff
changeset
|
105 # video image |
868
1fdafa9f6bf4
added colors more friendly for color blind people (thanks Ryan Louie!)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
773
diff
changeset
|
106 cv2.circle(videoImg,tuple(np.int32(np.round(videoPts[i]))),2,cvutils.cvBlue['default']) |
1fdafa9f6bf4
added colors more friendly for color blind people (thanks Ryan Louie!)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
773
diff
changeset
|
107 cv2.circle(videoImg,tuple(np.int32(np.round(projectedWorldPts[i]))),2,cvutils.cvRed['default']) |
1fdafa9f6bf4
added colors more friendly for color blind people (thanks Ryan Louie!)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
773
diff
changeset
|
108 cv2.putText(videoImg, str(i+1), tuple(np.int32(np.round(videoPts[i])+5)), cv2.FONT_HERSHEY_PLAIN, 2., cvutils.cvBlue['default'], 2) |
238
be3761a09b20
added functions to input point correspondences
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
237
diff
changeset
|
109 cv2.imshow('video frame',videoImg) |
478
d337bffd7283
Display of points in compute homography and step option to replay videos
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
476
diff
changeset
|
110 cv2.imshow('world image',worldImg) |
151
4af774bb186d
wrote a simple script to compute homography from point correspondences and display the reprojection for visual verification
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
111 cv2.waitKey() |
346
5f75d6c23ed5
added opencv function to destroy OpenCV windows (seems to work only on Windows)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
334
diff
changeset
|
112 cv2.destroyAllWindows() |