def process_frame(left_frame, right_frame, ir_frame): print('\n\n------------- New Frame -------------') global detected_humans global human_id_counter frame_1 = left_frame frame_2 = right_frame # detect humans in the frame boxes_1 = human_detection.detection(left_frame, right_frame, ir_frame, args['disparity']) print('positions where we have detected humans in the frame: {}'.format( boxes_1)) # track the humans # for each entry in the detector compare the detected postion with the postition of the humans that are already in the list # if there is no human in the range, create a new human and add it to the list if detected_humans: new_occurances = tracking.detect_new_occurance_and_update_positions( frame_1, threshold_tracking_deviating, boxes_1, detected_humans) for new_block in new_occurances: # calculate the histogram for the newly detected human image_in_bounding_box = frame_1[ int(new_block[1]):int(new_block[1]) + int(new_block[3]), int(new_block[0]):int(new_block[0]) + int(new_block[2])] hist = histogram.create_histogram(image_in_bounding_box) detected_humans.append( human.Human(human_id_counter, new_block, hist)) human_id_counter = human_id_counter + 1 else: for new_block in boxes_1: # calculate the histogram for the newly detected human image_in_bounding_box = frame_1[ int(new_block[1]):int(new_block[1]) + int(new_block[3]), int(new_block[0]):int(new_block[0]) + int(new_block[2])] hist = histogram.create_histogram(image_in_bounding_box) detected_humans.append( human.Human(human_id_counter, new_block, hist)) human_id_counter = human_id_counter + 1 # remove all humans from the list that have a non_detected counter higher than the threshold detected_humans = list( filter( lambda x: x.get_untracked_frame_counter() < threshold_tracking_undetected_frames, detected_humans)) print( 'our human list after filtering out all humans that were not detected for a few frames: {}' .format(detected_humans)) # update fps fps.update() if args['display']: if ir_frame is not None: display.display_with_humans([frame_1, ir_frame], [detected_humans, []]) else: display.display_with_humans([frame_1], [detected_humans])
def index(): #example_words = ['one', 'fish', 'two', 'fish', 'red', 'fish', 'blue', 'fish']; example_words = histogram.convert_to_array example_histo = histogram.create_histogram(example_words) tokens = len(example_words) ex_frequencies = histogram.get_frequencies(example_histo, tokens) histogram.create_word_range(ex_frequencies) random_word = histogram.stochastic(ex_frequencies) return render_template('index.html', random_word=random_word)
def create_all_histograms(pca_videos, codebooks, concatenate = 1, concatenate2 = 1): video_histograms = [] '''with Pool(get_threads()) as p: histograms = list(p.map(create_histogram, pca_videos, [codebooks]*len(pca_videos))) video_histograms.append(histograms) ''' for pca in pca_videos: histograms = [] if concatenate2 > 1: for i in range(concatenate2): if i == 0: histograms = create_histogram(pca[i::concatenate2], codebooks, concatenate) else: histograms = np.concatenate((histograms, create_histogram(pca[i::concatenate2], codebooks, concatenate)), axis = 0) else: histograms = create_histogram(pca, codebooks, concatenate) video_histograms.append(histograms) return video_histograms
def compile_histograms(target_dir): main_histogram = {} for file in os.listdir(target_dir): histogram = create_histogram(os.path.join(target_dir, file)) for key in histogram.keys(): main_histogram[key] = main_histogram.setdefault(key, 0) + histogram[key] hist_list = [] for key in main_histogram.keys(): hist_list.append((main_histogram[key], key)) hist_list.sort(reverse=True) counter = 0 max_count = 10000 for word in hist_list: if counter <= max_count: print(word) counter += 1 else: break
def main(): sentence = raw_input('Sentence: ').lower() words = create_words_list(sentence) histogram = create_histogram(words) print top3(histogram)
def detect_new_occurance_and_update_positions(frame, max_deviation, detected_bounding_boxes, detected_humans): # for each bounding box that was detected we calculate the euclidian distance of its center to the center of the bounding boxes that are available result_list = detected_bounding_boxes.copy() # we initialize the list of the previous humans that were not detected in this frame with all previous humans. If the humans is discovered in this frame its reference will be removed from the list non_detected_humans = detected_humans.copy() unmatched_previous_humans = detected_humans.copy() if unmatched_previous_humans: for detected_bounding_box in detected_bounding_boxes: detected_centroid = (detected_bounding_box[0] + detected_bounding_box[2] / 2, detected_bounding_box[1] + detected_bounding_box[3] / 2) detected_histogram = histogram.create_histogram( frame[detected_bounding_box[1]:detected_bounding_box[1] + detected_bounding_box[3], detected_bounding_box[0]:detected_bounding_box[0] + detected_bounding_box[2]]) for human in unmatched_previous_humans: new_centroid = human.get_current_position( )[0] + human.get_current_position( )[2] / 2, human.get_current_position( )[1] + human.get_current_position()[3] / 2 # for each bounding box we sort the previous human occurances by their proximity. If the closest previous_human is lower (e.g. closer) than the threshold, it is considered to be the same unmatched_previous_humans.sort( key=lambda human: euclidian_distance( (human.get_current_position()[0] + human. get_current_position()[2] / 2, human.get_current_position( )[1] + human.get_current_position()[ 3] / 2), detected_centroid)) # filter out all humans that are not in the range anyway unmatched_previous_humans_within_range = list( filter( lambda human: euclidian_distance( (human.get_current_position()[ 0] + human.get_current_position()[2] / 2, human.get_current_position()[1] + human. get_current_position()[3] / 2), detected_centroid) < max_deviation, unmatched_previous_humans)) # sort the humans that are left by the similarity of their histogram unmatched_previous_humans_within_range.sort( key=lambda human: histogram.compare_histograms( detected_histogram, human.get_histogram())) if unmatched_previous_humans_within_range: centroid_of_closest_unmatched_human = unmatched_previous_humans_within_range[ 0].get_current_position( )[0] + unmatched_previous_humans_within_range[ 0].get_current_position( )[2] / 2, unmatched_previous_humans_within_range[ 0].get_current_position( )[1] + unmatched_previous_humans_within_range[ 0].get_current_position()[3] / 2 print( 'we have a match between a newly detected human and an entry in our previous list!' ) # if the position is close enough we know that we dont need to add a new human result_list.remove(detected_bounding_box) # update the position of the human. Note since we used a shallow copy for the creation of the sorted_humans the following code updates the elements in the original detected_humans list unmatched_previous_humans[0].update_position( detected_bounding_box) # we found an occurance of that human so we can remove if from the 'not found' list non_detected_humans.remove(unmatched_previous_humans[0]) unmatched_previous_humans.remove(unmatched_previous_humans[0]) for human in non_detected_humans: human.increase_untracked_frame_counter() return result_list
import cv2 import basic_operations import utils import histogram import filters img = utils.load_image('girl.bmp') hist = histogram.create_histogram(img) def contrast_param_change(x): value = x/10 utils.display_image('image',basic_operations.adjust_contrast(img, value), hist) def brightness_param_change(x): value = x - 256 utils.display_image('image',basic_operations.adjust_brightness(img, value),hist) def negative_switch(x): if x == 1: utils.display_image('image', basic_operations.create_negative(img), hist) else: utils.display_image('image', img, hist) def average_filter_change(lvl): if lvl != 0: utils.display_image('image', filters.apply_average_filter(img, lvl), hist) else: utils.display_image('image', img, hist)
def init(): word = raw_input('Word: ') print create_histogram(word)
observations, avg_time_per_order, avg_time_observed, delta, ) avg_delta = float(total_delta) / trials output += "+-------+--------------+--------------+---------+----------+---------+\n" output += "| Average | %-7.2f |\n" % (avg_delta) output += "+----------------------------------------------------------+---------+" return output table = do_many_trials(50) histogram = histogram.create_histogram("Distribution of Transaction Times", 31) l_table = table.split('\n') l_histogram = histogram.split('\n') if len(l_table) > len(l_histogram): l_histogram += ['']*(len(l_table) - len(l_histogram)) elif len(l_histogram) > len(l_table): l_table += [" "] * (len(l_histogram) - len(l_table)) z = zip(l_table, l_histogram) print "\n".join([x + " " + y for x,y in z])