示例#1
0
def sub_callback_graphics2(results):
    claims = []
    claims.append({
        "type":
        "retract",
        "fact": [
            ["id", get_my_id_str()],
            ["id", "2"],
            ["postfix", ""],
        ]
    })
    if results:
        for result in results:
            claims.append({
                "type":
                "claim",
                "fact": [
                    ["id", get_my_id_str()],
                    ["id", "2"],
                    ["text", "draw"],
                    ["text", "graphics"],
                    ["text", str(result["graphics"])],
                    ["text", "on"],
                    ["integer", str(result["displayId"])],
                ]
            })
    batch(claims)
示例#2
0
def init_claim():
    claims = [
        {"type": "retract", "fact": [["id", get_my_id_str()], ["postfix", ""]]},
        {"type": "claim", "fact": [
            ["id", get_my_id_str()],
            ["id", "0"],
            ["text", "camera"],
            ["integer", str(CAMERA_ID)],
            ["text", "has"],
            ["text", "resolution"],
            ["integer", str(CAM_WIDTH)],
            ["integer", str(CAM_HEIGHT)],
        ]},
        {"type": "claim", "fact": [
            ["id", get_my_id_str()],
            ["id", "0"],
            ["text", "camera"],
            ["integer", str(CAMERA_ID)],
            ["text", "cv"],
            ["text", "threshold"],
            ["text", "is"],
            ["integer", str(THRESHOLD)],
        ]},
        {"type": "claim", "fact": [
            ["id", get_my_id_str()],
            ["id", "0"],
            ["text", "camera"],
            ["integer", str(CAMERA_ID)],
            ["text", "frame"],
            ["text", "at"],
            ["text", "http://{}:{}/src/files/cv-frame.jpg".format(get_host_ip(), PORT)],
        ]},
    ]
    batch(claims)
示例#3
0
def claim_data(data):
    global last_data, CAMERA_ID
    if len(last_data) == 0 and len(data) == 0:
        if DEBUG:
            logging.info("empty data again, skipping claim")
        return
    last_data = data
    currentTimeMs = int(round(time.time() * 1000))
    claims = [
        {"type": "retract", "fact": [["id", get_my_id_str()], ["id", "1"], ["postfix", ""]]}
    ]
    for datum in data:
        x = int(sum([d[0][0] for d in datum])/len(datum))
        y = int(sum([d[0][1] for d in datum])/len(datum))
        if DEBUG:
            logging.info((x, y))
        claims.append({"type": "claim", "fact": [
            ["id", get_my_id_str()],
            ["id", "1"],
            ["text", "laser"],
            ["text", "seen"],
            ["text", "at"],
            ["integer", str(x)],
            ["integer", str(y)],
            ["text", "@"],
            ["integer", str(currentTimeMs)],
            ["text", "on"],
            ["text", "camera"],
            ["integer", CAMERA_ID],
        ]})
    batch(claims)
def sub_callback_laser_dots(results):
    global lastLastPosition, MODE, DRAW_TARGET
    claims = []
    claims.append({
        "type": "retract", "fact": [
            ["id", get_my_id_str()],
            ["id", "2"],
            ["postfix", ""],
        ]
    })
    if results and len(results) > 0:
        result = results[0]
        lastLastPosition = [int(result["x"]), int(result["y"])]
        if MODE in ["0", "1", "2", "3"]:
            ill = Illumination()
            ill.stroke(255, 0, 255, 128)
            ill.fill(255, 0, 255, 100)
            current_corner = int(MODE)
            poly = regionPoints[:current_corner] + [lastLastPosition]
            projected_poly = list(map(lambda p: project(LASER_CAMERA_ID, p[0], p[1]), poly))
            ill.polygon(projected_poly)
            SIZE = 5
            for pt in projected_poly:
                ill.ellipse(pt[0] - SIZE, pt[1] - SIZE, SIZE * 2, SIZE * 2)
            claims.append(ill.to_batch_claim(get_my_id_str(), "2", DRAW_TARGET))
    else:
        lastLastPosition = None
    batch(claims)
