Exemple #1
0
def infer_yolo(timestamp, margin, points):
    while True:
        yolo_input.wait()
        ret, image = yolo_input.pull(flush=True)
        if not ret:
            continue

        # ret, flag = zone_image_update.pull()
        # if ret and flag:
        #     cv2.imwrite('../../../Angular-Dashboard-master/src/assets/rack_image.jpg', image)
        #     print("After Update")

        inference = Inference(image)
        img_shape = image.shape
        ret, point_set_dict = point_set.pull()
        if ret:
            point_set_dict["point_set_2"] = [
                [0,
                 0.6 * margin], [img_shape[1] - 4.25 * margin, 0.6 * margin],
                [img_shape[1] - 4.25 * margin, img_shape[0] - 0.6 * margin],
                [0, img_shape[0] - 0.6 * margin]
            ]
            print("updated points")
            points = point_set_dict['point_set_2']
            retail_an_object.rack_dict = point_set_dict
            retail_an_object.global_init()

        inference.get_meta_dict()['warp_points'] = retail_an_object.rack_dict
        yolo_ip.push(inference)
        yolo_op.wait()
        ret, inference = yolo_op.pull()
        ret1, zones = zone_detection_in_pipe.pull()
        if ret:
            i_dets = inference.get_result()
            boxes = tracker_stock.update(i_dets)
            image = i_dets.get_annotated(boxes)
            if ret1 and not zones:
                image = retail_an_object.print_shelfNo(image)
                image = retail_an_object.misplacedBoxes(boxes, image)
                image = retail_an_object.draw_empty_space(boxes, image)
                flag = retail_an_object.change_of_state()
                # cv2.rectangle(image, (margin, margin), (img_shape[1]-margin, img_shape[0]-margin), (0, 0, 255), 3)

                current_time = time.time()
                elapsed_seconds = (current_time - timestamp)
                # print(elapsed_seconds)
                if (elapsed_seconds > 3):
                    if flag == 1:
                        # pass
                        Thread(target=retail_an_object.postdata).start()
                        timestamp = time.time()

            # print("left corner: ",points[0][1])
            image = image[int(points[0][1] - margin / 2):int(points[2][1] +
                                                             margin / 2),
                          int(points[0][0]):int(points[2][0] + margin / 2), :]
            stock_in_pipe.push(image)
            cv2.imshow("retail_out", image)
            cv2.waitKey(1)
Exemple #2
0
def read():
    while True:
        ret, image = cap.read()
        if not ret:
            continue

        image = image.copy()
        yolo_input.push(image)
        # print("Image read count: ", count)
        # count+=1
        # image = cv2.resize(image, (int(image.shape[1] / 2), int(image.shape[0] / 2)))
        detector_ip.push(Inference(image))
        detector_op.wait()
        ret, inference = detector_op.pull()
        if ret:
            i_dets = inference.get_result()
            infer_idets = Inference(i_dets)
            infer_idets.get_meta_dict()['zone_pipe'] = zone_pipe
            trk_ip.push(infer_idets)