Beispiel #1
0
def interpolate_probability(probability, shape):
    normalization_constant = np.max(probability)
    probability = probability / normalization_constant
    probability = probability * 255.0
    probability = probability.astype('uint8')
    probability = resize_image(probability, shape)
    probability = probability / 255.0
    probability = probability * normalization_constant
    return probability
Beispiel #2
0
def quick_pose(image):
    image = resize_image(image, (128, 128))
    # show_image(resize_image(image, (256 * 3, 256 * 3)))
    keypoints = estimate_keypoints(image)
    points2D = keypoints['points2D']
    points3D = keypoints['points3D']
    # points3D[:, 2:3] = 0.0
    points2D = denormalize_points2D(points2D, 128, 128)
    success, rotation, translation = predict_pose(points3D, points2D)
    quaternion = rotation_vector_to_quaternion(rotation)
    pose6D = Pose6D(quaternion, translation, 'solar_panel')
    poses6D = [pose6D]
    # show_image(image)
    points = [[points2D, points3D]]
    image = draw_masks(image, points, object_sizes)
    image = image.astype('float')
    image = draw_poses6D(image, poses6D, cube_points3D, camera_intrinsics)
    image = image.astype('uint8')
    image = resize_image(image, (256 * 3, 256 * 3))
    show_image(image)
Beispiel #3
0
def test_resize_image(load_image, image_shape, rgb_channel, resized_shape):
    test_image = load_image(image_shape, rgb_channel)
    width, height, size = resized_shape(test_image)
    resized_image = opencv_image.resize_image(test_image, (width, height))
    assert resized_image.size == size
Beispiel #4
0
from paz.backend.image import show_image, load_image, resize_image
from paz.backend.camera import Camera
from paz.pipelines import PIX2YCBTools6D

image = load_image('images/unit_test.png')
# image = load_image('images/group_photo_onefourth.png')
print(image.shape)
camera = Camera()
camera.intrinsics_from_HFOV(55, image.shape)
pipeline = PIX2YCBTools6D(camera)

inferences = pipeline(image)
predicted_image = inferences['image']
H, W = predicted_image.shape[:2]
predicted_image = resize_image(predicted_image, (W * 3, H * 3))
show_image(predicted_image)

"""
from paz.backend.camera import VideoPlayer
camera = Camera(4)
camera.intrinsics_from_HFOV(55)
pipeline = PIX2YCBTools6D(camera, resize=False)
player = VideoPlayer((640 * 3, 480 * 3), pipeline, camera)
player.run()
"""
Beispiel #5
0
plt.title('mean face')
plt.show()

plt.plot(eigenvalues[:30])
plt.title('eigenvalues')
plt.show()

# plot post-processed eigenfaces
postprocess = PostrocessEigenFace(shape=(48, 48))
postprocessed_eigenfaces = np.zeros((len(eigenfaces), 48, 48, 1))
for arg, eigenface in enumerate(eigenfaces):
    postprocessed_eigenfaces[arg, :, :, 0] = postprocess(eigenface)
mosaic = make_mosaic(postprocessed_eigenfaces[:80], (10, 8))
plt.imshow(mosaic)
plt.title('first 80 eigenfaces')
plt.show()

# project new images to eigenspace
faces, num_projected_faces = np.expand_dims(np.moveaxis(faces, -1, 0), -1), 100
project = CalculateFaceWeights(eigenfaces, mean_face, with_crop=False)
images, weights = [], np.zeros((num_projected_faces, len(eigenvalues)))
for face_arg, face in enumerate(faces[:num_projected_faces]):
    images.append(resize_image(face, (20, 20)).astype('uint8'))
    weights[face_arg, :] = project(face)

# plot embeddings
plot = PlotEmbeddings(epsilon=0)
plot(weights[:, :2], images)
plt.title('embeddings projections')
plt.show()
Beispiel #6
0
# from meters to milimiters
# object_sizes = renderer.mesh.mesh.extents * 100
object_sizes = renderer.mesh.mesh.extents * 10000
print(object_sizes)
model = UNET_VGG16(3, image_shape, freeze_backbone=True)
model.load_weights(
    'experiments/UNET-VGG16_RUN_00_04-04-2022_12-29-44/model_weights.hdf5')
# model.load_weights('experiments/UNET-VGG16_RUN_00_06-04-2022_11-20-18/model_weights.hdf5')
# model.load_weights('experiments/UNET-VGG16_RUN_00_07-04-2022_13-28-04/model_weights.hdf5')
# estimate_pose = RGBMaskToPose6D(model, object_sizes, camera, draw=True)
# estimate_pose = SingleInferencePIX2POSE6D(model, object_sizes, camera)
estimate_pose = SingleInstancePIX2POSE6D(model, object_sizes, camera)

image, alpha, RGBA_mask = renderer.render()
image = np.copy(image)  # TODO: renderer outputs unwritable numpy arrays
show_image(image)
results = estimate_pose(image)
show_image(results['image'])

for arg in range(100):
    image, alpha, RGBA_mask = renderer.render()
    RGBA = concatenate_alpha_mask(image, alpha)
    background = make_random_plain_image(image.shape)
    image_with_background = blend_alpha_channel(RGBA, background)
    results = estimate_pose(image_with_background.copy())
    image = np.concatenate(
        [image_with_background, RGBA_mask[..., 0:3], results['image']], axis=1)
    H, W = image.shape[:2]
    image = resize_image(image, (W * 3, H * 3))
    show_image(image)
Beispiel #7
0
        super(PostprocessSegmentation, self).__init__()
        self.add(pr.UnpackDictionary(['image_path']))
        self.add(pr.LoadImage())
        self.add(pr.ResizeImage(model.input_shape[1:3]))
        self.add(pr.ConvertColorSpace(pr.RGB2BGR))
        self.add(pr.SubtractMeanImage(pr.BGR_IMAGENET_MEAN))
        self.add(pr.ExpandDims(0))
        self.add(pr.Predict(model))
        self.add(pr.Squeeze(0))
        self.add(Round())
        self.add(MasksToColors(model.output_shape[-1], colors))
        self.add(pr.DenormalizeImage())
        self.add(pr.CastImage('uint8'))
        self.add(ResizeImageWithNearestNeighbors((1024, 512)))
        # self.add(pr.ShowImage())


num_classes = len(data_manager.class_names)
input_shape = (128, 128, 3)
model = UNET_VGG16(num_classes, input_shape, 'imagenet', activation='softmax')
post_process = PostprocessSegmentation(model)
model.load_weights(args.weights_path)

for sample in data:
    masks = post_process(sample)
    image = load_image(sample['image_path'])
    image = resize_image(image, (1024, 512))
    image_with_masks = ((0.6 * image) + (0.4 * masks)).astype("uint8")
    # image_and_masks = np.concatenate([image, masks], axis=1)
    show_image(image_with_masks)