Exemple #1
0
    def cbDetectFaceLocations(self, params):
        # print(params)
        start = time.time()
        # res = self.get_frame(GetFrameRequest())
        # print("get_frame time: {} s".format(round((time.time() - start)*1000, 4)))
        # image_msg = res.image

        image_msg = self.image_msg
        if image_msg == None:
            return GetFaceDetectionsResponse()

        rect_image = toImage(self.image_msg)
        print("decode time: {} s".format(round((time.time() - start) * 1000,
                                               4)))
        boxes, labels, probs = self.detector.detect(rect_image)
        print("detect time: {} s".format(round((time.time() - start) * 1000,
                                               4)))
        print(boxes, labels, probs)
        if self.visualization:
            faces = self.detector.drawBoxes(rect_image, boxes)
            print("drawBoxes time: {} s".format(
                round((time.time() - start) * 1000, 4)))
            msg = toImageMsg(faces)
            print("encode time: {} s".format(
                round((time.time() - start) * 1000, 4)))
            self.pub_detections.publish(msg)
            # self.pub_detections.publish(self.bridge.cv2_to_imgmsg(faces,"bgr8"))
        return self.toFaceDetectionMsg()
Exemple #2
0
 def cbTextDetection(self, params):
     image = toImage(self.image_msg)
     img = image[self.roi[0][1]:self.roi[1][1],
                 self.roi[0][0]:self.roi[1][0]]
     text = ''
     try:
         text = self.detect(img, params.data)
     except Exception as e:
         print(e)
     return GetStringResponse(text)
Exemple #3
0
 def cbAddFaceLabel(self, params):
     if len(params.data) == 0:
         return SetStringResponse("添加失败,名称长度为0")
     try:
         cv_image = toImage(self.image_msg)
         res = self.recognizer.add_face_label(cv_image,
                                              params.data,
                                              save=True)
         return SetStringResponse(res)
     except Exception as e:
         print(e)
         return SetStringResponse("添加失败")
Exemple #4
0
 def cbDetectFaceLocations(self, params):
     # print(params)
     # res = self.get_frame(GetFrameRequest())
     # self.image_msg = res.image
     image_msg = self.image_msg
     if image_msg == None:
         return GetFaceDetectionsResponse()
     rect_image = toImage(image_msg)
     faces = self.recognizer.detect(rect_image)
     if self.visualization:
         # self.pub_detections.publish(self.bridge.cv2_to_imgmsg(faces,"bgr8"))
         self.pubImage(faces)
     return self.toFaceDetectionMsg(self.recognizer.face_locations)
Exemple #5
0
    def cbGetApriltagDetections(self, params):
        # res = self.get_frame(GetFrameRequest())
        # res = self.get_frame(GetFrameRequest([320,240]))
        # self.image_msg = res.image
        # print(params)
        image_msg = self.image_msg
        if image_msg == None:
            return GetApriltagDetectionsResponse()
        rect_image = toImage(image_msg)
        resized_image = cv2.resize(rect_image, (640, 480))
        # image_gray = cv2.cvtColor(resized_image, cv2.COLOR_BGR2GRAY)
        self.detector.detect(resized_image, label_tags=self.visualization)
        if self.visualization:
            resized_image = cv2.resize(resized_image, (480, 360))
            self.pubImage(resized_image)

        return self.toApriltagDetections()
Exemple #6
0
 def cbExecProc(self, params):
     image = toImage(self.image_msg)
     img = self.processor.process(image)
     self.pubImage(img)
     return GetStringResponse('执行成功')
Exemple #7
0
 def cbBarcodeScan(self, params):
     image = toImage(self.image_msg)
     barcodes = self.detect(image)
     # print(barcodes)
     self.pubImage(self.drawLabel(image, barcodes))
     return self.toBarcodeDetection(barcodes)
Exemple #8
0
 def cbImg(self, image_msg):
     self.image_msg = image_msg
     return
     cv_image = toImage(image_msg)
     cv2.rectangle(cv_image, self.roi[0], self.roi[1], (10, 255, 0), 2)
     self.pubImage(cv_image)