Ejemplo n.º 1
0
    def run_ntimes_oneblob(self):
        """
        Run the BlobFinder on one blob
        """
        self.background = background()
        self.mask = mask(self.background)
        blob = randomblob(self.background)[0]
        self.bfinder = BlobFinder(self.mask)
        # init background
        for _ in range(10):
            blob = randomblob(self.background)[0]
            self.bfinder.run(blob)

        self.blobs_center = list()
        self.blobs_found = list()
        for frame_i in range(10):
            blob, blob_center, _, _ = \
                randomblob(self.background)
            self.bfinder.run(blob)
            self.blobs_center.append(blob_center)
            self.blobs_found.append(self.bfinder.filtered_contours)

        self.blob = blob
Ejemplo n.º 2
0
bfinder.roundness_lim = [0, 1]
bfinder.background_init = 60
bfinder.threshold = 10
bfinder.gaussian_blur = 1
bfinder.skip_filter_contours = False
# Parameter for croping
xmargin = [0, 0]
ymargin = [0, 0]

# Build up an expected histogram
ninitframes = 50
bin_edges = np.arange(1, 255)
ref_cumsum = np.zeros(bin_edges.shape[0] - 1)
for _ in range(bfinder.background_init):
    # grab the current frame and initialize the occupied/unoccupied
    frame = btgen.randomblob(background, color=blob_brightness[0])[0]
    bfinder.run(frame)

for _ in range(ninitframes):
    # grab the current frame and initialize the occupied/unoccupied
    frame = btgen.randomblob(background, color=blob_brightness[0])[0]
    bfinder.run(frame)
    #
    image = bfinder.original_image
    image = image.astype(np.float)
    image[bfinder.processed_image == 0] = np.nan
    croped_images = crop(image, bfinder.filtered_contours, xmargin, ymargin)
    hist = btfilt.image2hist(croped_images[0], bin_edges)
    cumsum = btfilt.hist2cumsum(hist)
    ref_cumsum += cumsum / ninitframes
Ejemplo n.º 3
0
background = btgen.background()
mask = btgen.mask(background)
# Create a bfinder tracker
bfinder = BlobFinder(mask)
bfinder.erode_iter = 2
bfinder.dilate_iter = 2
bfinder.area_lim = [0, 10000]
bfinder.roundness_lim = [0, 1]
bfinder.background_init = 60
bfinder.threshold = 10
bfinder.gaussian_blur = 1
bfinder.skip_filter_contours = False

frame_i = 0
while True:
    # grab the current frame and initialize the occupied/unoccupied
    frame = btgen.randomblob(background, color=100)[0]
    for _ in range(1, nblobs):
        frame = btgen.randomblob(frame, color=100)[0]
    bfinder.run(frame)
    # display images when asked
    if (time.time() - t_start) > refresh_time:
        t_start = time.time()
        if bfimshow.original_image(bfinder, scale, frame_i, 5):
            break
    # Before next loop run
    frame_i += 1

# cleanup the camera and close any open windows
cv2.destroyAllWindows()