Example #1
0
    def getBoundingBoxes(self, image, threshold=0.8):
        bodies = self.model.detect([self.preprocessImage(image)], verbose=0)[0]
        boxes = []
        for id, score, box in zip(bodies["class_ids"], bodies["scores"],
                                  bodies["rois"]):
            if id == 1 and score > threshold:
                boxes.append(
                    BoundingBox(Vector(int(box[1]), int(box[0])),
                                Vector(int(box[3]), int(box[2]))))

        return image, boxes
Example #2
0
    def getBoundingBoxesAndMasks(self, image, threshold=0.8):
        bodies = self.model.detect([self.preprocessImage(image)], verbose=0)[0]
        boxes = []
        masks = []
        for index, (id, score, box) in enumerate(
                zip(bodies["class_ids"], bodies["scores"], bodies["rois"])):
            if id == 1 and score > threshold:
                boxes.append(
                    BoundingBox(Vector(int(box[1]), int(box[0])),
                                Vector(int(box[3]), int(box[2]))))

                masks.append(bodies["masks"][:, :, index])

        return (boxes, masks)
    def getBoundingBoxes(self, image, threshold=0.5):
        blob = cv.dnn.blobFromImage(image,
                                    1 / 255.,
                                    self.inputDim,
                                    swapRB=False,
                                    crop=False)
        self.model.setInput(blob)
        outs = self.model.forward(self.getOutputLayers())

        boxVectors = []
        confidence = []
        for out in outs:
            for detection in out:
                id = np.argmax(detection[5:])
                score = detection[5:][id]
                if id == 0 and score > threshold:
                    boxVector = detection[:4] * np.array([
                        image.shape[1], image.shape[0], image.shape[1],
                        image.shape[0]
                    ])
                    boxVectors.append([
                        int(boxVector[0] - (boxVector[2] / 2)),
                        int(boxVector[1] - (boxVector[3] / 2)),
                        int(boxVector[2]),
                        int(boxVector[3])
                    ])

                    confidence.append(float(score))

        boxes = []
        if boxVectors:
            indexes = cv.dnn.NMSBoxes(boxVectors, confidence, threshold,
                                      self.nmsThreshold)
            boxes = [
                BoundingBox(
                    Vector(boxVector[0], boxVector[1]),
                    Vector(boxVector[0] + boxVector[2],
                           boxVector[1] + boxVector[3]))
                for boxVector in map(lambda i: boxVectors[i[0]], indexes)
            ]
        return image, boxes
Example #4
0
 def add_vector(self, vid, vector_array):
     self.vectors.append(Vector(vid, vector_array))