Пример #1
0
import GameController as gc
import imgdecode as imd
import numpy as np
import cv2

con = gc.Controller()
con.connect()

keyarray = np.zeros(128, dtype=np.int)

while True:
    img = con.getDepth()
    img = imd.decode(img)
    cv2.imshow('Depth', img)

    key = cv2.waitKey(10)
    if key <= 127:
        keyarray[key] = ~keyarray[key]
        ckey = chr(key)
        if ckey.isalnum():
            if keyarray[key] != 0:
                con.KeyDown(ckey)
            else:
                con.KeyUp(ckey)
        elif key == 27:
            break

con.close()
Пример #2
0
         np.sum(
             np.square(
                 np.array(sample_position) -
                 np.array(position))))
     if (position[1] - sample_position[1]) >= 0.001:
         print("DROPPED: vertically shifted")
     elif shifted >= sigma_xy * 1.5:
         print("DROPPED: 2d shifted more than 1.5 * sigma_xy")
     else:
         image_count += 1
         print("point collected, image count: {}".format(
             image_count))
         image_filename = node_id + '_' + str(i) + '.jpg'
         image_path = os.path.join(room_dir, image_filename)
         image = con.getSpherical()
         image = imd.decode(image)
         cv2.imwrite(image_path, image)
         image_id_list.append(image_count)
         node_id_list.append(node_id)
         room_id_list.append(room_id)
         position_list.append(sample_position)
         angle_list.append(sample_angle)
         image_path_list.append(image_path)
 except:
     print("DROPPED: controller error")
     con.close()
     try:
         con = gc.Controller()
         con.connect()
         print("successfully connect to game controller")
     except:
Пример #3
0
                    sys.exit()
                if len(json_data[k])!=data_len:
                    print('Data length of key {} does not equal to {}'.format(k, data_len))
                    print('Error: .json file is not in the correct format')
                    sys.exit()

            for i in range(data_len):
                pos = json_data['position'][i]
                ang = json_data['angle'][i]
                # go to the pose
                con.setPos(pos[0], pos[1], pos[2])
                con.setRot(ang[0], ang[1], ang[2])
                # get pose
                json_data['position'][i] = con.getPos()
                json_data['angle'][i] = con.getRot()
                # take snapshot
                img = con.getSpherical()
                img = imd.decode(img)
                # save image
                img_path = json_data['image_path'][i]
                img_path = osp.join(room_dir, img_path)
                cv2.imwrite(img_path, img)

            # update some robot poses in json file
            with open(json_fname, 'w') as f:
                json.dump(json_data, f)
    finally:
       con.close()
       print('Connection end!')
       print('Program end!')
Пример #4
0
     con.setPos(x, position[1], z)
     con.setRot(angle[0], theta + quad_rotate, angle[2])
     sample_position = con.getPos()
     sample_angle = con.getRot()
     shifted = np.sqrt(np.sum(np.square(np.array(sample_position) - np.array(position))))
     if (position[1] - sample_position[1]) >= 0.001:
         print("DROPPED: vertically shifted")
     elif shifted >= sigma_xy * 1.5:
         print("DROPPED: 2d shifted more than 1.5 * sigma_xy")
     else:
         image_count += 1
         print("point collected, image count: {}".format(image_count))
         image_filename = node_id + '_' + str(i) + '.jpg'
         image_path = os.path.join(room_dir, image_filename)
         image = con.getSpherical()
         image = imd.decode(image)
         cv2.imwrite(image_path, image)
         image_id_list.append(image_count)
         node_id_list.append(node_id)
         room_id_list.append(room_id)
         position_list.append(sample_position)
         angle_list.append(sample_angle)
         image_path_list.append(image_path)
 except:
     print("DROPPED: controller error")
     con.close()
     try:
         con = gc.Controller()
         con.connect()
         print("successfully connect to game controller")
     except:
Пример #5
0
# use 'connect' to connect to unity
con.connect()  # defalut is set to ip=127.0.0.1 port=4567 timeout=10

# use 'KeyDown' 'KeyUp' 'KeyPress' to pass key event to unity
con.KeyPress('W')
con.KeyUp('A')
con.KeyDown('S')
con.KeyUp('S')

# use 'setSpeed' and 'setRotateSpeed' to pass setting to unity
con.setSpeed(10)  # or con.Speed(10)
con.setRotateSpeed(20)  # or con.RSpeed(20)

# use 'getFirstView' 'getThirdView' to get image from unity
# ::NOTICE:: the return image is encoded as PNG format
# you need to use 'decode' function in 'imgdecode' module to decode it to cvmat form
# or you can just write your own decode function like 'decode' which use 'np.fromstring' and 'cv2.imdecode'
import imgdecode as imd

data = con.getFirstView()

img = imd.decode(data)
#  or
arr = np.fromstring(data, up.uint8)
img = cv2.imdecode(arr, cv2.IMREAD_COLOR)
# then you can use other cv2 function to do process to your image
cv2.imshow('test', img)

# if any error occerred then you can check log file
Пример #6
0
# use 'KeyDown' 'KeyUp' 'KeyPress' to pass key event to unity
con.KeyPress('W')
con.KeyUp('A')
con.KeyDown('S')
con.KeyUp('S')

# use 'setSpeed' and 'setRotateSpeed' to pass setting to unity
con.setSpeed(10)  # or con.Speed(10)
con.setRotateSpeed(20)  # or con.RSpeed(20)

# use 'getFirstView' 'getThirdView' to get image from unity
# ::NOTICE:: the return image is encoded as PNG format
# you need to use 'decode' function in 'imgdecode' module to decode it to cvmat form
# or you can just write your own decode function like 'decode' which use 'np.fromstring' and 'cv2.imdecode'
import imgdecode as imd

data = con.getFirstView()

img = imd.decode(data)
#  or
arr = np.fromstring(data, up.uint8)
img = cv2.imdecode(arr, cv2.IMREAD_COLOR)
# then you can use other cv2 function to do process to your image
cv2.imshow('test', img)



# if any error occerred then you can check log file