Exemple #1
0
 def __init__(self, logger_name):
     #初始化日志模块
     self.log_name = logger_name
     self.logger = my_logging.get_logger(self.log_name)
     #
     self.is_alive_recognition_thread = False  # 识别线程状态
     # 处理线程队列
     self.light_queue = Queue.Queue()
     #线程句柄
     self.recognition_thread_id = None
     self.faster_rcnn_model = None
     self.video_stream_path = None
     #读取数据帧线程句柄
     self.read_frame_thread_id = None
     #帧率转sleep时间
     self.read_frame_time_interval = float(1) / self.read_frame_rate
     #实例化处理对象,可考虑需要时再做
     #  初始化faster_rcnn模型
     self.faster_rcnn_model = faster_rcnn_calculate(
         self.is_save_result_image, self.log_name)
     self.logger.info('ecnu 模块初始化成功')
     #打开一次视频流句柄
     self.cap = None
     #
     self.read_frame_thread_status = True
     #数据帧队列
     self.frame_queue = Queue.Queue()
Exemple #2
0
 def __init__(self, fct_id, aas_obs_id, aas_dept_id, rt_stream_path):
     # 巡检区因素编号
     self.fct_id = fct_id
     # 巡检区部门编号
     self.aas_dept_id = aas_dept_id
     # 巡检区光电编号
     self.aas_obs_id = aas_obs_id
     # 多少秒一查询巡检记录表
     self.second = 2
     # 视频地址
     self.rt_stream_path = rt_stream_path
     # 当前巡检id
     self.current_ri_id = None
     # self.test_nums = 122
     self.aas_zone_id = None
     # 日志对象声明
     self.logger = my_logging.get_logger(aas_dept_id + "_" + aas_obs_id +
                                         "_" + fct_id)
     # 数据库工具
     self.MysqldbHelper = MysqldbHelper(self.logger)
     self.video_flag = False
     self.judge = False
     # 此处初始化识别程序
     self.detection = ai_rt_stream_detection(aas_dept_id + "_" +
                                             aas_obs_id + "_" + fct_id)
     self.pumpunit_list = []
     self.alarmarea_list = []
     self.testing_video_sum = True
     # self.videoPath()
     self.azimuth = 0.0
     self.deviation_x = 0.0
     self.tvfocus = 0.0
     self.tvfoci = 0.0
     self.irfocus = 0.0
     self.irfoci = 0.0
Exemple #3
0
    def __init__(self):
        # 调用日志类
        self.logger = my_logging.get_logger(None)
        # 数据库类
        self.mysqldbHelper = MysqldbHelper(self.logger)
        # 存入当前执行的配置参数,是个字典,格式例如:fct_id + obs_id + dept_id , F001110101
        self.list = {}

        # 当前机器编号

        self.med_id = int(self.set_med_id())
        # 检测开关
        self.flag = True
Exemple #4
0
    def close(self, params, strings):
        """
        关闭程序函数

        :param params:
        :return:
        """
        pid = int(self.list[strings])
        command = "kill -9 %d" % int(self.list[strings])
        sub_process = subprocess.Popen(command.split())
        print(command)
        log = my_logging.get_logger(params['dept_id'] + "_" +
                                    params['obs_id'] + "_" + params['fct_id'])
        # log.info("部门[%s],光电[%s],因素[%s]的视频自动分析程序已关闭,进程号:%s"
        #          % (params['dept_id'], params['obs_id'], params['fct_id'], sub_process.pid))pid
        self.update_close_handle(params)
