Esempio n. 1
0
    def standard_test(self):

        # Use the Percent Matcher to get an estimate of the match ranges.
        start_time = time.time()
        match_ranges = self.pm.get_match_ranges()
        util.display_total_time(start_time, "Percent Matching")

        # Use the Stage Detector to determine the match bboxes and labels and
        # exit if a stage was not found within any of the match ranges.
        start_time = time.time()
        new_match_ranges, match_bboxes, match_labels = \
            self.sd.get_match_info(match_ranges)
        if match_labels:
            util.display_total_time(start_time, "Stage Detection")
            print("\tMatch Bboxes: {:}".format(match_bboxes))
            print("\tMatch Labels: {:}".format(match_labels))
            match_times = [(mr[1] - mr[0]) // 30 for mr in new_match_ranges]
            print("\tMatch Times: {:}".format(match_times))
        else:
            print("\tNo stage detected!")
            return False

        # Use the Percent Matcher to get an estimate of the ports in use.
        port_nums = self.pm.get_port_num_list(new_match_ranges, match_bboxes)
        print("\tPorts in Use: {:}".format(port_nums))

        # Create a dict to return the relevant video info.
        video_info = dict()
        video_info['match_times'] = match_times
        video_info['match_labels'] = match_labels
        video_info['port_nums'] = port_nums
        return video_info
Esempio n. 2
0
def run_va_over_video_folder():

    # Create a single darkflow object to be reused by each video analyzer.
    start_total_time = time.time()
    tfnet = TFNet(TFNET_OPTIONS)
    video_info_list = list()

    # Perform video analysis over all the videos in the video directory.
    for file_name in os.listdir('videos'):

        # Skip the files that do not contain a .mp4 extension
        if "mp4" not in file_name:
            continue
        video_location = "{:s}/{:s}".format('videos', file_name)
        va = video_analysis.VideoAnalyzer(video_location, tfnet,
                                          args.show_flag)
        video_info_list.append(va.standard_test())

    # Calculate the overall video statistics
    print("====TOTAL STATS====")
    match_times, match_labels, port_nums = list(), list(), list()
    for video_info in video_info_list:
        match_times.extend(video_info['match_times'])
        match_labels.extend(video_info['match_labels'])
        port_nums.extend(video_info['port_nums'])

    # Time Statistics
    avg_time = sum(match_times) // len(match_times)
    print("Average match time {:}:{:02d}".format(avg_time // 60,
                                                 avg_time % 60))

    # Stage Statistics
    label_list = [
        "battlefield", "dreamland", "finaldest", "fountain", "pokemon",
        "yoshis"
    ]
    for label in label_list:
        label_percentage = 100 * match_labels.count(label) / len(match_labels)
        print("Stage {:}: {:.2f}%".format(label, label_percentage))

    # Port Number Statistics
    for i in [1, 2, 3, 4]:
        port_percentage = 100 * port_nums.count(i) / len(port_nums)
        print("Port {:}: {:.2f}%".format(i, port_percentage))

    util.display_total_time(start_total_time, "Analyze")
Esempio n. 3
0
    def timeline_test(self):

        # Use a random number of frames to calibrate the percent template size.
        start_time = time.time()
        self.initialize_template_scale()
        util.display_fps(start_time, self.num_init_frames, "Initialize")

        # Iterate through the video to identify when percent is present.
        start_time = time.time()
        pct_timeline = self.get_pct_timeline()
        frame_count = (self.stop_fnum - self.start_fnum) // self.step_size
        util.display_fps(start_time, frame_count, "Initial Sweep")

        # Fill holes in the history timeline list, and filter out timeline
        # sections that are smaller than a particular size.
        clean_timeline = timeline.fill_filter(pct_timeline,
                                              self.max_tl_gap_size)
        clean_timeline = timeline.size_filter(clean_timeline, self.step_size,
                                              self.min_match_length_s)
        if self.show_flag:
            timeline.show_plots(pct_timeline, clean_timeline, ["pct found"])

        # Display the frames associated with the calculated match ranges.
        timeline_ranges = timeline.get_ranges(clean_timeline)
        match_ranges = np.multiply(timeline_ranges, self.step_size)
        if self.show_flag:
            util.show_frames(self.capture, match_ranges.flatten())

        # Display the frames associated with the precise match ranges.
        start_time = time.time()
        new_match_ranges = self.get_precise_match_ranges(match_ranges)
        util.display_total_time(start_time, "Cleaning Sweep")
        print("\tMatch Ranges: {:}".format(match_ranges.tolist()))
        print("\tPrecise Match Ranges: {:}".format(new_match_ranges.tolist()))
        if self.show_flag:
            util.show_frames(self.capture, new_match_ranges.flatten())
Esempio n. 4
0
    def get_port_num_list(self, match_ranges, match_bboxes):

        start_time = time.time()
        for i, match_range in enumerate(match_ranges):
            random_fnum_list = np.random.randint(low=match_range[0],
                                                 high=match_range[1],
                                                 size=self.num_port_frames)

            # print(match_range)
            x_pos_list = list()
            for fnum in random_fnum_list:
                frame = util.get_frame(self.capture, fnum, self.gray_flag)
                _, bbox_list = self.get_tm_results(frame, 4)
                for bbox in bbox_list:
                    x_pos_list.append(bbox[0][0])
                # print((fnum, conf_list, bbox_list))

            port_pos_list = position_tools.get_port_pos_list(x_pos_list)
            port_num_list = position_tools.get_port_num_list(
                port_pos_list, match_bboxes[i])
            # print(port_num_list)

        util.display_total_time(start_time, "Port Sweep")
        return port_num_list
Esempio n. 5
0
def show_ocr_result(frame):
    start_time = time.time()
    text = pytesseract.image_to_string(frame, lang="eng", config="--psm 8")
    print(text)
    util.display_total_time(start_time)

    start_time = time.time()
    pytess_result = pytesseract.image_to_boxes(
        frame,
        lang="eng",
        config="--psm 8",
        output_type=pytesseract.Output.DICT)
    print(pytess_result)
    util.display_total_time(start_time)

    bbox_list = list()
    for i, _ in enumerate(pytess_result['bottom']):
        tl = (pytess_result['left'][i], pytess_result['bottom'][i])
        br = (pytess_result['right'][i], pytess_result['top'][i])
        bbox_list.append((tl, br))
    util.show_frame(frame, bbox_list=bbox_list, wait_flag=True)

    start_time = time.time()
    pytess_data = pytesseract.image_to_data(
        frame,
        lang="eng",
        config="--psm 8",
        output_type=pytesseract.Output.DICT)
    print(pytess_data)
    util.display_total_time(start_time)

    bbox_list = list()
    for i, conf in enumerate(pytess_data['conf']):
        if int(conf) != -1:
            print("\tconf: {}".format(conf))
            tl = (pytess_data['left'][i], pytess_data['top'][i])
            br = (tl[0] + pytess_data['width'][i],
                  tl[1] + pytess_data['height'][i])
            bbox_list.append((tl, br))
    util.show_frame(frame, bbox_list=bbox_list, wait_flag=True)