Exemple #1
0
def test_foreground_probability(savegif=False):

    subplt_titles = ["Original", "Foreground %"]
    ims = init_comparison_plot(get_frame_GREY(data[0]),
                               subplt_titles,
                               1,
                               2,
                               title="Probabilistic Foreground Detection")

    for i in range(len(data)):
        frame = get_frame(data[i])
        L_frame = L[:, i].reshape(width, height).T
        S_frame = S[:, i].reshape(width, height).T
        L_probability = foreground_probability(L_frame, frame)

        # this condition is now abstracted as the function cleaned_godec_img() in background_subtractio.py
        S_probability = foreground_probability(S_frame, frame)
        if np.amax(L_probability) > np.amax(S_probability):
            probability = L_probability
            img = L_frame
        else:
            probability = S_probability
            img = S_frame

        images = [normalize_frame(img), normalize_frame(probability)]
        update_comparison_plot(ims, images)
        create_folder_if_absent("testpics")
        plt.savefig("testpics/{}.png".format(i))

    if savegif:
        files = get_all_files("testpics")
        write_gif_from_pics(files,
                            "probabilistic_foreground_detection.gif",
                            fps=20)
def test_analyze_centroid_displacement_history():
    data_path = "data/teck_one_day_activity"
    files = get_all_files(data_path)
    analysis_results = analyze_centroid_displacement_history(files)
    print(analysis_results)
    write_to_json(analysis_results,
                  "displacement_{}.json".format(basename(data_path)))
def test_analyze_centroid_area_history_short_time():
    data_path = "data/teck_calib_2"
    files = get_all_files(data_path)
    analysis_results = analyze_centroid_area_history(files)
    print(analysis_results)
    write_to_json(
        analysis_results, "sample_presence_detection_analysis/{}.json".format(
            basename(data_path)))
Exemple #4
0
def test_naive_presence_detection_pipeline():
    start = time.time()
    folder_name = "sw_first_trial"
    data_path = "./data/" + folder_name
    files = get_all_files(data_path)
    print("Number of frames: ", len(files))
    result = analyze()
    end = time.time()

    print("Analysis completed in ", end - start, "seconds")
    write_to_json(result,
                  "./sample_time_series_results/{}.json".format(folder_name))
def test_analyze_centroid_displacement_history():
    start = time.time()
    data_path = "data/dataset_for_xavier/2020.07.16"
    files = get_all_files(data_path)
    print("Number of files: {}".format(len(files)))
    analysis_results = analyze_centroid_displacement_history(files)
    json_name = basename(data_path)
    print("Analysis done, writing to {}.json...".format(json_name))
    write_to_json(analysis_results,
                  "displacement_history/{}.json".format(json_name))
    end = time.time()
    print("Time taken to collect displacement dictionary for {} files : {}".
          format(len(files), end - start))
def naive_detection_from_files(data_path, startIndex=None, endIndex=None):
    heatmap_plot = get_init_heatmap_plot()
    likelihood_plot = get_init_likelihood_plot()
    files = get_all_files(data_path)
    if startIndex == None:
        startIndex = 0
    if endIndex == None:
        endIndex = len(files)
    print(startIndex, endIndex)
    for i in range(startIndex, endIndex):
        frame = get_frame(files[i])
        areas_person_is_in = naive_detection_by_frame(frame)
        likelihood_array = [[
            areas_person_is_in[i]["likelihood"] for i in range(4)
        ], [areas_person_is_in[i]["likelihood"] for i in range(4, 8)]]

        # if debugging with plot view
        update_heatmap(frame, heatmap_plot)
        update_heatmap(likelihood_array, likelihood_plot)
Exemple #7
0
from presence_detection import get_centroid_area_number, get_centroid_area_history
from background_subtraction_test import test_postprocess_img
from centroid_history import plot_centroid_history
from file_utils import get_all_files
from naive_presence_detection import (get_frame,
                                      naive_binary_likelihood_by_frame,
                                      naive_detection_by_frame,
                                      naive_detection_from_files,
                                      optical_flow_dense, optical_flow_lk,
                                      visualize_likelihood_plot)

data_path = "./data/teck_walk_out_and_in"  # dirty data with movement
# data_path = "./data/sw_second_trial" # very dirty data with no movement
files = get_all_files(data_path)
print("Number of frames found in ", data_path, ": ", len(files))
"""
Naive Presence Detection Tests
"""


def test_naive_one_frame():
    # view normal heatmap next to percentage plot
    test_frame = get_frame(files[60 * 20])
    areas_person_is_in = naive_detection_by_frame(test_frame)
    fig, ax = plt.subplots()
    im = ax.imshow(test_frame, cmap="hot")
    visualize_likelihood_plot(areas_person_is_in)