Exemple #5
0
 def update_pumps_curresult(self, pumps, logger_name):
     """
     更新抽油机状态记录
     :param pumps:
     :param logger_name:
     :return:
     """
     if self.logger is None:
         self.logger = my_logging.get_logger(logger_name)
         self.MysqldbHelper = MysqldbHelper(self.logger)
     global pump_sql, ld_sql, time_str
     time_str = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
     for temp in pumps:
         if len(temp) != 0:
             pump_sql = "select * from ldata_pumpunit_curresult " \
                        "where zcr_zone_id = '%s' and pcr_pump_id = '%s' " % (temp[1], temp[2])
             res = self.MysqldbHelper.select(pump_sql)
             if len(res) != 0:
                 ld_sql = "UPDATE ldata_pumpunit_curresult " \
                          "SET pcr_status = '%s' , pcr_updatetm = '%s', pcr_flag = '%s', pcr_ri_id = '%s' where zcr_zone_id = '%s' and pcr_pump_id = '%s' " % \
                          (temp[3], time_str, 1, temp[0], temp[1], temp[2])
                 print("update_pumps_curresult:" + ld_sql)
                 self.logger.info("更新当前巡检区结果表人车时间 :"+ld_sql)
                 self.MysqldbHelper.update(ld_sql)
                 if temp[3] == 0:
                     self.insert_inspection_process_record(temp, time_str)
             else:
                 ldata_zone_curresult_isnull_sql = "select * from ldata_zone_curresult where zcr_zone_id = '%s'" % \
                                                   temp[1]
                 isnull = self.MysqldbHelper.select(ldata_zone_curresult_isnull_sql)
                 print(ldata_zone_curresult_isnull_sql)
                 if len(isnull) == 0:
                     time_strs = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
                     ld_sql = "INSERT INTO ldata_zone_curresult (zcr_zone_id, zcr_updatetm, zcr_people, zcr_car, zcr_flag, zcr_ri_id) " \
                              "VALUES ('%s', '%s', '%d', '%d', '%d', '%s')" % (temp[1], time_strs, 0, 0, 1, temp[0])
                     print(ld_sql)
                     self.MysqldbHelper.insert(ld_sql)
                 ld_sql = "INSERT INTO ldata_pumpunit_curresult (zcr_zone_id,pcr_updatetm, pcr_pump_id, pcr_status, pcr_flag, pcr_ri_id)" \
                          " VALUES('%s', '%s', '%s', '%d', '%d', '%s')" % (temp[1], time_str, temp[2], int(temp[3]), 1, temp[0])
                 print("update_pumps_curresult:" + ld_sql)
                 self.logger.debug("增加当前巡检区结果表人车时间 :" + ld_sql)
                 self.MysqldbHelper.insert(ld_sql)
                 if temp[3] == 0:
                     self.insert_inspection_process_record(temp, time_str)
Exemple #6
0
    def start(self, params, strings):
        """
        启动程序
        :param params:
        :return:
        """
        command = "python ../dqsy/main_thread.py --aas_dept_id %s --aas_obs_id %s --fct_id %s --stream %s" \
            % (params['dept_id'], params['obs_id'], params['fct_id'], params['video_url'])
        sub_process = subprocess.Popen(command.split())

        log = my_logging.get_logger(params['dept_id'] + "_" +
                                    params['obs_id'] + "_" + params['fct_id'])
        fct = params['fct_id']
        dept = params['dept_id']
        obs = params['obs_id']
        # log.info("部门[%s],光电[%s],因素[%s]的视频自动分析程序已启动,进程号:%d,关闭进程使用:kill -9 %d"
        #             % (params['dept_id'], params['obs_id'], params['fct_id'], sub_process.pid, sub_process.pid))
        self.list[strings] = sub_process.pid
        self.update_pid(sub_process.pid, params)
Exemple #7
0
    def update_area_status(self, alarms, logger_name):
        """
        增加巡检处理记录
        :param alarms:
        :param logger_name:
        :return:
        """
        if self.logger is None:
            self.logger = my_logging.get_logger(logger_name)
            self.MysqldbHelper = MysqldbHelper(self.logger)
        alarms_car_count = 0
        alarms_person_count = 0
        ri_id = ""
        for temp in alarms:
            if temp[2] == 'person':
                ri_id = temp[0]
                alarms_person_count = alarms_person_count + temp[3]
                self.peopleCount += 1
                self.logger.info("人的处理结果总和:"+ str(self.peopleCount))
            elif temp[2] == 'car':
                alarms_car_count = alarms_car_count + temp[3]
                self.carCount += 1
                self.logger.info("车的处理结果总和:"+str(self.carCount))
        self.count = self.carCount + self.peopleCount + self.pumpCount
        self.logger.info('处理结果总和:'+str(self.count))
        if alarms_car_count != 0 or alarms_person_count != 0:
            time_str = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
            times = random.uniform(10, 20)

            ip_sql = "INSERT INTO ldata_inspection_process_record (ri_id, ipr_id, ipr_datetime, ipr_people, ipr_car) " \
                     "VALUES ('%s','%s', '%s', '%d', '%d')" % (
                     alarms[0][0], times, time_str, alarms_person_count, alarms_car_count)
            self.logger.debug("对巡检区结果表进行插入人车数量 :"+ip_sql)
            self.MysqldbHelper.insert(ip_sql)
        if len(alarms) != 0:
            self.update_zone_curresult(alarms[0][1], alarms_person_count, alarms_car_count, ri_id)