示例#5
0
def show_winner():
    global PLAYER_REGIONS, WINNER
    claims = []
    claims.append({
        "type":
        "retract",
        "fact": [
            ["id", get_my_id_str()],
            ["id", "1"],
            ["postfix", ""],
        ]
    })
    if WINNER in PLAYER_REGIONS and PLAYER_REGIONS[WINNER] is not None:
        p1 = project(LASER_CAMERA_ID, PLAYER_REGIONS[WINNER]["x2"],
                     PLAYER_REGIONS[WINNER]["y2"])
        p2 = project(LASER_CAMERA_ID, PLAYER_REGIONS[WINNER]["x3"],
                     PLAYER_REGIONS[WINNER]["y3"])
        logging.error("P1 P2")
        logging.error(p1)
        logging.error(p2)
        ill = Illumination()
        ill.push()
        ill.translate(p1[0], p1[1])
        ill.rotate(
            math.atan2(p2[1] - p1[1], p2[0] - p1[0]) +
            random.uniform(-0.1, 0.1))
        ill.fontsize(40)
        ill.fontcolor(255, 255, 0)
        ill.text(0, 0, "WINNER!")
        ill.pop()
        claims.append(ill.to_batch_claim(get_my_id_str(), "1", "global"))
    batch(claims)
示例#6
0
def show_scores():
    global PLAYER_REGIONS, SCORES
    logging.error("SHOWING SCORES")
    logging.error(SCORES)
    logging.error(PLAYER_REGIONS)
    claims = []
    claims.append({
        "type":
        "retract",
        "fact": [
            ["id", get_my_id_str()],
            ["id", "1"],
            ["postfix", ""],
        ]
    })
    for player_id in SCORES:
        if player_id in PLAYER_REGIONS and PLAYER_REGIONS[
                player_id] is not None:
            r = 255
            g = 0
            b = 0
            if player_id == "2":
                r = 0
                g = 0
                b = 255
            score_percentage = (1.0 * SCORES[player_id]) / (1.0 * MAX_SCORE)
            claims.append(
                draw_score_on_region(PLAYER_REGIONS[player_id],
                                     score_percentage, r, g, b, "1"))
            PLAYER_REGIONS[player_id]
    batch(claims)
def highlight_regions(results, subscription_id, r, g, b):
    global projection_matrixes
    claims = []
    claims.append({
        "type":
        "retract",
        "fact": [
            ["id", get_my_id_str()],
            ["id", subscription_id],
            ["postfix", ""],
        ]
    })
    highlighted_regions = {}
    for result in results:
        if result["regionId"] in highlighted_regions:
            continue  # Region is already highlighted
        camera_homography_matrix = projection_matrixes.get(
            str(result["cameraId"]), None)
        polygon = [
            project(camera_homography_matrix, result["x1"], result["y1"]),
            project(camera_homography_matrix, result["x2"], result["y2"]),
            project(camera_homography_matrix, result["x3"], result["y3"]),
            project(camera_homography_matrix, result["x4"], result["y4"]),
        ]
        highlighted_regions[result["regionId"]] = True
        ill = Illumination()
        ill.fill(r, g, b, 150)
        ill.nostroke()
        ill.polygon(polygon)
        claims.append(
            ill.to_batch_claim(get_my_id_str(), subscription_id,
                               result["displayId"]))
    batch(claims)
示例#8
0
def sub_callback_laser_dots(results):
    global projection_matrixes
    claims = []
    claims.append({"type": "retract", "fact": [
        ["id", get_my_id_str()],
        ["id", "1"],
        ["postfix", ""],
    ]})
    for result in results:
        pt = project(projection_matrixes.get(str(result["cameraId"])), result["x"], result["y"])
        logging.info("DOT {} {} {} {}".format(result["x"], result["y"], pt[0], pt[1]))
        if pt[0] >= 0 and pt[1] >= 0 and pt[0] < DAYS_IN_WEEK and pt[1] < WEEKS_IN_CALENDAR:
            grid_x = int(pt[0])
            grid_y = int(pt[1])
            claims.append({"type": "claim", "fact": [
                ["id", get_my_id_str()],
                ["id", "1"],
                ["text", "laser"],
                ["text", "at"],
                ["text", "calendar"],
                ["text", str(grid_x)],
                ["text", str(grid_y)],
                ["text", "@"],
                ["text", str(result["t"])],
            ]})
    batch(claims)
