def send_result(self): rabbit = Rabbit() # rabbitMQ print("self.level_arr: ", self.level_arr) self.result_data['level'] = int(np.mean(self.level_arr)) if len( self.level_arr) else 0 rabbit.create_queue(var.rabbitmq_queue['result_black'], self.result_data) self.level_arr = []
def end_black_test(self, dot_id): dn_darkness_id = "dn_darkness_" + dot_id stop_data = { "type": "stop" } print("dn_darkness_id=", dn_darkness_id, "close black test") # print("stop_data=", stop_data) rabbit = Rabbit() # rabbitMQ rabbit.create_queue(dn_darkness_id, stop_data)
def send_dn_result(self): # 生成图片 img_filename = str(time.time()) + '.jpg' evidence_img_path = os.path.join(var.local_path['keyframe_path'], img_filename) if len(self.max_darkness_frame) > 0: utils.write_log(str(self.camera), "send_dn_result 生成检出图片") cv2.imwrite(evidence_img_path, self.max_darkness_frame) self.result_dn_data['evidence_img'].append(img_filename) print(self.lingerman_darkness, type(self.lingerman_darkness)) if self.lingerman_bool == 1: self.result_dn_data['level'] = int(self.lingerman_darkness) self.result_dn_data['board_bool'] = 1 utils.write_log(str(self.camera), "林格曼等级lingerman_darkness = "+ str(self.lingerman_darkness)) # if self.result_dn_data['smoke_change']: utils.write_log(str(self.camera), "self.pass_frame_num = "+ str(self.pass_frame_num)) utils.write_log(str(self.camera), "原来的level = "+ str(self.result_dn_data['level'])) # if self.pass_frame_num >= 35: # self.result_dn_data['level'] = 0 # 判断是否检出黑烟 if self.result_dn_data['level'] >= 2 and self.lingerman_bool != 1: utils.write_log(str(self.camera), "send_dn_result 检出黑烟") self.result_dn_data['result'] = 1 # 写入redis self.data = r.get_values(self.camera) self.data['rath_end'] = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) self.data['rath_board_time'] = round(time.time() - self.start_time,2) self.data['filedata'] = { "xmin": 0, "ymin": 0, "xmax": 0, "ymax": 0 } self.data['status'] = "rath ending" r.set_values(self.camera ,self.data) utils.write_log(str(self.camera), "send_dn_result 写入观察redis: ") utils.write_log(str(self.camera), self.data) rabbit = Rabbit() rabbit.create_queue(var.rabbitmq_queue['dn_darkness_result'], self.result_dn_data) # 打印日志 self.temp_write_log(self.result_dn_data)
def measurement (self, zset, dn_rtsp, camera_rtsp, dot_id, task_id): print("dot_id=",dot_id, "darkness start") # 开启计量 blacktest_id = "blacktest_" + dot_id filename = str(int(time.time())) source_name = "source_" + filename + ".mp4" dist_name = "dist_" + filename + ".mp4" formdata = { "type": "start", "source_name": source_name, "dist_name": dist_name, "camera": zset } rabbit = Rabbit() # rabbitMQ rabbit.create_queue(blacktest_id, formdata) time_length = 10 for i in range(time_length): time.sleep(1) print(time_length - i) formdata["type"] = "stop" rabbit.create_queue(blacktest_id, formdata)
def measurement(self, zset, dn_rtsp, camera_rtsp, dot_id, task_id): pass # 根据调用的id和type开启一个计量线程 # 找板 # overtime = self.find_board(dn_rtsp, camera_rtsp, dot_id, task_id) # 等待找板结束 # 判断开启那一个 # 情况分类 ''' 首先判断返回的超时时间,得出当前球机是否找到了板 然后判断你的兄弟球机的找板函数是否在运行 假如在的话就是你先运行。 假如不在的话就是已经有程序在运行了。 ''' # 超时时间大于0,说明找到了板 # if overtime > 0: # # 判断兄弟球机的找板函数状态 # command = "ps -ef | grep -v grep | grep " + dn_rtsp + " | grep find_board.py | awk '{print $2}' | wc -l" # camera_run_bool = os.popen(command).read() # 判断那一个程序进入计量/测烟 # 开启计量 blacktest_id = "blacktest_" + dot_id filename = str(int(time.time())) source_name = "source_" + filename + ".mp4" dist_name = "dist_" + filename + ".mp4" formdata = { "type": "start", "source_name": source_name, "dist_name": dist_name, "camera": zset } rabbit = Rabbit() # rabbitMQ rabbit.create_queue(blacktest_id, formdata) time_length = 10 for i in range(time_length): time.sleep(1) print(time_length - i) formdata["type"] = "stop" rabbit.create_queue(blacktest_id, formdata)
def consumer_board_thread(self): rabbit = Rabbit() rabbit.consumer(var.rabbitmq_queue['result_black'], self.consumer_result_black)
import json, os from route import camera_blue from extend.rabbitMQ import Rabbit from flask import request from extend.variables import Variables from extend.utils import Utils rabbit = Rabbit() # rabbitMQ var = Variables() # 初始化变量 utils = Utils() # 初始化工具函数 # 刷新网点黑度 def refresh_data(): camera_list = utils.load_json(var.config_path['camera_list']) camera_dots = [item['dot_id'] for item in camera_list['camera_list']] darkness_level = utils.load_yaml(var.config_path['darkness_level']) new_darkness_level = {"camera": {}} for item in camera_dots: dot_exists = False for its in darkness_level['camera']: if its == item: dot_exists = True new_darkness_level['camera'][item] = darkness_level['camera'][ its] break if not dot_exists: new_darkness_level['camera'][item] = { 0: 0, 1: 20, 2: 40,
def consumer_darkness_thread(self): rabbit = Rabbit() rabbit.consumer("dn_darkness_result", self.consumer_dn_darkness_result)
def consumer_board_thread(self): rabbit = Rabbit() rabbit.consumer("find_board", self.consumer_find_board)
def listen_blacktest(self): rabbit = Rabbit() # rabbitMQ rabbit.consumer( var.rabbitmq_queue['blacktest'] + '_' + str(self.camera), self.blacktest)
def listen_darkness(self): rabbit = Rabbit() # rabbitMQ rabbit.consumer( var.rabbitmq_queue['darkness_level'] + '_' + str(self.camera), self.consumer_controll)