def image_enqueue(image_path): start_time = time.time() with open(image_path, "rb") as imageFile: # generate an ID for the classification then add the # classification ID + image to the queue k = str(uuid.uuid4()) image = helpers.base64_encode_image(imageFile.read()) d = {"id": k, "path": image_path, "image": image} DB.rpush(settings.IMAGE_QUEUE, json.dumps(d)) print("Push to redis %d ms" % int(round((time.time() - start_time) * 1000)))
def image_enqueue(fname, img, label=None): ''' :param fname: cutted image name, e.g. 0_320.jpg :param img: numpy ndarray :param label: region label corresponded :return: none ''' start_time = time.time() k = str(uuid.uuid4()) img_encoded = helpers.base64_encode_image(img) d = {"id": str(k), "path": fname, "image": img_encoded} DB.xadd(settings.IMAGE_STREAMING, d)
def streaming(): cam = cv2.VideoCapture(0) #(settings.RTSP_ADDR) start = time.time() while cam.isOpened(): _, image = cam.read() cv2.imshow('{}-{}'.format(image.shape[0], image.shape[1]), image) if cv2.waitKey(1) == ord('q'): exit() if time.time() - start < 1: continue else: start = time.time() img_height, img_width, _ = image.shape image = cv2.resize(image, (640, 480), interpolation=cv2.INTER_LINEAR) image = image.astype(np.float32) # generate an ID for the classification then add the # classification ID + image to the queue k = time.strftime('%Y-%m-%d %H:%M:%S') #str(uuid.uuid4()) image = base64_encode_image(image) d = {"id": k, "image": image} db.rpush(settings.IMAGE_QUEUE, json.dumps(d)) print(time.time() - start)
def add_embeds(self, embeds, labels): base64_embeds = [base64_encode_image(e) for e in embeds] self.db.rpush(EMBED_QUEUE, *base64_embeds) self.db.rpush(LABEL_QUEUE, *labels) self.__write_logs("INSERT", "{} embeds of {}".format(len(embeds), labels[0])) return self.update_reload_status(value=True)
def push_image(self, id, image): image = base64_encode_image(image) d = {"id": id, "image": image} return self.db.rpush(self.settings.IMAGE_QUEUE, json.dumps(d))