示例#9
0
def sub_callback_calibration(results):
    global is_selecting
    claims = []
    if results:
        for result in results:
            if is_selecting:
                claims.append({
                    "type":
                    "claim",
                    "fact": [
                        ["id", "0"],
                        ["id", "1"],
                        ["text", "region"],
                        ["text", str(result["regionId"])],
                        ["text", "is"],
                        ["text", "toggled"],
                    ]
                })
                logging.error("region {} is on".format(result["regionId"]))
            else:
                claims.append({
                    "type":
                    "retract",
                    "fact": [
                        ["id", "0"],
                        ["id", "1"],
                        ["text", "region"],
                        ["text", str(result["regionId"])],
                        ["text", "is"],
                        ["text", "toggled"],
                    ]
                })
                logging.error("region {} is OFF".format(result["regionId"]))
        batch(claims)
def sub_callback(results):
    global p
    claims = []
    claims.append({
        "type":
        "retract",
        "fact": [
            ["variable", ""],
            ["variable", ""],
            ["text", "wish"],
            ["variable", ""],
            ["text", "would"],
            ["text", "be"],
            ["text", "thermal"],
            ["text", "printed"],
            ["text", "on"],
            ["text", "epson"],
        ]
    })
    batch(claims)
    for result in results:
        logging.info("PRINTING {} {}".format(datetime.now().isoformat(),
                                             result["filePath"]))
        try:
            url = result["filePath"]
            if not ("http" in result["filePath"]):
                url = "http://192.168.1.34:5000/{}".format(result["filePath"])
            PIL_image = Image.open(requests.get(url, stream=True).raw)
            p.image(PIL_image)
            p.cut()
        except Exception as e:
            logging.error(traceback.format_exc())
示例#11
0
def highlight_regions(results, subscription_id, r, g, b):
    claims = []
    claims.append({
        "type":
        "retract",
        "fact": [
            ["id", get_my_id_str()],
            ["id", subscription_id],
            ["postfix", ""],
        ]
    })
    highlighted_regions = {}
    for result in results:
        if result["regionId"] in highlighted_regions:
            continue  # Region is already highlighted
        polygon = [
            project(LASER_CAMERA_ID, result["x1"], result["y1"]),
            project(LASER_CAMERA_ID, result["x2"], result["y2"]),
            project(LASER_CAMERA_ID, result["x3"], result["y3"]),
            project(LASER_CAMERA_ID, result["x4"], result["y4"]),
        ]
        highlighted_regions[result["regionId"]] = True
        ill = Illumination()
        ill.fill(r, g, b, 50)
        ill.nostroke()
        ill.polygon(polygon)
        claims.append(
            ill.to_batch_claim(get_my_id_str(), subscription_id, "global"))
    batch(claims)
示例#12
0
def sub_callback_keyboard(results):
    global is_selecting, ignore_key_press
    if ignore_key_press:
        ignore_key_press = False
        return
    claims = []
    claims.append({
        "type":
        "retract",
        "fact": [
            ["id", get_my_id_str()],
            ["id", "2"],
            ["postfix", ""],
        ]
    })
    if results:
        key = str(results[0]["key"])
        if key == "up" and is_selecting:
            is_selecting = False
            ill = Illumination()
            ill.text(0, 0, "clearing\ntoggle")
            claims.append(ill.to_batch_claim(get_my_id_str(), "2"))
        else:
            is_selecting = True
    batch(claims)
def my_prehook():
    batch_claims = []
    batch_claims.append({"type": "death", "fact": [
        ["id", get_my_id_pre_init(__file__)],
    ]})
    batch(batch_claims)
    logging.error("cleaning my old subs")
