Perspective transformation is a technique (geometric transformation) that can be used to generate a top view (birds eye) from a scene. Can be useful by giving more insights into the objects of interest. Usually, to find the right perspective transform much experimentation is needed, this is where this tool can support.
Left: red dots-input transfom, blue dots-desired transform , Right: Warped image
- load and save the configuration for input, and output perspectives;
- stores the transformation matrix (direct / inverse) in *.npy format, which can be easily loaded in the desired program;
- input/output point pairs (4x2) are defined with the mouse, and the position of the points is editable, to find accurate / desired values.
- install requirements (pip install numpy, opencv-python, glob);
- run python perspective_transform_tool.py, which will load the demo;
- put your video file in the data folder (for this work the CARLA simulator was used [1]), or edit cfg.json file to point to the right location. In case the input is an image, it can be loaded by editing the
"files": "*.mp4"
to"files": "*.png"
in thecfg.json
file. There is a test file in thedata
folder for testing. - use the menu to generate the transform, hit 's' to save
- load in your project the transformation matrices, and use it for something great
...
t_mat = numpy.load('transform.npy')
# apply perspective transform
val = cv2.perspectiveTransform (pts, t_mat)
...
/Enjoy