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)
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)
def createglobalmask(total_blobs, bg_models): size = bg_models[0].bg_img.shape height = size[0] width = size[1] total_masks = [] for bg_blobs in total_blobs: global_mask = np.zeros((height, width), dtype=np.uint8) for blob in bg_blobs: blob.drawglobalmask(global_mask) total_masks.append( cv2.morphologyEx( global_mask, cv2.MORPH_CLOSE, cv2.getStructuringElement(cv2.MORPH_CROSS, (5, 10)))) """ cv2.imshow( "demo", cv2.morphologyEx( global_mask, cv2.MORPH_CLOSE, cv2.getStructuringElement( cv2.MORPH_CROSS, (5, 10)))) """ return total_masks
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)
def createglobalmask(total_blobs, bg_models): size = bg_models[0].bg_img.shape height = size[0] width = size[1] total_masks = [] for bg_blobs in total_blobs: global_mask = np.zeros((height, width), dtype=np.uint8) for blob in bg_blobs: blob.drawglobalmask(global_mask) total_masks.append(global_mask) return total_masks
def createglobalmask(total_blobs, bg_models): size = bg_models[0].bg_img.shape height = size[0] width = size[1] total_masks = [] for bg_blobs in total_blobs: global_mask = np.zeros((height, width), dtype=np.uint8) for blob in bg_blobs: blob.drawglobalmask(global_mask) total_masks.append( cv2.morphologyEx( global_mask, cv2.MORPH_CLOSE, cv2.getStructuringElement( cv2.MORPH_CROSS, (5, 10)))) """ cv2.imshow( "demo", cv2.morphologyEx( global_mask, cv2.MORPH_CLOSE, cv2.getStructuringElement( cv2.MORPH_CROSS, (5, 10)))) """ return total_masks