def media_publish(publisher, data): if len(data) > 0: try: (image, now) = data filename = "{}-{}-{}-{}.jpg".format(now.hour, now.minute, now.second, now.microsecond) target = "/Secure/Camera/{}/{}/{}/{}".format(now.year, now.month, now.day, filename) source = "{}/{}".format(tempfile.gettempdir(), filename) logging.info("Uploading file: {}".format(target)) cv2.imwrite(source, image) publisher.upload(source, target) os.remove(source) logging.info("Upload completed; file: {}".format(target)) except Exception as e: logging.error("Upload error {}".format(e))
def publish(publisher, data): for m in data: publisher.publish("video/event", m) print m time.sleep(1)
labels2Path = "mobilenet/object_detection_classes.txt" labels = open(labels1Path).read().strip().split("\n") labels_ru = open(labels2Path).read().strip().split("\n") vs = cv2.VideoCapture(0) (grabbed, frame) = vs.read() motion_detector = md.MotionDetector(frame) #object_detector = tod.TensorObjectDetector(weightsPath, configPath) object_detector = cod.CaffeObjectDetector(weightsPath, configPath) processor = fp.FrameProcessor(motion_detector, object_detector, labels) cv2.namedWindow("out_img", cv2.WINDOW_NORMAL) publisher_worker = publisher.PublisherThread(p.MqttPublisher("1.2.3.4", 1883, "user", "password"), data_to_publish, publish, 10) publisher_worker.start() while True: (grabbed, img) = vs.read() #img = cv2.resize(frame, (0, 0), fx=0.8, fy=0.8) (out_img, out_labels_idxs) = processor.process(img) for i in out_labels_idxs: publisher_worker.schedule(labels_ru[i]) cv2.imshow('out_img', out_img) cv2.waitKey(1) cv2.destroyAllWindows()
def get_media_publisher(media_config): return publisher.PublisherThread("media fire", mfp.MediaFirePublisher(media_config["user"], media_config["password"], media_config["maxClients"]), media_data_to_publish, media_publish, media_config["publisher"]["delay"], media_config["publisher"]["threads"])
def get_mqtt_publisher(mqtt_config): return publisher.PublisherThread("mqtt", p.MqttPublisher(mqtt_config["host"], mqtt_config["port"], mqtt_config["user"], mqtt_config["password"]), data_to_publish, publish, mqtt_config["publisher"]["delay"], mqtt_config["publisher"]["threads"])
def publish(publisher, data): for m in data: publisher.publish("video/event", m) logging.info("Publishing event: {}".format(m)) time.sleep(1)
def publish(publisher, data): (mbox, frame) = data publisher.upload("IMG_20150801_180120.jpg", "/Tmp/test.jpg")
mbox = (min(mx, x), min(my, y), max(mw, w), max(mh, h)) return mbox return None def publish(publisher, data): (mbox, frame) = data publisher.upload("IMG_20150801_180120.jpg", "/Tmp/test.jpg") vs = cv2.VideoCapture(0) cv2.namedWindow("out_img", cv2.WINDOW_NORMAL) (grabbed, frame) = vs.read() motion_detector = md.MotionDetector(frame) publisher_worker = publisher.PublisherThread(mfp.MediaFirePublisher("username", "password"), lambda q : q.pop(0), publish, 0.1) publisher_worker.start() while True: (grabbed, frame) = vs.read() boxes = motion_detector.detect(frame) mbox = max_box(boxes) if mbox: (x, y, w, h) = mbox cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2) publisher_worker.schedule((mbox, frame)) cv2.imshow('out_img', frame) cv2.waitKey(1) cv2.destroyAllWindows()