Exemple #8
0
    # 子进程列表
    sub_process_list = []

    # 每个channel分配一路处理程序
    for channel in channels:
        # 获取部门编号
        aas_dept_id = channel.get_aas_dept_id()
        # 获取光电编号
        aas_obs_id = channel.get_aas_obs_id()
        # 获取影响因素编号
        fct_id = channel.get_fct_id()
        # 获取视频流地址
        stream = channel.get_stream()

        logger = my_logging.get_logger(aas_dept_id + "_" + aas_obs_id + "_" + fct_id)

        # 调用dqsy/main_thread.py,来处理一路
        command = "python ../dqsy/main_thread.py --aas_dept_id %s --aas_obs_id %s --fct_id %s --stream %s"\
                  % (aas_dept_id, aas_obs_id, fct_id, stream)

        # 以非阻塞方式启动子进程
        sub_process = subprocess.Popen(command.split())
        sub_process_list.append(sub_process)
        logger.info("部门[%s],光电[%s],因素[%s]的视频自动分析程序已启动,进程号:%s,关闭进程使用:kill -9 %d"
                    % (aas_dept_id, aas_obs_id, fct_id, sub_process.pid, sub_process.pid))
        logger.debug("启动命令:%s" % command)

    # 必须所有子进程结束,主进程才可以结束
    for sub_process in sub_process_list:
        #体面的推出
