Demo entry 6716752

python

   

Submitted by anonymous on Feb 22, 2018 at 00:06
Language: Python. Code size: 1.4 kB.

# Author: Markus Solbach (solbach@eecs.yorku.ca)
from websocket import create_connection
import io, sys, json, base64
from json import dumps

try:
    from PIL import Image
except ImportError:
    print("PIL not installed on system. Running lightweight example.")

# Create Connection
ws = create_connection("ws://localhost:8888/api/")

# Prepare Data
cam_parameter = {
    'x':-0.911,
    'y':1.238,
    'z':-4.1961,
    'qw':-0.0544,
    'qx':-0.307,
    'qy':0.9355,
    'qz':0.16599
}

# Mandatory
parameter = {
    'ID':'782fec97-83c0-42d2-b09b-7d3fe37b2317b',
    'light_fixed':'true',
    'random_cam': 'true',
    'cam_x':-0.911,
    'cam_y':1.238,
    'cam_z':-4.1961,
    'cam_qw':-0.0544,
    'cam_qx':-0.307,
    'cam_qy':0.9355,
    'cam_qz':0.16599
}

json_params = dumps(parameter, indent=2)
ws.send(json_params)

while True:
    result = json.loads(ws.recv())
    print("Job Status: {0}".format(result['status']))
    if result['status'] == "SUCCESS":
        break
    elif "FAILURE" in result['status'] or "INVALID" in result['status']:
        sys.exit()

image_base64 = result['image']
image_decoded = base64.b64decode(image_base64)

random_cam_param = result['cam_pose']
print(random_cam_param)

fh = open("imageToSave.png", "wb")
fh.write(image_decoded)
fh.close()

if 'PIL' in sys.modules:
    im = Image.open(io.BytesIO(image_decoded))
    im.show()

ws.close()

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).