コード例 #1
0
 def fire_vehicle_detected_event(self, vehicle):
     """Send event."""
     self.hass.bus.fire(
         EVENT_VEHICLE_DETECTED,
         {
             ATTR_ENTITY_ID:
             self.entity_id,
             ATTR_PLATE:
             vehicle["licenseplate"],
             ATTR_VEHICLE_TYPE:
             vehicle["vehicleType"],
             ATTR_MAKE:
             vehicle["make"],
             ATTR_MODEL:
             vehicle["model"],
             ATTR_COLOR:
             vehicle["color"],
             ATTR_REGION:
             vehicle["region"],
             ATTR_BOUNDING_BOX:
             hound.bboxvert_to_tf_style(vehicle["boundingBox"],
                                        self._image_width,
                                        self._image_height),
         },
     )
コード例 #2
0
def test_bboxvert_to_tf_style():
    bbox = RECOGNITIONS_LICENSEPLATE["objects"][0]["licenseplateAnnotation"][
        "bounding"]
    img_width = 960
    img_height = 480
    assert hound.bboxvert_to_tf_style(bbox, img_width, img_height) == (
        0.6125,
        0.51458,
        0.6625,
        0.56458,
    )
コード例 #3
0
    def save_image(self, image, vehicles, directory):
        """Save a timestamped image with bounding boxes around targets."""
        try:
            img = Image.open(io.BytesIO(bytearray(image))).convert("RGB")
        except UnidentifiedImageError:
            _LOGGER.warning("Sighthound unable to process image, bad data")
            return
        draw = ImageDraw.Draw(img)

        for vehicle in vehicles:
            box = hound.bboxvert_to_tf_style(vehicle["boundingBox"],
                                             self._image_width,
                                             self._image_height)
            draw_box(draw, box, self._image_width, self._image_height)

        latest_save_path = directory / f"{self._name}_latest.jpg"
        img.save(latest_save_path)

        if self._save_timestamped_file:
            timestamp_save_path = directory / f"{self._name}_{self._last_detection}.jpg"
            img.save(timestamp_save_path)
            _LOGGER.info("Sighthound saved file %s", timestamp_save_path)