Skip to content

Commit 2068ccf

Browse files
committed
add new files
1 parent 6355a7e commit 2068ccf

27 files changed

+683
-1
lines changed

get_projection_maps.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
"""
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
Manually select points to get the projection map
4+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5+
"""
6+
import argparse
7+
import os
8+
import numpy as np
9+
import cv2
10+
from surround_view import FisheyeCameraModel, PointSelector, display_image
11+
import surround_view.param_settings as settings
12+
13+
14+
def get_projection_map(camera_model, image, dst_points):
15+
image = camera_model.undistort(image)
16+
gui = PointSelector(image, title=camera_model.camera_name)
17+
choice = gui.loop()
18+
if choice > 0:
19+
src = np.float32(gui.keypoints)
20+
dst = np.float32(dst_points)
21+
camera_model.project_matrix = cv2.getPerspectiveTransform(src, dst)
22+
image = camera_model.project(image)
23+
24+
ret = display_image("Bird's View", image)
25+
if ret > 0:
26+
return True
27+
if ret < 0:
28+
cv2.destroyAllWindows()
29+
30+
return False
31+
32+
33+
parser = argparse.ArgumentParser()
34+
parser.add_argument("-camera", required=True,
35+
choices=["front", "back", "left", "right"],
36+
help="The camera view to be projected")
37+
parser.add_argument("-scale", nargs="+", default=None,
38+
help="scale the undistorted image")
39+
parser.add_argument("-shift", nargs="+", default=None,
40+
help="shift the undistorted image")
41+
args = parser.parse_args()
42+
43+
if args.scale is not None:
44+
scale = [float(x) for x in args.scale]
45+
else:
46+
scale = (1.0, 1.0)
47+
48+
if args.shift is not None:
49+
shift = [float(x) for x in args.shift]
50+
else:
51+
shift = (0, 0)
52+
53+
camera_name = args.camera
54+
camera_file = os.path.join(os.getcwd(), "yaml", camera_name + ".yaml")
55+
image_file = os.path.join(os.getcwd(), "images", camera_name + ".png")
56+
image = cv2.imread(image_file)
57+
dst_points = settings.dst_points[camera_name]
58+
camera = FisheyeCameraModel(camera_file, camera_name)
59+
camera.set_scale_and_shift(scale, shift)
60+
success = get_projection_map(camera, image, dst_points)
61+
if success:
62+
print("saving projection matrix to yaml")
63+
64+
else:
65+
print("failed to compute the projection map")

get_weight_matrices.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import os
2+
import numpy as np
3+
import cv2
4+
from PIL import Image
5+
from surround_view import FisheyeCameraModel, display_image, BirdView
6+
7+
8+
names = ["front", "back", "left", "right"]
9+
images = [os.path.join(os.getcwd(), "images", name + ".png") for name in names]
10+
yamls = [os.path.join(os.getcwd(), "yaml", name + ".yaml") for name in names]
11+
camera_models = [FisheyeCameraModel(camera_file, camera_name)
12+
for camera_file, camera_name in zip (yamls, names)]
13+
14+
projected = []
15+
for image_file, camera in zip(images, camera_models):
16+
img = cv2.imread(image_file)
17+
img = camera.undistort(img)
18+
img = camera.project(img)
19+
img = camera.flip(img)
20+
projected.append(img)
21+
22+
birdview = BirdView()
23+
Gmat, Mmat = birdview.get_weights(projected)
24+
projected2 = birdview.make_luminance_balance(projected)
25+
birdview.stitch_all_parts(projected2)
26+
birdview.make_white_balance()
27+
birdview.copy_car_image()
28+
ret = display_image("BirdView Result", birdview.image)
29+
if ret > 0:
30+
Image.fromarray((Gmat * 255).astype(np.uint8)).save("weights.png")
31+
Image.fromarray(Mmat.astype(np.uint8)).save("masks.png")

images/back.png

1.32 MB
Loading

images/car.png

42.8 KB
Loading

images/front.png

1.28 MB
Loading

images/left.png

1.32 MB
Loading

images/right.png

1.29 MB
Loading

masks.png

8 KB
Loading

surround_view/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .fisheye_camera import FisheyeCameraModel
2+
from .birdview import BirdView
3+
from .gui import display_image, PointSelector
348 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)