Example #1
0
 def render(self, surface):
     render_text(surface,
                 f'{self.current_time}',
                 'huge',
                 settings.VIRTUAL_WIDTH // 2,
                 settings.VIRTUAL_HEIGHT // 2 - 20,
                 center=True)
Example #2
0
 def render(self, surface):
     render_text(surface,
                 'Bird',
                 'large',
                 settings.VIRTUAL_WIDTH // 2,
                 settings.VIRTUAL_HEIGHT // 2 - 30,
                 center=True)
     render_text(surface,
                 'Press Enter',
                 'medium',
                 settings.VIRTUAL_WIDTH // 2,
                 settings.VIRTUAL_HEIGHT // 2 + 10,
                 center=True)
Example #3
0
 def render(self, surface):
     render_text(surface,
                 'Oops! You lost!',
                 'large',
                 settings.VIRTUAL_WIDTH // 2,
                 settings.VIRTUAL_HEIGHT // 2 - 30,
                 center=True)
     render_text(surface,
                 f'Score: {self.score}',
                 'medium',
                 settings.VIRTUAL_WIDTH // 2,
                 settings.VIRTUAL_HEIGHT // 2 + 10,
                 center=True)
     render_text(surface,
                 'Press Enter to Play Again!',
                 'medium',
                 settings.VIRTUAL_WIDTH // 2,
                 settings.VIRTUAL_HEIGHT // 2 + 80,
                 center=True)
Example #4
0
            print(f"{COCOLabels(box.classID).name}: {box.confidence}")
            input_image = render_box(input_image,
                                     box.box(),
                                     color=tuple(RAND_COLORS[box.classID %
                                                             64].tolist()))
            size = get_text_size(
                input_image,
                f"{COCOLabels(box.classID).name}: {box.confidence:.2f}",
                normalised_scaling=0.6)
            input_image = render_filled_box(
                input_image,
                (box.x1 - 3, box.y1 - 3, box.x1 + size[0], box.y1 + size[1]),
                color=(220, 220, 220))
            input_image = render_text(
                input_image,
                f"{COCOLabels(box.classID).name}: {box.confidence:.2f}",
                (box.x1, box.y1),
                color=(30, 30, 30),
                normalised_scaling=0.5)

        if FLAGS.out:
            cv2.imwrite(FLAGS.out, input_image)
            print(f"Saved result to {FLAGS.out}")
        else:
            cv2.imshow('image', input_image)
            cv2.waitKey(0)
            cv2.destroyAllWindows()

    # VIDEO MODE
    if FLAGS.mode == 'video':
        print("Running in 'video' mode")
        if not FLAGS.input:
Example #5
0
    def infer(self,input_img,triton_client,confidence = 0.5):
        confidence = confidence
        out = "output/"+input_img.split("/")[1]
        # IMAGE MODE
        # print("Running in 'image' mode")
        if not input_img:
            print("FAILED: no input image")
            sys.exit(1)
        
        inputs = []
        outputs = []
        inputs.append(grpcclient.InferInput('data', [1, 3, 640, 640], "FP32"))
        outputs.append(grpcclient.InferRequestedOutput('prob'))

        # print("Creating buffer from image file...")
        input_image = cv2.imread(input_img)
        if input_image is None:
            print(f"FAILED: could not load input image {str(input_img)}")
            sys.exit(1)
        input_image_buffer,dw,dh,padding_w,padding_h= preprocess(input_image)
        input_image_buffer = np.expand_dims(input_image_buffer, axis=0)
        inputs[0].set_data_from_numpy(input_image_buffer)

        # print("Invoking inference...")
        results = self.triton_client.infer(model_name=self.model,
                                    inputs=inputs,
                                    outputs=outputs,
                                    client_timeout=self.client_timeout)
        if self.model_info:
            statistics = self.triton_client.get_inference_statistics(model_name=self.model)
            if len(statistics.model_stats) != 1:
                print("FAILED: get_inference_statistics")
                sys.exit(1)
            # print(statistics)
        # print("load model done")

        result = results.as_numpy('prob')
        # print(f"Received result buffer of size {result.shape}")
        # print(f"Naive buffer sum: {np.sum(result)}")

        detected_objects = postprocess(result, input_image.shape[1], input_image.shape[0],dw,dh,padding_w,padding_h,confidence, self.nms)
        print(f"Raw boxes: {int(result[0, 0, 0, 0])}")
        print(f"Detected objects: {len(detected_objects)}")

        return_info = []

        for box in detected_objects:
            return_info.append([box.classID,box.u1,box.u2,box.v1,box.v2])
            print(f"{COCOLabels(box.classID).name}: {box.confidence}")
            input_image = render_box(input_image, box.box(), color=tuple(RAND_COLORS[box.classID % 64].tolist()))
            size = get_text_size(input_image, f"{COCOLabels(box.classID).name}: {box.confidence:.2f}", normalised_scaling=0.6)
            input_image = render_filled_box(input_image, (box.x1 - 3, box.y1 - 3, box.x1 + size[0], box.y1 + size[1]), color=(220, 220, 220))
            input_image = render_text(input_image, f"{COCOLabels(box.classID).name}: {box.confidence:.2f}", (box.x1, box.y1), color=(30, 30, 30), normalised_scaling=0.5)

        if out:
            cv2.imwrite(out, input_image)
            print(f"Saved result to {out}")
        else:
            cv2.imshow('image', input_image)
            cv2.waitKey(0)
            cv2.destroyAllWindows()
        return return_info
Example #6
0
def send():
    ctx = get_ctx()
    if len(ctx['heroes']):
        text = render.render_text(ctx)
        html = render.render_html(ctx)
        email(text, html)
Example #7
0
    def render(self, surface):
        for log in self.logs:
            log.render(surface)

        self.bird.render(surface)
        render_text(surface, f'Score: {self.score}', 'large', 5, 5)
Example #8
0
def intro_loop(pos, loc):
	screen.blit(background_image, [0, 0])
	intro_buttons(loc)
	render.render_text("Life", intro_head, intro_size, WHITE)
	pygame.display.flip()
	clock.tick(120)
Example #9
0
def mode_loop(pos, loc):
    screen.fill(GREY)
    mode_buttons(loc)
    render.render_text("Choose Evolution Method", head_title, head_size, WHITE)
    pygame.display.flip()
Example #10
0
    def render(self, surface):
        for pipe in self.pipes:
            pipe.render(surface)

        self.bird.render(surface)
        render_text(surface, f'Score: {self.score}', 'large', 5, 5)