model_pinhole.set_image_shape(450, 450)
model_pinhole.set_matrix(250, 250, 0, 300, 300)

model_fisheye = pb.CameraUniversalOmni()
model_fisheye.load(os.path.join(data_path, "front.yaml"))

transform = pb.NarrowToWideFovPtoP(narrow_model=model_pinhole,
                                   wide_model=model_fisheye)

image_fisheye = pb.load_planar(os.path.join(data_path, "front_hike.jpg"),
                               np.uint8)
image_pinhole = image_fisheye.createNew(model_pinhole.width,
                                        model_pinhole.height)

image_distorter = transform.create_image_distort(
    pb.ImageType(image_fisheye.getImageType()))

image_distorter.apply(image_fisheye, image_pinhole)

# Make the fisheye image smaller so that it's easier to manage
small_fisheye = cv2.resize(pb.boof_to_ndarray(image_fisheye),
                           None,
                           fx=0.5,
                           fy=0.5,
                           interpolation=cv2.INTER_LINEAR)

cv2.imshow("Fisheye", small_fisheye[..., [2, 1, 0]])
cv2.imshow("Pinhole", pb.boof_to_ndarray(image_pinhole)[..., [2, 1, 0]])

# Rotate the camera so that it's focused on the path behind and rotated to appear "up"
transform.set_rotation_wide_to_narrow(
Beispiel #2
0
 def get_image_type(self):
     return pyboof.ImageType(self.java_image_type)
                             np.uint8)
image1 = pb.load_single_band("../data/example/stereo/chair01_right.jpg",
                             np.uint8)

# Load stereo rectification
stereo_param = pb.StereoParameters()
stereo_param.load(
    "../data/example/calibration/stereo/Bumblebee2_Chess/stereo.xml")

# Rectify and undistort the images
model_rectifier = pb.StereoRectification(stereo_param.left, stereo_param.right,
                                         stereo_param.right_to_left)
model_rectifier.all_inside_left()

distort_left = model_rectifier.create_distortion(
    pb.ImageType(image0.getImageType()), True)
distort_right = model_rectifier.create_distortion(
    pb.ImageType(image0.getImageType()), False)

rect0 = image0.createSameShape()
rect1 = image1.createSameShape()

distort_left.apply(image0, rect0)
distort_right.apply(image1, rect1)

# Configure and compute disparity
config = pb.ConfigStereoDisparity()
config.minDisparity = 10
config.maxDisparity = 60

factory = pb.FactoryStereoDisparity(np.uint8)
Beispiel #4
0
# Enable use of memory mapped files for MUCH faster conversion between some python and boofcv data types
pb.init_memmap(5)

# Load two images
image0 = pb.load_single_band("../data/example/stereo/chair01_left.jpg", np.uint8)
image1 = pb.load_single_band("../data/example/stereo/chair01_right.jpg", np.uint8)

# Load stereo rectification
stereo_param = pb.StereoParameters()
stereo_param.load("../data/example/calibration/stereo/Bumblebee2_Chess/stereo.yaml")

# Rectify and undistort the images
model_rectifier = pb.StereoRectification(stereo_param.left, stereo_param.right, stereo_param.right_to_left)
model_rectifier.all_inside_left()

distort_left = model_rectifier.create_distortion(pb.ImageType(image0.getImageType()), True)
distort_right = model_rectifier.create_distortion(pb.ImageType(image0.getImageType()), False)

rect0 = image0.createSameShape()
rect1 = image1.createSameShape()

distort_left.apply(image0, rect0)
distort_right.apply(image1, rect1)

# Configure and compute disparity
config = pb.ConfigDisparityBMBest5()
config.disparityMin = 10
config.disparityRange = 50
config.errorType = pb.DisparityError.CENSUS

factory = pb.FactoryStereoDisparity(np.uint8)