Example #1
0
        while True:
            retval, img = vid.read()
            if not retval:
                print("Done!")
                break

            img1 = np.copy(img)
            img2 = np.zeros_like(img)

            # model to predict
            x = np.array([preprocess(img, input_size)])
            with sl_graph.as_default():
                with sl_session.as_default():
                    y = sl_model.predict(x)

            result = prior_util.decode(y[0], confidence_threshold)

            if len(result) > 0:

                bboxs = result[:, 0:4]
                quads = result[:, 4:12]
                rboxes = result[:, 12:17]

                boxes = np.asarray([rbox3_to_polygon(r) for r in rboxes])

                xy = boxes
                xy = xy * [vid_w, vid_h]
                xy = np.round(xy)
                xy = xy.astype(np.int32)

                cv2.polylines(img1, tuple(xy), True, (0, 0, 255))
        while current_y + crop_h < height:
            while current_x + crop_w < width:

                crop_img = rot_img[current_y:current_y + crop_h,
                                   current_x:current_x + crop_w]

                if do_preprocess:
                    crop_img = preprocess(crop_img, (512, 512))

                model_output = model.predict(np.array([crop_img]),
                                             batch_size=1,
                                             verbose=0)

                res = prior_util.decode(model_output[0],
                                        confidence_threshold,
                                        fast_nms=False)
                bboxes = res[:, 0:4]
                quades = res[:, 4:12]
                rboxes = res[:, 12:17]
                conf = res[:, 17:]

                for j in range(len(rboxes)):
                    # convert rbox
                    polygon = rbox3_to_polygon(rboxes[j]) * 512

                    # translate to full image location
                    polygon[:, 0] += current_x
                    polygon[:, 1] += current_y

                    # rotate to orientation when image is not rotated