Ejemplo n.º 1
0
def run_nn(img, input_queue, width, height):
    frameNn = dai.ImgFrame()
    frameNn.setType(dai.ImgFrame.Type.BGR888p)
    frameNn.setWidth(width)
    frameNn.setHeight(height)
    frameNn.setData(toPlanar(img, (height, width)))
    input_queue.send(frameNn)
Ejemplo n.º 2
0
    def run_face(self):
        # img, scale, top, left = resize_padding(self.frame, 300, 300)

        if not self.camera:
            nn_data = run_nn(
                self.face_in,
                self.face_nn,
                {"data": toPlanar(self.frame, (300, 300))},
            )
        else:
            nn_data = self.face_nn.tryGet()
        if nn_data is None:
            return False

        bboxes = nn_data.detections
        self.number_of_people = len(bboxes)
        for bbox in bboxes:
            face_coord = frameNorm(
                self.debug_frame, [bbox.xmin, bbox.ymin, bbox.xmax, bbox.ymax])
            # face_coord = restore_point(face_coord, scale, top, left).astype(int)
            face_coord = scale_bbox(face_coord)
            self.face_frames.put(self.frame[face_coord[1]:face_coord[3],
                                            face_coord[0]:face_coord[2]])
            self.face_coords.put(face_coord)
            self.draw_bbox(face_coord, (10, 245, 10))

        return True
Ejemplo n.º 3
0
    def run_mask(self):
        masked = 0
        while self.face_frames.qsize():
            face_frame = self.face_frames.get()
            face_coord = self.face_coords.get()
            nn_data = run_nn(
                self.mask_in,
                self.mask_nn,
                {"data": toPlanar(face_frame, (224, 224))},
            )
            if nn_data is None:
                return
            self.fps_handler.tick("NN")
            out = softmax(to_nn_result(nn_data))
            mask = np.argmax(out) > 0.5

            color = (0, 255, 0) if mask else (0, 0, 255)
            self.draw_bbox(face_coord, color)
            self.put_text(f"{out[1]:.2%}", face_coord, color)

            if mask:
                masked += 1

            self.put_text(
                f"masks: {masked / self.number_of_people:.2%} ",
                (10, 30),
                (255, 0, 0),
                0.75,
            )
Ejemplo n.º 4
0
def run_nn(x_in, frame, w, h):
    nn_data = dai.ImgFrame()
    nn_data.setData(toPlanar(frame, (w, h)))
    nn_data.setType(dai.RawImgFrame.Type.BGR888p)
    nn_data.setTimestamp(monotonic())
    nn_data.setWidth(w)
    nn_data.setHeight(h)
    x_in.send(nn_data)
Ejemplo n.º 5
0
def run_nn(img, input_queue, width, height):
    """
    It takes an image, converts it to a planar image, and sends it to the input queue

    :param img: The image to be processed
    :param input_queue: The input queue to the neural network
    :param width: The width of the image in pixels
    :param height: The height of the image in pixels
    """
    frameNn = dai.ImgFrame()
    frameNn.setType(dai.ImgFrame.Type.BGR888p)
    frameNn.setWidth(width)
    frameNn.setHeight(height)
    frameNn.setData(toPlanar(img, (height, width)))
    input_queue.send(frameNn)