def image_put(q, queueid): name = queue_rtsp_dict.get(queueid, None)[1] pwd = queue_rtsp_dict.get(queueid, None)[2] ip = queue_rtsp_dict.get(queueid, None)[3] channel = queue_rtsp_dict.get(queueid, None)[4] camera_corp = queue_rtsp_dict.get(queueid, None)[5] # 大华的情况 : if camera_corp == 'dahua': full_vedio_url = "rtsp://%s:%s@%s/cam/realmonitor?channel=%s&subtype=0" % (name, pwd, ip, channel) # 网络摄像头是海康: elif camera_corp == 'hik': full_vedio_url = "rtsp://%s:%s@%s/Streaming/Channels/%s" % (name, pwd, ip, channel) if camera_corp in ('dahua', 'hik'): try: ull_vedio_url = deal_specialchar_in_url(full_vedio_url) cap = cv2.VideoCapture(full_vedio_url) # 通过timeF控制多少帧数真正读取1帧到队列中 timeF = 15 count = 1 while True: if cap.isOpened(): status, frame = cap.read() if status: if count % timeF == 0: # print('pick=', count) print(type(frame), numpy.size(frame), 'queueid=', queueid) # time.sleep(0.5) # print('sleep 0.5') sender('localhost', frame, queueid) count += 1 except cv2.error as e: print('#'*10, 'cv2 error:', e)
def device_control(): """ 物联网设备反馈api,真正使用api像rabbitmq发送消息 """ if request.method == "GET": id = session["userid"] user = User.query.filter_by(id=id).first_or_404() else: # 获取请求的smarthome标题和正文 title = request.form["title"] print('received from front-end =', title) print('#' * 20) sender('localhost', None, title) # 渲染smarthome详情页面 return rt("device_control.html", max_title="")
def HKI_base64(ip, name, pw, queueid): HKIPcamera.init(ip, name, pw) print('here0', ip, name, pw) # HKIPcamera.getfram() while 1: print(ip, name, pw, '#' * 5) # frame = HKIPcamera.getframe() frame = HKIPcamera.getframe() # time.sleep(3) # print('1.1', type(frame)) img = np.array(frame) # print('img=', img) # cv2.imshow('Camera', img) # img_gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY) sender('localhost', img, queueid) cv2.namedWindow('SDK', flags=cv2.WINDOW_NORMAL) cv2.imshow('SDK', img) cv2.waitKey(1) # print('here') time.sleep(3) HKIPcamera.release()
def image_put(queueid, sock_address): global queue_rtsp_dict if len(queue_rtsp_dict) == 0: queue_rtsp_dict = load_rtsp_dict() process = mp.current_process() process_id = process.pid print("queueid=",queueid,"process_id=", process_id) sleep_time = 1 label.begin name = queue_rtsp_dict.get(queueid, None)[1] pwd = queue_rtsp_dict.get(queueid, None)[2] ip = queue_rtsp_dict.get(queueid, None)[3] channel = queue_rtsp_dict.get(queueid, None)[4] camera_corp = queue_rtsp_dict.get(queueid, None)[5] default_enter_rule = queue_rtsp_dict.get(queueid, None)[9] print(default_enter_rule, "#" * 20) # 大华的情况 : if camera_corp == "dahua": full_vedio_url = "rtsp://%s:%s@%s/cam/realmonitor?channel=%s&subtype=0" % ( name, pwd, ip, channel, ) # 网络摄像头是海康: elif camera_corp == "hik": full_vedio_url = "rtsp://%s:%s@%s/Streaming/Channels/%s" % ( name, pwd, ip, channel, ) if camera_corp in ("dahua", "hik"): try: ull_vedio_url = deal_specialchar_in_url(full_vedio_url) cap = cv2.VideoCapture(full_vedio_url) # 通过timeF控制多少帧数真正读取1帧到队列中 timeF = 25 count = 1 if "LifeJacket" in default_enter_rule: timeF = 5 if "FireProof" in default_enter_rule: timeF = 5 if "SafetyBelt" in default_enter_rule: timeF = 25 while True: if cap.isOpened(): status, frame = cap.read() if not status: print( "ERROR:IP:[%s] sleep_time:[%d] rtsp read error!!!!!" % (ip, sleep_time) ) time.sleep(sleep_time) sleep_time = sleep_time * 2 if sleep_time >= 1024: sleep_time = 1 cap.release() goto.begin if status: cv2.imwrite(queueid + "queueid.png", frame) print(queueid, " runing") if count % timeF == 0: # print('pick=', count) # print(type(frame), numpy.size(frame), 'queueid=', queueid) # time.sleep(0.5) # print('sleep 0.5') if "LifeJacket" in default_enter_rule: sender( i13rabbitmq_config.Where_This_Server_ReadFrom, frame, queueid, "LifeJacket", ) if "FireProof" in default_enter_rule: sender( i13rabbitmq_config.Where_This_Server_ReadFrom, frame, queueid, "FireProof", ) if "SafetyBelt" in default_enter_rule: sender( i13rabbitmq_config.Where_This_Server_ReadFrom, frame, queueid, "SafetyBelt", ) sender( i13rabbitmq_config.Where_This_Server_ReadFrom, frame, queueid, "hello", ) if watch_dog_open_flag: socket_camera_obj = SocketClient(sock_address) socket_camera_obj.send(process_id) # print("socket_camera_obj=",socket_camera_obj) socket_camera_obj.close() count += 1 except cv2.error as e: print("#" * 10, "cv2 error:", e)