def sub_callback_calibration_points(results):
    global projection_matrixes, camera_to_display_map
    claims = [{
        "type": "retract",
        "fact": [["id", get_my_id_str()], ["id", "0"], ["postfix", ""]]
    }]
    if results and len(results) > 0:
        for result in results:
            src = np.float32([
                [0, 0],
                [SCREEN_REGION_WIDTH_PX, 0],
                [0, SCREEN_REGION_HEIGHT_PX],
                [SCREEN_REGION_WIDTH_PX,
                 SCREEN_REGION_HEIGHT_PX]  # notice the order is not clock-wise
            ])
            camera_homography_matrix = projection_matrixes.get(
                str(result["cameraId"]), None)
            if camera_homography_matrix is None:
                continue
            dst = np.float32([
                project(camera_homography_matrix, result["rx1"],
                        result["ry1"]),
                project(camera_homography_matrix, result["rx2"],
                        result["ry2"]),
                project(camera_homography_matrix, result["rx4"],
                        result["ry4"]),
                project(camera_homography_matrix, result["rx3"],
                        result["ry3"])  # notice the order is not clock-wise
            ])
            homography_matrix = cv2.getPerspectiveTransform(src, dst)
            claims.append({
                "type":
                "claim",
                "fact": [
                    ["id", get_my_id_str()],
                    ["id", "0"],
                    ["text", str(result["regionName"])],
                    ["integer", str(result["cameraId"])],
                    ["text", "calibration"],
                    ["text", "for"],
                    [
                        "text",
                        str(camera_to_display_map[str(result["cameraId"])])
                    ],
                    ["text", "is"],
                    ["float", str(homography_matrix[0][0])],
                    ["float", str(homography_matrix[0][1])],
                    ["float", str(homography_matrix[0][2])],
                    ["float", str(homography_matrix[1][0])],
                    ["float", str(homography_matrix[1][1])],
                    ["float", str(homography_matrix[1][2])],
                    ["float", str(homography_matrix[2][0])],
                    ["float", str(homography_matrix[2][1])],
                    ["float", str(homography_matrix[2][2])],
                ]
            })
    batch(claims)
