示例#1
0
def image_with_single_person():
    URL = ('https://github.com/oarriaga/altamira-data/releases/download'
           '/v0.10/single_person_test_pose.png')
    filename = os.path.basename(URL)
    fullpath = get_file(filename, URL, cache_subdir='paz/tests')
    image = load_image(fullpath)
    return image
示例#2
0
def image_with_YCB_objects():
    URL = ('https://github.com/oarriaga/altamira-data/releases/download'
           '/v0.9.1/image_with_YCB_objects.jpg')
    filename = os.path.basename(URL)
    fullpath = get_file(filename, URL, cache_subdir='paz/tests')
    image = load_image(fullpath)
    return image
示例#3
0
文件: database.py 项目: oarriaga/paz
 def load_data(self, path, label, with_crop=True):
     data = []
     for filename in os.listdir(path):
         face = load_image(os.path.join(path, filename))
         if with_crop:
             croped_face = self.crop(face)
         sample = {'image': croped_face, 'label': label}
         data.append(sample)
     return data
示例#4
0
def predict(target_dir: pathlib.Path) -> Dict[str, np.ndarray]:
    results = {}
    detect = EmotionDetector()
    for i, img_file in enumerate(map(str, target_dir.glob("*.png"))):
        image = load_image(img_file)
        predictions = detect(image)
        if len(predictions) != 1:
            continue

        print(f"{i:05d} {img_file}", predictions[0][0].tolist())
        results[img_file] = predictions[0][0]

    return results
示例#5
0
import argparse
from pipelines import DetectGMMKeypointNet2D
from paz.backend.image import show_image, load_image

description = 'Demo for visualizing uncertainty in probabilistic keypoints'
parser = argparse.ArgumentParser(description=description)
parser.add_argument('-p', '--path', type=str, help='Path to image')
args = parser.parse_args()

pipeline = DetectGMMKeypointNet2D()
image = load_image(args.path)
inferences = pipeline(image)
show_image(inferences['image'])
show_image(inferences['contours'][0])
示例#6
0
文件: demo.py 项目: oarriaga/paz
        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)
示例#7
0
import os
from tensorflow.keras.utils import get_file
from paz.backend.image import load_image, show_image
from paz.applications import MinimalHandPoseEstimation


URL = ('https://github.com/oarriaga/altamira-data/releases/download'
       '/v0.14/image_with_hand.png')
filename = os.path.basename(URL)
fullpath = get_file(filename, URL, cache_subdir='paz/tests')
image = load_image(fullpath)

detect = MinimalHandPoseEstimation(right_hand=False)
inferences = detect(image)

image = inferences['image']
show_image(image)
示例#8
0
import os
from paz.abstract import SequentialProcessor
from paz.backend.image import show_image, load_image
import paz.processors as pr
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.utils import get_file

# let's download a test image and put it inside our PAZ directory
IMAGE_URL = ('https://github.com/oarriaga/altamira-data/releases/download'
             '/v0.9/image_augmentation.png')
filename = os.path.basename(IMAGE_URL)
image_fullpath = get_file(filename, IMAGE_URL, cache_subdir='paz/tutorials')

# we load the original image and display it
image = load_image(image_fullpath)
show_image(image)

# We construct a data augmentation pipeline using the built-in PAZ processors:
augment = SequentialProcessor()
augment.add(pr.RandomContrast())
augment.add(pr.RandomBrightness())
augment.add(pr.RandomSaturation())

# We can now apply our pipeline as a normal function:
for _ in range(5):
    image = load_image(image_fullpath)
    # use it as a normal function
    image = augment(image)
    show_image(image)
示例#9
0
def test_load_image_shape_with_4_channels(image_with_face_fullpath):
    image = opencv_image.load_image(image_with_face_fullpath, 4)
    assert len(image.shape) == 3
    assert image.shape[-1] == 4
示例#10
0
def test_passes(image_with_face_fullpath):
    with pytest.raises(Exception):
        opencv_image.load_image(image_with_face_fullpath, 2)
        opencv_image.load_image(image_with_face_fullpath, 5)
示例#11
0
from paz.pipelines import DetectSingleShot
from paz.models.detection import SSD300
from paz.backend.image import load_image, show_image, write_image


class SSD300SolarPanel(DetectSingleShot):
    def __init__(self,
                 weights_path,
                 score_thresh=0.50,
                 nms_thresh=0.45,
                 draw=True):
        class_names = ['background', 'solar_panel']
        model = SSD300(len(class_names), None, None)
        model.load_weights(weights_path)
        super(SSD300SolarPanel, self).__init__(model,
                                               class_names,
                                               score_thresh,
                                               nms_thresh,
                                               draw=draw)


# weights_path = 'trained_models/SSD300/weights.172-3.15.hdf5'
weights_path = 'trained_models/SSD300/weights.141-2.66.hdf5'
detect = SSD300SolarPanel(weights_path)
image_paths = glob.glob('datasets/test_solar_panel/*.jpg')
for image_arg, image_path in enumerate(image_paths):
    image = load_image(image_path)
    results = detect(image)
    # show_image(results['image'])
    write_image('results/image_%s.png' % image_arg, results['image'])
