Exemplo n.º 1
0
Arquivo: blob.py Projeto: lacatus/TFM
    def __applymeanthreshold(self, blob_img):

        size = blob_img.shape
        height = size[0]
        width = size[1]

        mask = np.zeros((height, width), dtype=np.uint8)

        smooth_projection_x = self.smooth_projection[0]
        mean_x = int(self.mean[0] / 4)
        smooth_projection_y = self.smooth_projection[1]
        mean_y = int(self.mean[1] / 3)

        # Mask in X
        for ii in xrange(0, height - 1, 1):

            if (smooth_projection_x[ii] >= mean_x):
                mask[ii, :] = 255

        # Mask in Y
        for jj in xrange(0, width - 1, 1):

            if (smooth_projection_y[jj] >= mean_y):
                mask[:, jj] = 255

        # By now only mask in y projection
        self.mask = cv2.bitwise_and(blob_img, blob_img, mask=mask)
Exemplo n.º 2
0
    def __applymeanthreshold(self, blob_img):

        size = blob_img.shape
        height = size[0]
        width = size[1]

        mask = np.zeros((height, width), dtype=np.uint8)

        smooth_projection_x = self.smooth_projection[0]
        mean_x = int((self.mean[0]*2) / 3)
        smooth_projection_y = self.smooth_projection[1]
        mean_y = int((self.mean[1]*2) / 3)

        # Mask in X
        for ii in xrange(0, height - 1, 1):

            if(smooth_projection_x[ii] >= mean_x):
                mask[ii, :] = 255

        # Mask in Y
        for jj in xrange(0, width - 1, 1):

            if(smooth_projection_y[jj] >= mean_y):
                mask[:, jj] = 255

        # By now only mask in y projection
        self.mask = cv2.bitwise_and(blob_img, blob_img, mask=mask)
Exemplo n.º 3
0
Arquivo: blob.py Projeto: lacatus/TFM
    def drawmask(self, frame):

        # Create colored mask for visualization
        x, y, w, h = self.bound_rect

        mask_color = np.zeros((h, w, 3), dtype=np.uint8)
        mask_color[:, :, 1] = 255  # Assign blue color to created colored mask
        mask_color = cv2.bitwise_and(mask_color, mask_color, mask=self.mask)

        frame[y:y + h, x:x + w] = cv2.add(frame[y:y + h, x:x + w], mask_color)
Exemplo n.º 4
0
    def drawmask(self, frame):

        # Create colored mask for visualization
        x, y, w, h = self.bound_rect

        mask_color = np.zeros((h, w, 3), dtype=np.uint8)
        mask_color[:, :, 1] = 255  # Assign blue color to created colored mask
        mask_color = cv2.bitwise_and(mask_color, mask_color, mask=self.mask)

        frame[y:y + h, x:x + w] = cv2.add(frame[y:y + h, x:x + w], mask_color)
Exemplo n.º 5
0
def globalmasktosubjects(total_masks, bg_models, cameras, frames):

    debug_flag = 0

    if debug_flag:
      print(">> Detecciones")

    total_subjs = []

    win_width = bg_models[0].win_width
    win_height = bg_models[0].win_height

    for ii in range(len(total_masks)):

        subjs = []

        # OpenCV 2.4.8
        contours, hierarchy = cv2.findContours(
            total_masks[ii], cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
        """
        # OpenCV 3.0.0
        _, contours, hierarchy = cv2.findContours(
            total_masks[ii], cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
        """

        res =  cv2.bitwise_and(frames[ii], frames[ii], mask = total_masks[ii])

        for cont in contours:

            x, y, w, h = cv2.boundingRect(cont)
            box = [x, y, w, h]

            if w >= (win_width / 2) and h >= (win_height / 2):

                ellipse = cv2.fitEllipse(cont)
                rot_box = cv2.minAreaRect(cont)
                circle = cv2.minEnclosingCircle(cont)
                subj = subject.Subject()
                subj.setdefault(
                    total_masks[ii][y:y + h, x:x + w],
                    box, rot_box, ellipse, circle, cameras[ii], cont,
                    res[y:y + h, x:x + w])
                subjs.append(subj)

                if debug_flag:
                  print(box)


        total_subjs.append(subjs)

    return total_subjs
Exemplo n.º 6
0
def globalmasktosubjects(total_masks, bg_models, cameras, frames):

    debug_flag = 0

    if debug_flag:
        print(">> Detecciones")

    total_subjs = []

    win_width = bg_models[0].win_width
    win_height = bg_models[0].win_height

    for ii in range(len(total_masks)):

        subjs = []

        # OpenCV 2.4.8
        contours, hierarchy = cv2.findContours(total_masks[ii],
                                               cv2.RETR_EXTERNAL,
                                               cv2.CHAIN_APPROX_NONE)
        """
        # OpenCV 3.0.0
        _, contours, hierarchy = cv2.findContours(
            total_masks[ii], cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
        """

        res = cv2.bitwise_and(frames[ii], frames[ii], mask=total_masks[ii])

        for cont in contours:

            x, y, w, h = cv2.boundingRect(cont)
            box = [x, y, w, h]

            if w >= (win_width / 2) and h >= (win_height / 2):

                ellipse = cv2.fitEllipse(cont)
                rot_box = cv2.minAreaRect(cont)
                circle = cv2.minEnclosingCircle(cont)
                subj = subject.Subject()
                subj.setdefault(total_masks[ii][y:y + h, x:x + w], box,
                                rot_box, ellipse, circle, cameras[ii], cont,
                                res[y:y + h, x:x + w])
                subjs.append(subj)

                if debug_flag:
                    print(box)

        total_subjs.append(subjs)

    return total_subjs