示例#15
0
def run_cv():
    global url, blob_images, debug_image
    claims = []
    claims.append({"type": "retract", "fact": [["id", get_my_id_str()], ["postfix", ""]]})
    if url is not None:
        try:
            pil_image = Image.open(requests.get(url, stream=True).raw)
            # run CV
            image = np.array(pil_image) 
            # Convert RGB to BGR 
            image = image[:, :, ::-1].copy() 
            image_grey = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
            ret, threshold_image = cv2.threshold(image_grey, THRESHOLD, 255, cv2.THRESH_BINARY)
            with lock:
                debug_image = threshold_image
            im2, raw_contours, hierarchy = cv2.findContours(threshold_image, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
            contours = []
            print("n raw contours: {}".format(len(raw_contours)))
            for (i, c) in enumerate(raw_contours):
                if hierarchy[0,i,3] == -1 and cv2.contourArea(c) > MIN_CONTOUR_AREA:
                    contours.append(c)
            contours = sorted(contours, key=lambda ctr: cv2.boundingRect(ctr)[0])
            blob_images = []
            chosen_contours = []
            for (i, c) in enumerate(contours[:MAX_N_IMAGES]):
                chosen_contours.append(c)
                box = cv2.minAreaRect(c)
                box = cv2.boxPoints(box)
                box = order_points(box)  # Order the points to (tl, tr, bl, br) to match the perspective transform dst
                contour_perspective = np.array(box, dtype="float32")
                dst = np.array([
                        [0, 0],
                        [CONTOUR_PERSPECTIVE_IMAGE_WIDTH - 1, 0],
                        [CONTOUR_PERSPECTIVE_IMAGE_WIDTH - 1, CONTOUR_PERSPECTIVE_IMAGE_HEIGHT - 1],
                        [0, CONTOUR_PERSPECTIVE_IMAGE_HEIGHT - 1]], dtype = "float32")
                contour_perspective_matrix = cv2.getPerspectiveTransform(contour_perspective, dst)
                contour_perspective_image = cv2.warpPerspective(image, contour_perspective_matrix, (CONTOUR_PERSPECTIVE_IMAGE_WIDTH, CONTOUR_PERSPECTIVE_IMAGE_HEIGHT))
                with lock:
                    blob_images.append(contour_perspective_image)
            # claim
            for i in range(len(blob_images)):
                claims.append({"type": "claim", "fact": [
                    ["id", get_my_id_str()],
                    ["id", "0"],
                    ["text", "camera"],
                    ["text", "sees"],
                    ["text", "subframe"],
                    ["text", str(i)],
                    ["text", "http://{}:{}/src/files/cv-frame-{}.jpg".format(get_host_ip(), PORT, i)],
                    ["text", "@"],
                    ["integer", str(int(time.time()*1000))],
                ]})
        except Exception as e:
            logging.error(traceback.format_exc())
    batch(claims)
示例#16
0
def sub_callback_papers(results):
    papers = list(
        map(
            lambda p: ({
                "id":
                p["id"],
                "seenByCamera":
                p["cameraId"],
                "corners": [{
                    "x": p["x1"],
                    "y": p["y1"]
                }, {
                    "x": p["x2"],
                    "y": p["y2"]
                }, {
                    "x": p["x3"],
                    "y": p["y3"]
                }, {
                    "x": p["x4"],
                    "y": p["y4"]
                }]
            }), results))
    logging.info("--")

    WISKER_LENGTH = 150
    claims = []
    claims.append({
        "type": "retract",
        "fact": [
            ["id", get_my_id_str()],
            ["postfix", ""],
        ]
    })
    for paper in papers:
        other_paper = get_paper_you_point_at(papers, paper["id"],
                                             WISKER_LENGTH)
        logging.info("{} pointing at {}".format(paper["id"], other_paper))
        if other_paper is not None:
            claims.append({
                "type":
                "claim",
                "fact": [
                    ["id", get_my_id_str()],
                    ["id", "1"],
                    ["text", "paper"],
                    ["integer", str(paper["id"])],
                    ["text", "is"],
                    ["text", "pointing"],
                    ["text", "at"],
                    ["text", "paper"],
                    ["integer", str(other_paper)],
                ]
            })
    batch(claims)
示例#17
0
def next_feed():
    batch = next(batches)
    encoder_inputs_, encoder_inputs_length_ = helper.batch(batch)
    decoder_targets_, _ = helper.batch(
        [seq + [EOS] + [PAD] * 2 for seq in batch]
    )
    return {
        encoder_inputs: encoder_inputs_,
        encoder_inputs_length: encoder_inputs_length_,
        decoder_targets: decoder_targets_
    }
示例#18
0
def room_claim(addr, batch_update_from_ble_device):
    print("TODO claim: {} {}".format(addr, batch_update_from_ble_device))
    batch([{
        "type":
        "claim",
        "fact": [
            ["id", get_my_id_str()],
            ["id", device.addr],
            ["text", batch_update_from_ble_device],
        ]
    }])
def sub_callback_normal_key(results):
    global MODE, is_toggleable, region_name, region_id
    if results:
        key = str(results[0]["key"]).lower()
        if MODE == "is_toggleable":
            region_name = ""
            if key == "n" or key == "y":
                is_toggleable = key == "y"
                batch(render_mode())
        elif MODE == "naming":
            if key.isalpha() or key.isdigit() or key == " ":
                region_name += key
                batch(render_mode())
示例#20
0
def handle_key_event(e):
    claims = []
    claims.append({
        "type": "retract",
        "fact": [
            ["id", get_my_id_str()],
            ["postfix", ""],
        ]
    })
    ctrl_held = keyboard.is_pressed('ctrl')
    shift_held = keyboard.is_pressed('shift')
    if e.event_type == 'down':
        if e.name != 'unknown':
            if ctrl_held:
                if shift_held and e.name.isalpha():
                    claims.append(add_key(None, 'C-{}'.format(e.name.upper())))
                elif shift_held and e.name in shift_map:
                    claims.append(
                        add_key(None, 'C-{}'.format(shift_map[e.name])))
                elif e.name == '−':
                    claims.append(add_key(None, 'C--'.format(e.name)))
                else:
                    claims.append(add_key(None, 'C-{}'.format(e.name)))
            elif e.name in special_keys:
                claims.append(add_key(None, e.name))
            elif shift_held and e.name.isalpha():
                claims.append(add_key(e.name.upper(), None))
            elif shift_held and e.name in shift_map:
                claims.append(add_key(shift_map[e.name], None))
            elif e.name == '−':
                claims.append(add_key('-', None))
            else:
                claims.append(add_key(e.name, None))
    keys_to_claim_when_pressed = ["up", "right", "down", "left", "space"]
    for key_name in keys_to_claim_when_pressed:
        if keyboard.is_pressed(key_name):
            claims.append({
                "type":
                "claim",
                "fact": [
                    ["id", get_my_id_str()],
                    ["id", "0"],
                    ["text", "keyboard"],
                    ["text", get_my_id_str()],
                    ["text", "has"],
                    ["text", "pressed"],
                    ["text", "key"],
                    ["text", key_name],
                ]
            })
    batch(claims)
示例#21
0
def add_key(key, special_key):
    global last_server_health_check, health_check_delay_s
    timestamp = int(time.time() * 1000.0)
    claims = []
    claims.append({
        "type": "retract",
        "fact": [
            ["id", get_my_id_str()],
            ["postfix", ""],
        ]
    })
    if special_key:
        logging.info("ADDING SPECIAL KEY {}".format(special_key))
        claims.append({
            "type":
            "claim",
            "fact": [
                ["id", get_my_id_str()],
                ["id", "0"],
                ["text", "keyboard"],
                ["text", get_my_id_str()],
                ["text", "typed"],
                ["text", "special"],
                ["text", "key"],
                ["text", str(special_key)],
                ["text", "@"],
                ["integer", str(timestamp)],
            ]
        })
    else:
        logging.info("ADDING KEY {}".format(key))
        claims.append({
            "type":
            "claim",
            "fact": [
                ["id", get_my_id_str()],
                ["id", "0"],
                ["text", "keyboard"],
                ["text", get_my_id_str()],
                ["text", "typed"],
                ["text", "key"],
                ["text", str(key)],
                ["text", "@"],
                ["integer", str(timestamp)],
            ]
        })
    batch(claims)
    if time.time() - last_server_health_check > health_check_delay_s:
        last_server_health_check = time.time()
        check_server_connection()
def prehook_init():
    global lock, cached_image
    claims = [
        {"type": "retract", "fact": [["id", get_my_id_str()], ["postfix", ""]]},
        {"type": "claim", "fact": [
            ["id", get_my_id_str()],
            ["id", "0"],
            ["text", "camera"],
            ["integer", str(CAMERA_ID)],
            ["text", "frame"],
            ["text", "at"],
            ["text", "http://{}:{}/src/files/{}".format(get_host_ip(), PORT, BOOT_FILENAME)],
        ]},
    ]
    frame = cv2.imread(os.path.join(os.path.dirname(os.path.dirname(__file__)), 'files/{}'.format(BOOT_FILENAME)))
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    aruco_dict = aruco.Dictionary_get(aruco.DICT_6X6_1000)
    arucoParameters = aruco.DetectorParameters_create()
    corners, ids, rejectedImgPoints = aruco.detectMarkers(
        gray, aruco_dict, parameters=arucoParameters)
    currentTimeMs = int(round(time.time() * 1000))
    if ids is not None and len(ids) > 0:
        for i, _tag_corners in enumerate(corners):
            tag_corners = _tag_corners[0]
            claims.append({"type": "claim", "fact": [
                ["id", get_my_id_str()],
                ["id", "1"],
                ["text", "camera"],
                ["integer", str(CAMERA_ID)],
                ["text", "sees"],
                ["text", "aruco"],
                ["integer", str(ids[i][0])],
                ["text", "at"],
                ["integer", str(int(tag_corners[0][0]))],
                ["integer", str(int(tag_corners[0][1]))],
                ["integer", str(int(tag_corners[1][0]))],
                ["integer", str(int(tag_corners[1][1]))],
                ["integer", str(int(tag_corners[2][0]))],
                ["integer", str(int(tag_corners[2][1]))],
                ["integer", str(int(tag_corners[3][0]))],
                ["integer", str(int(tag_corners[3][1]))],
                ["text", "@"],
                ["integer", str(currentTimeMs)]
            ]})
    debugFrame = aruco.drawDetectedMarkers(frame, corners)
    with lock:
        is_success, buffer = cv2.imencode(".jpg", debugFrame)
        cached_image = BytesIO(buffer)
    batch(claims)
示例#23
0
def my_prehook():
    time.sleep(1)
    logging.error("sending #1")
    currentTimeMs = int(round(time.time() * 1000))
    claims = []
    claims.append({
        "type":
        "claim",
        "fact": [["text", get_my_id_str()], ["text", "test"],
                 ["text", "client"], ["integer", MY_ID], ["text", "says"],
                 ["integer", MY_ID], ["text", "@"],
                 ["integer", str(currentTimeMs)]]
    })
    batch(claims)
    print("1300 claim")
def sub_callback_laser_dots(results):
    claims = []
    claims.append({
        "type":
        "retract",
        "fact": [
            ["id", get_my_id_str()],
            ["id", "1"],
            ["postfix", ""],
        ]
    })
    for result in results:
        polygon = [[int(result["x1"]), int(result["y1"])],
                   [int(result["x2"]), int(result["y2"])],
                   [int(result["x3"]), int(result["y3"])],
                   [int(result["x4"]), int(result["y4"])]]
        inside = point_inside_polygon(int(result["x"]), int(result["y"]),
                                      polygon)
        if inside:
            logging.info("laser {} {} inside region {}".format(
                result["x"], result["y"], result["regionId"]))
            claims.append({
                "type":
                "claim",
                "fact": [
                    ["id", get_my_id_str()],
                    ["id", "1"],
                    ["text", "laser"],
                    ["text", "in"],
                    ["text", "region"],
                    ["text", str(result["regionId"])],
                ]
            })
            claims.append({
                "type":
                "claim",
                "fact": [
                    ["id", get_my_id_str()],
                    ["id", "1"],
                    ["text", "laser"],
                    ["text", "in"],
                    ["text", "region"],
                    ["text", str(result["regionId"])],
                    ["text", "@"],
                    ["text", str(result["t"])],
                ]
            })
    batch(claims)
示例#25
0
def my_prehook():
    claims = []
    claims.append({
        "type":
        "claim",
        "fact": [
            ["id", get_my_id_str()],
            ["id", "0"],
            ["text", "Man"],
            ["integer", "5"],
            ["text", "has"],
            ["integer", "0"],
            ["text", "toes"],
        ]
    })
    batch(claims)
示例#26
0
def sub_callback(results):
    currentTimeMs = int(round(time.time() * 1000))
    claims = []
    claims.append({
        "type": "retract",
        "fact": [
            ["id", get_my_id_str()],
            ["postfix", ""],
        ]
    })
    batch(claims)
    # const span = tracer.startSpan('1200-done', { childOf: room.wireCtx() });
    start_time = int(results[0]['time1'])
    finish_time = int(results[0]['time2'])
    print("TEST IS DONE @ %s %s" % (currentTimeMs, results))
    logging.error("elapsed time: %s ms" % (finish_time - start_time))
示例#27
0
def add_key(key, special_key):
    logging.info("{} - {}".format(key, special_key))
    timestamp = int(time.time() * 1000.0)
    claims = []
    claims.append({
        "type": "retract",
        "fact": [
            ["id", get_my_id_str()],
            ["postfix", ""],
        ]
    })
    if special_key:
        logging.info("ADDING SPECIAL KEY {}".format(special_key))
        claims.append({
            "type":
            "claim",
            "fact": [
                ["id", get_my_id_str()],
                ["id", "0"],
                ["text", "keyboard"],
                ["text", get_my_id_str()],
                ["text", "typed"],
                ["text", "special"],
                ["text", "key"],
                ["text", str(special_key)],
                ["text", "@"],
                ["integer", str(timestamp)],
            ]
        })
    else:
        logging.info("ADDING KEY {}".format(key))
        claims.append({
            "type":
            "claim",
            "fact": [
                ["id", get_my_id_str()],
                ["id", "0"],
                ["text", "keyboard"],
                ["text", get_my_id_str()],
                ["text", "typed"],
                ["text", "key"],
                ["text", str(key)],
                ["text", "@"],
                ["integer", str(timestamp)],
            ]
        })
    batch(claims)
示例#28
0
 def claimProjectorCalibration(self):
     batch_claims = [{
         "type":
         "retract",
         "fact": [["id", get_my_id_str()], ["id", "0"], ["postfix", ""]]
     }]
     batch_claims.append({
         "type":
         "claim",
         "fact": [
             ["id", get_my_id_str()],
             ["id", "0"],
             ["text", "camera"],
             ["integer", "1"],
             ["text", "has"],
             ["text", "projector"],
             ["text", "calibration"],
             ["text", "TL"],
             ["text", "("],
             ["integer", str(self.projector_calibration[0][0])],
             ["text", ","],
             ["integer", str(self.projector_calibration[0][1])],
             ["text", ")"],
             ["text", "TR"],
             ["text", "("],
             ["integer", str(self.projector_calibration[1][0])],
             ["text", ","],
             ["integer", str(self.projector_calibration[1][1])],
             ["text", ")"],
             ["text", "BR"],
             ["text", "("],
             ["integer", str(self.projector_calibration[2][0])],
             ["text", ","],
             ["integer", str(self.projector_calibration[2][1])],
             ["text", ")"],
             ["text", "BL"],
             ["text", "("],
             ["integer", str(self.projector_calibration[3][0])],
             ["text", ","],
             ["integer", str(self.projector_calibration[3][1])],
             ["text", ")"],
             ["text", "@"],
             ["integer", str(int(round(time.time() * 1000)))],
         ]
     })
     batch(batch_claims)
def sub_callback_calibration_points(results):
    claims = [{
        "type": "retract",
        "fact": [["id", get_my_id_str()], ["id", "1"], ["postfix", ""]]
    }]
    if results and len(results) > 0:
        for result in results:
            src = np.float32([
                [result["rx1"], result["ry1"]],
                [result["rx2"], result["ry2"]],
                [result["rx4"], result["ry4"]],
                [result["rx3"],
                 result["ry3"]]  # notice the order is not clock-wise
            ])
            dst = np.float32([
                [result["sx1"], result["sy1"]],
                [result["sx2"], result["sy2"]],
                [result["sx4"], result["sy4"]],
                [result["sx3"],
                 result["sy3"]]  # notice the order is not clock-wise
            ])
            homography_matrix = cv2.getPerspectiveTransform(src, dst)
            claims.append({
                "type":
                "claim",
                "fact": [
                    ["id", get_my_id_str()],
                    ["id", "1"],
                    ["text", "camera"],
                    ["integer", str(result["cam"])],
                    ["text", "calibration"],
                    ["text", "for"],
                    ["text", str(result["display"])],
                    ["text", "is"],
                    ["float", str(homography_matrix[0][0])],
                    ["float", str(homography_matrix[0][1])],
                    ["float", str(homography_matrix[0][2])],
                    ["float", str(homography_matrix[1][0])],
                    ["float", str(homography_matrix[1][1])],
                    ["float", str(homography_matrix[1][2])],
                    ["float", str(homography_matrix[2][0])],
                    ["float", str(homography_matrix[2][1])],
                    ["float", str(homography_matrix[2][2])],
                ]
            })
    batch(claims)
示例#30
0
def sub_callback(results):
    currentTimeMs = int(round(time.time() * 1000))
    claims = []
    claims.append({
        "type": "retract",
        "fact": [
            ["id", MY_ID_STR],
            ["postfix", ""],
        ]
    })
    claims.append({
        "type":
        "claim",
        "fact": [["text", MY_ID_STR], ["text", "test"], ["text", "client"],
                 ["integer", MY_ID], ["text", "says"], ["integer", MY_ID],
                 ["text", "@"], ["integer", str(currentTimeMs)]]
    })
    batch(claims)