-
Notifications
You must be signed in to change notification settings - Fork 2
/
pic_collection.py
70 lines (52 loc) · 2.08 KB
/
pic_collection.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import cozmo
from cozmo.util import degrees
import os
import cv2
import numpy as np
import img_processing as imgPr
import PIL
from PIL import Image, ImageOps
IMG_DIR = 'cozmo-imgs'
def get_in_position(robot: cozmo.robot.Robot):
robot.set_lift_height(0).wait_for_completed()
robot.set_head_angle(degrees(15.0), in_parallel = True).wait_for_completed()
def take_an_img(robot: cozmo.robot.Robot, img_path: str):
robot.camera.image_stream_enabled = True # Enabling Cozmo Camera
get_in_position(robot)
img = robot.world.latest_image
if img is not None:
annotated = img.annotate_image()
converted = annotated.convert()
img = ImageOps.grayscale(converted)
img = np.array(img)
imgPr.save_img(img, img_path)
print('IMG TAKEN')
else:
print('CANNOT TAKE IMG')
def take_imgs(robot: cozmo.robot.Robot, num_pic=15, img_dir=IMG_DIR, is_stitch=True):
robot.camera.image_stream_enabled = True # Enabling Cozmo Camera
get_in_position(robot)
if not os.path.exists(img_dir): os.makedirs(img_dir)
currAngle = 0.0
rotateAngle = 360.0/num_pic
for i in range(num_pic):
img = robot.world.latest_image
if img is not None:
annotated = img.annotate_image()
converted = annotated.convert()
img = ImageOps.grayscale(converted)
img = np.array(img)
imgPr.save_img(img, os.path.join(img_dir, f'{i}.jpg'))
robot.turn_in_place(degrees(rotateAngle), speed=degrees(45)).wait_for_completed()
currAngle += rotateAngle
else:
get_in_position(robot)
print('CANNOT TAKE IMG')
#stich panorama togehter from our images collected
if is_stitch: imgPr.stitching()
def collect_imgs(num_pic: int=20, img_dir: str='./cozmo-dataset'):
cozmo.run_program(lambda x : take_imgs(x, num_pic, img_dir, False))
def collect_an_img(img_name: str):
cozmo.run_program(lambda x : take_an_img(x, img_name))
if __name__ == '__main__':
collect_imgs(num_pic=72, img_dir='./model/data/19')