<jupyter_start><jupyter_text>In this notebook we develop the burn-in function, which uses the blobdetector to find blobs and then find the right number of flies and the initial position.<jupyter_code>import numpy as np
import cv2 as cv
import matplotlib.pyplot as plt

from flytracker.utils import FourArenasQRCodeMask
def default_blob_detector_params():
    # Setup SimpleBlobDetector parameters.
    params = cv.SimpleBlobDetector_Params()

    # Change thresholds
    params.minThreshold = 20
    params.maxThreshold = 150

    # Filter by Area.
    params.filterByArea = True
    params.minArea = 15
    params.maxArea = 60
    params.minDistBetweenBlobs = 1.0

    # Turn off other filters
    params.filterByCircularity = False
    params.filterByConvexity = False
    params.filterByInertia = False

    return params
path = '../../data/movies/4arenas_QR.h264'

blob_detector = cv.SimpleBlobDetector_create(default_blob_detector_params())
capture = cv.VideoCapture(path)
mask = FourArenasQRCodeMask().mask
image = cv.cvtColor(capture.read()[1], cv.COLOR_BGR2GRAY)
plt.imshow(image, cmap='gray')
plt.imshow(mask, cmap='gray')
%%time
keypoints = blob_detector.detect(image * mask)  # get keypoints
print(len(keypoints))
locs = np.array([keypoint.pt for keypoint in keypoints])
plt.figure(figsize=(15, 15))
plt.scatter(locs[:, 0], locs[:, 1], marker='x')
plt.imshow(mask * image, cmap='gray')
locs.shape
  # Run blob detector at the first n_frames to get number of flies and initial position

        
        locations = []
        for frame_idx in np.arange(n_ini_frames):
            # Load as grayscale, apply mask, f
            
            
            keypoints = blob_detector.detect(image)  # get keypoints
            print(len(keypoints))
            locations.append([keypoint.pt for keypoint in keypoints])  # extract coordinates from keypoints

        n_flies = [len(frame) for frame in locations]
        print(n_flies)
n_frames = 5
n_batch = 100
0 % n_batch
(1000 - 2 * 60)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09382716049382717, 'fraction_numerical': 0.017777777777777778, 'mean_word_length': 3.563063063063063, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '661245', 'license': 'MIT', 'n_tokens_mistral': 701, 'n_tokens_neox': 633, 'n_words': 173, 'path': 'dev/Implementing/Burn_in.ipynb', 'repo_name': 'nicolaseberle/flyTracker', 'size': '2025'}