예제 #1
0
def create_image_pb(frame, id):
    img = images_pb2.Image()
    h, w = frame.shape[:2]
    img.width = w
    img.height = h
    img.id = id
    img.imgdata = cv2.imencode('.png', frame)[1].tostring()
    return img
예제 #2
0
    def getImages(self, request_iterator, context):
        if self.userImageAccessor == None:
            self.userImageAccessor = userimage.UserImageAccessor()

        for request in request_iterator:
            imageId = request.imageId
            image = self.userImageAccessor.getImage(imageId)
            yield images__pb2.Image(imageData=image["data"].read(), imageName=image["name"], userId=request.userId)
예제 #3
0
    def getImage(self, request, context):
        if self.userImageAccessor == None:
            self.userImageAccessor = userimage.UserImageAccessor()
        image = self.userImageAccessor.getImage(request.imageId)

        resultImage = images__pb2.Image(
            imageData=image["data"].read(), imageName=image["name"], userId=request.userId)
        return resultImage
예제 #4
0
 def publish_image_pb(self, w, h, id, frame):
     if self.client == None:
         return
     img = images_pb2.Image()
     img.width = w
     img.height = h
     img.id = id
     img.imgdata = frame
     frame_pb = img.SerializeToString()
     self.client.publish(self.topic + "_pb", frame_pb)
예제 #5
0
 def on_message(self, mqttc, obj, message):
     print(message.topic + " " + str(message.qos))
     if message.topic == "ha/camera/mqtt":
         print("Matched!!!")
         nparr = np.frombuffer(message.payload, np.uint8)
         self.frame = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
         self.show_frame = True
     elif message.topic == "ha/camera/mqtt_pb":
         frame_pb = images_pb2.Image()
         frame_pb.ParseFromString(message.payload)
         print("PB img: width:", frame_pb.width, "height:", frame_pb.height)
         nparr = np.frombuffer(frame_pb.imgdata, np.uint8)
         self.frame = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
         self.show_frame = True
예제 #6
0
def on_message(client, userdata, message):
    global frame
    global showFrame
    print("Received message on topic '"
          + message.topic + "' with QoS " + str(message.qos))
    if message.topic == "ha/camera/mqtt":
        print("Matched!!!")
        nparr = np.frombuffer(message.payload, np.uint8)
        frame = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
        showFrame = True
    elif message.topic == "ha/camera/mqtt_pb":
        frame_pb = images_pb2.Image()
        frame_pb.ParseFromString(message.payload)
        print("PB img: width:",frame_pb.width, "height:", frame_pb.height)
        nparr = np.frombuffer(frame_pb.imgdata, np.uint8)
        frame = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
        showFrame = True