| | |
| | | "JOBS": [{"id": "my_job", # 任务ID |
| | | "func": "__main__:extract_voltage_send",#任务位置 |
| | | "trigger": "interval", #触发器 |
| | | "seconds": 60 # 时间间隔 |
| | | }, |
| | | {"id": "my_job2", # 任务ID |
| | | "func": "delete_task:delete_old_images",#任务位置 |
| | | "trigger": "interval", #触发器 |
| | | "seconds": 60 # 时间间隔 |
| | | "minutes": 1 # 时间间隔 |
| | | } |
| | | ]} |
| | | ) |
| | |
| | | def extract_voltage_send(): |
| | | print('extract_voltage_send job started!') |
| | | time_now = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S") |
| | | time_public=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") |
| | | app.logger.info(time_now+' extract_voltage_send job started!') |
| | | #camera = cv2.VideoCapture(0) #use 0 for web camera deplyoment |
| | | cap = cv2.VideoCapture(0) # for testing |
| | |
| | | fails_count = 0 |
| | | while True: |
| | | ret, frame = cap.read() |
| | | return_digital,job_status = extrct_digits_from_frame(frame,app.config['IMAGE_CLIP_COLS_START'],app.config['IMAGE_CLIP_COLS_END'],app.config['IMAGE_CLIP_ROWS_START'],app.config['IMAGE_CLIP_ROWS_END']) |
| | | return_digital,job_status = extrct_digits_from_frame(frame,app.config['IMAGE_CLIP_COLS_START'],app.config['IMAGE_CLIP_COLS_END'],app.config['IMAGE_CLIP_ROWS_START'],app.config['IMAGE_CLIP_ROWS_END'],app) |
| | | if job_status or fails_count > 10: |
| | | mqtt.publish(app.config['REMOTE_MQTT_PUBLISH_TOPIC'], "{'voltage':"+str(return_digital)+"}") |
| | | cv2.imwrite("./imageframe/image_frame_"+time_now+".jpg", cv2.putText(frame, str(return_digital), (app.config['IMAGE_CLIP_ROWS_START'], app.config['IMAGE_CLIP_COLS_START']), cv2.FONT_HERSHEY_COMPLEX, 1.5, (0, 255, 255), 2)) |
| | | #mqtt.publish(app.config['REMOTE_MQTT_PUBLISH_TOPIC'], "{'voltage':"+str(return_digital)+"}") |
| | | mqtt.publish(app.config['REMOTE_MQTT_PUBLISH_TOPIC'], "{\"sn\":" + "\"" + app.config['MQTT_CLIENT_ID'] +"\"" + " , \"time\":"+ "\"" + time_public +"\""+" , \"value\":"+ str(return_digital) +" }") |
| | | app.logger.info(" send the digital "+str(return_digital)) |
| | | cv2.imwrite("./image_frame/success_"+time_now+".jpg", cv2.putText(frame, str(return_digital), (app.config['IMAGE_CLIP_ROWS_START'], app.config['IMAGE_CLIP_COLS_START']), cv2.FONT_HERSHEY_COMPLEX, 1.5, (0, 255, 255), 2)) |
| | | app.logger.info("image is identified successful") |
| | | cap.release() |
| | | break |
| | | else: |
| | | fails_count +=1 |
| | | cv2.imwrite("./fails/image_frame_"+time_now+".jpg", frame) |
| | | app.logger.info("image is identified fail=======") |
| | | cv2.imwrite("./fails/fail_"+time_now+".jpg", frame) |
| | | |
| | | #if need_send _image : |
| | | # send_image |
| | | |
| | |
| | | AddJobConfig() # 配置任务,不然无法启动任务 |
| | | scheduler.init_app(app) |
| | | scheduler.start() |
| | | |
| | | app.logger.info("scheduler is running......") |
| | | #app.run() |
| | | socketio.run(app, host='0.0.0.0', port=8058, debug=True) |
| | | #mqtt.subscribe(app.config['REMOTE_MQTT_SUBSCRIBE_TOPIC']) // need to wait for mqtt client finished connection |