Exemple #9
0
class ConfChange:
    logger = my_logging.get_logger()
    MysqldbHelper = MysqldbHelper(logger)
    arr0 = [
        "rtsp://*****:*****@192.168.1.33:554/h264/ch1/main/av_stream",
        "rtsp://*****:*****@192.168.1.31:554/h264/ch1/main/av_stream",
        "rtsp://*****:*****@192.168.1.36:554/h264/ch1/main/av_stream",
        "rtsp://*****:*****@192.168.1.35:554/h264/ch1/main/av_stream",
        "rtsp://*****:*****@192.168.1.39:554/h264/ch1/main/av_stream",
        "rtsp://*****:*****@192.168.1.70:554/h264/ch1/main/av_stream",
        "rtsp://*****:*****@192.168.1.73:554/h264/ch1/main/av_stream"
    ]
    arr1 = [
        "rtsp://*****:*****@192.168.1.32:554/h264/ch1/main/av_stream",
        "rtsp://*****:*****@192.168.1.30:554/h264/ch1/main/av_stream",
        "rtsp://*****:*****@192.168.1.37:554/h264/ch1/main/av_stream",
        "rtsp://*****:*****@192.168.1.34:554/h264/ch1/main/av_stream",
        "rtsp://*****:*****@192.168.1.38:554/h264/ch1/main/av_stream",
        "rtsp://*****:*****@192.168.1.71:554/h264/ch1/main/av_stream",
        "rtsp://*****:*****@192.168.1.72:554/h264/ch1/main/av_stream"
    ]

    def get_ini(self):
        szone_devationql = "SELECT * FROM ldata_effect_factor;"
        result = self.MysqldbHelper.select(szone_devationql)
        list1 = []
        for index in range(len(result)):
            list1.append(result[index]['fct_id'])
        szone_devationql = "SELECT * FROM ldata_obs_curview;"
        result = self.MysqldbHelper.select(szone_devationql)
        list2 = []
        for index in range(len(result)):
            list2.append(result[index]['ocv_obs_id'])
        sum = []
        sum.append(list1)
        sum.append(list2)
        return sum

    def get_list(self):
        list = []
        config = ConfigParser.ConfigParser()
        config.readfp(open('../conf/my.ini'))
        a = config.options("channels")
        for index in range(len(a)):
            b = config.get("channels", a[index])
            shu = b.split("/")
            end = shu[2].find(":")
            username = shu[2][0:end]
            shu2 = shu[2].split("@")
            password = shu2[0][end + 1:len(shu2[0])]
            ip0 = shu2[1]
            temp = ip0.split(":")
            ip = temp[0]
            code = shu[5]
            arr = a[index].split('_')
            arr[2] = arr[2].upper()
            strs = "部门编号:" + str(arr[0]) + ",光电编号:" + str(
                arr[1]) + ",因素编号:" + str(arr[2]) + ",用户名:" + str(
                    username) + ",密码:" + str(password) + ",ip:" + str(ip)
            list.append(strs)
        return list

    def get_section(self, id):
        list = []
        config = ConfigParser.ConfigParser()
        config.readfp(open('../conf/my.ini'))
        a = config.options("channels")
        for index in range(len(a)):
            b = config.get("channels", a[index])
            shu = b.split("/")
            end = shu[2].find(":")
            username = shu[2][0:end]
            shu2 = shu[2].split("@")

            password = shu2[0][end + 1:len(shu2[0])]

            ip0 = shu2[1]
            temp = ip0.split(":")
            ip = temp[0]
            code = shu[5]
            arr = a[index].split('_')
            arr[2] = arr[2].upper()
            list.append({
                'dept': arr[0],
                'obs': arr[1],
                'fct': arr[2],
                'username': username,
                'ip': ip,
                'password': password,
                'code': code
            })
        if (len(a) == 0):
            list.append({
                'dept': "",
                'obs': "",
                'fct': "",
                'username': "",
                'ip': "",
                'password': "",
                'code': ""
            })
            return list[0]
        return list[id]

    def edge(self, id):
        config2 = ConfigParser.ConfigParser()
        config2.readfp(open('../conf/my.ini'))
        a = config2.options("channels")
        if (id < 0 or len(a) == 0):
            return -1
        elif (id >= len(a)):
            return 1
        else:
            return 0

    def video_test(self, string):
        cap = cv2.VideoCapture(string)

        if cap.isOpened():
            return True
        return False

    def delete(self, id):
        list = []
        config2 = ConfigParser.ConfigParser()
        config2.readfp(open('../conf/my.ini'))
        a = config2.options("channels")
        if (id < 0 or id >= len(a)):
            list.append({
                'dept': "",
                'obs': "",
                'fct': "",
                'username': "",
                'ip': "",
                'password': "",
                'code': "",
                'id': 0
            })
            return list
        b = a[id].upper()
        conf_ini = "../conf/my.ini"
        config = ConfigObj(conf_ini, encoding='UTF8')
        del config['channels'][b]
        config.write()
        edge = self.edge(id)
        if (edge == -1):
            list.append({
                'dept': "",
                'obs': "",
                'fct': "",
                'username': "",
                'ip': "",
                'password': "",
                'code': "",
                'id': 0
            })
            return list[0]
        elif (edge == 0):
            list = self.get_section(id)
            list.setdefault('id', id)
            return list
        else:
            list = self.get_section((id - 1))
            list.setdefault('id', (id - 1))
            return list

    def insert(self, arr):
        obs_id = arr[0]
        fct_id = arr[1]
        key = ""
        value = ""
        if fct_id == 'F001':
            key = "1010_" + str(obs_id) + "_F001"
            value = self.arr0[int(obs_id) - 1]
        else:
            key = "1010_" + str(obs_id) + "_F003"
            value = self.arr1[int(obs_id) - 1]

        conf_ini = "../conf/my.ini"
        config = ConfigObj(conf_ini, encoding='UTF8')

        config['channels'][key] = value
        config.write()
        return True

    def update(self, arr, id):
        obs_id = arr[0]
        fct_id = arr[1]
        key = ""
        value = ""
        if fct_id == 'F001':
            key = "1010_" + str(obs_id) + "_F001"
            value = self.arr0[int(obs_id) - 1]
        else:
            key = "1010_" + str(obs_id) + "_F003"
            value = self.arr1[int(obs_id) - 1]

        self.delete(id)
        conf_ini = "../conf/my.ini"
        config = ConfigObj(conf_ini, encoding='UTF8')
        config['channels'][key] = value
        config.write()
        config2 = ConfigParser.ConfigParser()
        config2.readfp(open('../conf/my.ini'))
        a = config2.options("channels")
        return (len(a) - 1)