Esempio n. 1
0
 def add(self, pic_path: str):
     new_pic = TemplatePicture(pic_path)
     new_pic_name = new_pic.pic_name
     self._match_template_pic_dict[new_pic_name] = new_pic
     logger.info(self.TAG,
                 msg='LOAD PICTURE',
                 path=pic_path,
                 name=new_pic_name,
                 video=self.video_name)
Esempio n. 2
0
 def add(cls, video_path: str):
     new_video = SSVideo(video_path)
     new_video_name = new_video.video_name
     cls.video_dict[new_video_name] = new_video
     logger.info(cls.TAG,
                 msg='LOAD VIDEO',
                 path=video_path,
                 name=new_video_name)
     return new_video
Esempio n. 3
0
    def run(cls) -> (ResultReporter, list):
        analyser_list = check_analyser(NormalConfig.ANALYSER_LIST)
        video_dict = VideoManager.video_dict
        logger.info(cls.TAG, analyser=analyser_list, video=video_dict)

        result_reporter_list = list()
        for each_video_name, each_ssv in video_dict.items():
            result_reporter = ResultReporter(each_video_name)
            cls.analyse_video(each_ssv, analyser_list, result_reporter)
            result_reporter_list.append(result_reporter)

        # export result
        # 如果同时分析多个视频,最终结果是一个装着Reporter的list
        # 如果只分析一个视频,最终结果是一个Reporter
        if len(result_reporter_list) <= 1:
            return result_reporter_list[0]
        return result_reporter_list
Esempio n. 4
0
    def export(self, file_path):
        """ export result to json file. Path can be file, dir. """

        # check file path
        if os.path.isfile(file_path):
            logger.warn(self.TAG,
                        msg='File "{}" already existed'.format(file_path))
            file_path = os.path.join(os.path.dirname(file_path),
                                     self.result_id + '.json')
        elif os.path.isdir(file_path):
            logger.warn(self.TAG,
                        msg='Path "{}" is a directory'.format(file_path))
            file_path = os.path.join(file_path, self.result_id + '.json')

        # write file
        with open(file_path, 'w+') as json_file:
            json_file.write(str(self.data))
            logger.info(self.TAG, msg='Result saved in "{}"'.format(file_path))
Esempio n. 5
0
    def analyse_video(cls, ssv_video: SSVideo, analyser_list: list,
                      result_reporter: ResultReporter):
        """ analyse ssv video """
        with video_capture(ssv_video) as each_video:
            ret, frame = each_video.read()
            while ret:
                if not ret:
                    # end of video
                    break

                # prepare frame
                frame = frame_prepare(frame)
                # rotate
                frame = rotate_pic(frame, ssv_video.rotate)

                # current status
                cur_frame_count = int(each_video.get(cv2.CAP_PROP_POS_FRAMES))
                cur_second = each_video.get(cv2.CAP_PROP_POS_MSEC) / 1000

                # new row of result
                new_row = ResultRow(
                    result_reporter.result_id,
                    ssv_video.video_path,
                    cur_frame_count,
                    cur_second,
                )

                for each_analyser in analyser_list:
                    result = each_analyser.run(frame, ssv_video)
                    new_row.add_analyser_result(each_analyser.name, result)

                logger.info(cls.TAG, msg='analysing', **new_row.__dict__)
                result_reporter.add_row(new_row)

                # read new frame
                ret, frame = each_video.read()

        # clean analyser
        for each in analyser_list:
            each.clean()
Esempio n. 6
0
    def draw(cls, content: list, dst_path: str):
        # base page
        page = Page()

        # time line,直接用float作为x轴会出现 echarts 兼容问题
        time_list = [str(each['current_time']) for each in content]

        # 目前只支持 match_template 与 trend 的图表绘制
        draw_type_dict = {
            'match_template': cls.build_match_template_line,
            'trend': cls.build_trend_line,
        }
        for each_type, each_func in draw_type_dict.items():
            # 以第一项为例检验是否包含该类分析结果
            if each_type not in content[0]:
                continue

            data_list = [each_data[each_type] for each_data in content]
            data_line = draw_type_dict[each_type](time_list, data_list)
            page.add(data_line)

        page.render(dst_path)
        logger.info(cls.TAG,
                    msg='report built finished: "{}"'.format(dst_path))