示例#12
0
def test_load_image_shape_with_1_channel(image_with_face_fullpath):
    image = opencv_image.load_image(image_with_face_fullpath, 1)
    assert len(image.shape) == 2
示例#13
0
parser.add_argument('-p', '--image_path', type=str,
                    help='full image path used for the pipelines')
parser.add_argument('-c', '--camera_id', type=str,
                    help='Camera/device ID')
parser.add_argument('-d', '--dataset', type=str, default='COCO',
                    choices=['VOC', 'COCO', 'YCBVideo', 'FAT'],
                    help='Dataset name')
args = parser.parse_args()



name_to_model = {'VOC': SSD300VOC, 'FAT': SSD300FAT, 'COCO': SSD512COCO,
                 'YCBVideo': SSD512YCBVideo}


image = load_image(args.image_path)
H = 1000
W = int((H / image.shape[0]) * image.shape[1])
# image = resize_image(image, (W, H))

focal_length = image.shape[1]
image_center = (image.shape[1] / 2.0, image.shape[0] / 2.0)
camera = Camera(args.camera_id)
camera.distortion = np.zeros((4, 1))
camera.intrinsics = np.array([[focal_length, 0, image_center[0]],
                              [0, focal_length, image_center[1]],
                              [0, 0, 1]])

pipeline_A = DetectMiniXceptionFER([args.offset, args.offset])
pipeline_B = DetectFaceKeypointNet2D32()
pipeline_C = HeadPoseKeypointNet2D32(camera)
示例#14
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()
"""
示例#15
0
import os
import numpy as np
from paz.abstract import SequentialProcessor
from paz.backend.image import show_image, load_image
import paz.processors as pr
from tensorflow.keras.utils import get_file

# let's download a test image and put it inside our PAZ directory
IMAGE_URL = ('https://github.com/oarriaga/altamira-data/releases/download'
             '/v0.9/object_detection_augmentation.png')
filename = os.path.basename(IMAGE_URL)
image_fullpath = get_file(filename, IMAGE_URL, cache_subdir='paz/tutorials')

# The x_min, y_min are the **noramlized** coordinates
# of **top-left** bounding-box corner.
H, W = load_image(image_fullpath).shape[:2]

# The x_max, y_max are the **normalized** coordinates
class_names = ['background', 'human', 'horse']
box_data = np.array([[200 / W, 60 / H, 300 / W, 200 / H, 1],
                     [100 / W, 90 / H, 400 / W, 300 / H, 2]])

# Let's visualize our boxes!
# first we transform our numpy array into our built-in ``Box2D`` messages
to_boxes2D = pr.ToBoxes2D(class_names)
denormalize = pr.DenormalizeBoxes2D()
boxes2D = to_boxes2D(box_data)
image = load_image(image_fullpath)
boxes2D = denormalize(image, boxes2D)
draw_boxes2D = pr.DrawBoxes2D(class_names)
show_image(draw_boxes2D(image, boxes2D))
示例#16
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)


image = load_image('images/zed_left_1011.png')
image = image[250:800, 250:850, :]
H, W, num_channels = image.shape
# image = resize_image(image, (W * 20, H * 20))
quick_pose(image)

image = load_image('images/MicrosoftTeams-image.png')
quick_pose(image)

image = load_image('images/zed_left_705.png')
image = image[250:1080, 250:1400, :]
quick_pose(image)


image = load_image('images/zed_left_792.png')
# image = image[280:1060, 320:1060, :]
示例#17
0
文件: rock.py 项目: oarriaga/paz
if __name__ == "__main__":
    from paz.backend.image import show_image, load_image
    from paz.backend.camera import Camera
    from paz.pipelines import RGBMaskToPowerDrillPose6D
    from paz.pipelines import SSD300FAT

    def approximate_intrinsics(image):
        image_size = image.shape[0:2]
        focal_length = image_size[1]
        image_center = (image_size[1] / 2.0, image_size[0] / 2.0)
        camera_intrinsics = np.array([[focal_length, 0, image_center[0]],
                                      [0, focal_length, image_center[1]],
                                      [0, 0, 1]])
        return camera_intrinsics

    image = load_image('images/test_image2.jpg')
    camera = Camera(device_id=0)
    camera.intrinsics = approximate_intrinsics(image)
    camera.distortion = np.zeros((4))

    estimate_pose = RGBMaskToPowerDrillPose6D(camera, 0.15, draw=False)
    pipeline = PIX2POSE_ROCK(estimate_pose, [0.5, 0.5], ['035_power_drill'],
                             True)
    detect = SSD300FAT(0.5, 0.45, draw=False)

    boxes2D = detect(image)['boxes2D']
    inferences = pipeline(image, boxes2D)
    predicted_image = inferences['image']
    show_image(predicted_image)