def test_naive_many_frames():
    naive_detection_from_files(files, 7200, 12000)
import matplotlib.pyplot as plt
import numpy as np

from background_subtraction_test import test_postprocess_img
from centroid_history import (Interpolator, get_centroid_area_history,
                              get_centroid_area_number,
                              displacement_history,
                              get_centroid_history, input_target_centroid_area,
                              plot_centroid_history_hexbin)
from file_utils import get_all_files
from visualizer import init_heatmap, update_heatmap

data = "data/teck_calib_2"
files = get_all_files(data)

def test_input_target_centroid_area():
    input_target_centroid_area()
    
def test_get_centroid_area_number():
    centroid = (0,0)
    print("Area number for centroid ", centroid, " is ", get_centroid_area_number(centroid))
    centroid = (12,0)
    print("Area number for centroid ", centroid, " is ", get_centroid_area_number(centroid))
    centroid = (0,12)
    print("Area number for centroid ", centroid, " is ", get_centroid_area_number(centroid))
    centroid = (6,24)
    print("Area number for centroid ", centroid, " is ", get_centroid_area_number(centroid))
    
def test_get_centroid_area_number_from_postprocess(file):
    thresholded_img, centroids = test_postprocess_img(file, plot=True)
    centroid = centroids[0]
from file_utils import get_all_files
from optical_flow import optical_flow_dense, optical_flow_lk
from visualizer import write_gif_from_pics


def test_opticalflow_lk():
    print("Performing Lucas-Kanade Optical Flow")
    optical_flow_lk(files)


def test_opticalflow_dense():
    print("Performing Dense Optical Flow with Gunnar Farneback")
    optical_flow_dense(files)


data_path = "data/teck_walk_out_and_in"
files = get_all_files(data_path)
test_opticalflow_dense()

pics = get_all_files("optical_flow_pics/")
write_gif_from_pics(pics, "dense_v2.gif", start=0, end=len(pics), fps=5)
Exemple #10
0
def test_bs_godec(files,
                  save_data=False,
                  save_gif=False,
                  gif_name=None,
                  fps=60):
    """Test bs_godec Implementation

    Keyword Arguments:
        save_data {bool} -- (default: {False})
        save_gif {bool} -- (default: {False})
        gif_name {string} -- (default: {None})
        fps {int} -- (default: {60})
    ---
    This test shows you different ways of running the bs_godec method and obtain the various type of data you need.
    """
    print("Testing Godec...")
    t = Timer("accumulate")
    t.start()
    M, LS, L, S, width, height = bs_godec(files)
    print("M: ")
    print(M)
    print("L: ")
    print(L)
    t.stop("Time taken to run background subtraction with godec: ")

    if save_data:
        t.start()

        npy_path = "godec_data/" + basename(data_path)
        create_folder_if_absent(godec_data_path)
        save_npy(M, npy_path, "M")
        save_npy(L, npy_path, "L")
        save_npy(S, npy_path, "S")
        save_npy(LS, npy_path, "LS")

        t.stop("Time taken to save godec result npy arrays: ")

    plots_path = godec_pics_path + basename(data_path)
    if not save_gif:
        print("Plotting....")
        t.start()

        plot_godec(M,
                   LS,
                   L,
                   S,
                   plots_path,
                   width=width,
                   height=height,
                   preview=True)

        t.stop("Time taken to save godec plots: ")
    elif save_gif and gif_name:
        print("Saving gif as {}....".format(gif_name))
        t.start()

        plot_godec(M, LS, L, S, plots_path, width=width, height=height)
        pics = get_all_files(plots_path)

        t.stop("Time taken to save godec plots: ")
        write_gif(pics,
                  godec_gifs_path + gif_name,
                  start=0,
                  end=len(pics),
                  fps=fps)

    print("The entire process has taken: ", t.timers['accumulate'], " seconds")
Exemple #11
0
# backgrounds = []
#
# for i in range(len(data)):
#
#     if i == 2:
#         background = generate_background_est(m, background, first_uncluttered, 0.2)
#     elif i > 2:
#         background = generate_background_est(m, backgrounds[i - 2], result[i - 1], 0.2)
#
#     backgrounds.append(background)
#     r = get_frame_GREY(data[i]) - background
#     print(r + background == get_frame_GREY(data[i]))
#     result.append(r)

# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@__xxXX__TEST____XXxx@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

data = get_all_files("data/teck_walk_out_and_in")
result, backgrounds = static_clutter_algo(data)

plt.subplot(131)
plt.imshow(get_frame_GREY(data[29]))
# plt.title("Original Image %d" % i)
plt.subplot(132)
plt.imshow(result[29])
# plt.title("clutter removed %d" % i)
plt.subplot(133)
plt.imshow(backgrounds[29])
# plt.title("backgrounds %d" % i)

plt.show()