Data Overlay on Camera Image from inputs and outputs

Kyle I just wanted to start off and say that you have developed some great software. I’m using it on my grow and I keep adding new sensors to it.

I like to look at all the data to see how my grow is performing. I always have a timelapse running of my grow. I’ve been messing around trying to add some overlay text of the inputs and outputs status over the images. It would be great to add some type of overlay that draws it on the camera’s saved video, stills, timelapse, and streaming video. You can see what I mean by the picture that I have attached. I think it would be amazing to see the video with the data so you know what works best and what you are possibly doing wrong with your grow. I’ve done this with one of my weather stations and everyone loved it. Also, the image attached is just something I found on google.

Thank you so much Kyle!

unnamed

1 Like

Here is a function that is a good start to accomplishing this. But keep in mind there was a recent change to how the latest camera image filename is stored/accessed, which could affect how this works in the future when the next release occurs and this code becomes live. This module can be imported from the Configure → Custom Functions page. Keep in mind it’s a very basic start. If you upgrade to master, you can start developing the module for the latest code. In that case, it would help to be able to access the most recent photo or timelapse file. The following are two logging lines that will print that information. You can use these filenames (and timestamps) to access the latest image of each instead of using the inefficient glob method that’s currently in the module.

        self.logger.info("Last still: {}, {}".format(
            camera.still_last_ts, camera.still_last_file))
        self.logger.info("Last timelapse: {}, {}".format(
            camera.timelapse_last_file, camera.timelapse_last_ts))

camera_image_overlay.py (5.3 KB)

If you want to decrease the period so the function operates faster to find an unaltered image and altering it, you can store the name of the latest filename that has been altered in the database to indicate that it’s already been altered. This prevents the function from attempting to alter a file that’s already been altered. This can be accomplished with the self.set_custom_option() and self.get_custom_option() functions. Below is a simple way of using these, based on the previous code I provided that gets the latest filename:

# Get camera DB entry
camera = db_retrieve_table_daemon(Camera, unique_id=self.camera_id)

# Print information about the last timelapse and still images
self.logger.info("Last still: {}, {}".format(
    camera.still_last_ts, camera.still_last_file))
self.logger.info("Last timelapse: {}, {}".format(
    camera.timelapse_last_file, camera.timelapse_last_ts))

# Get the path to the latest image
camera_path = os.path.join(PATH_CAMERAS, '{uid}'.format(uid=self.camera_id))
if camera.path_still:
    still_path = camera.path_still
else:
    still_path = os.path.join(camera_path, 'still')

# Generate the full path to the image
list_still_img_full_path = '{path}/{fname}'.format(
    path=still_path, fname=camera.timelapse_last_file)

# Check if the latest image is different from what has been stored in the database
if self.get_custom_option("altered_image_path") != list_still_img_full_path:
    # Code here to do something with the image at list_still_img_full_path

    # Store the full path to the database
    self.set_custom_option("altered_image_path", list_still_img_full_path)

Perfect. So what is needed to display the data from my inputs to display the temperature, PH, EC, and other data from my sensors on the camera’s image?

I would use the opencv python library.