Using pictures made with Farmbot

After I got my farmbot finally running good enough to have it make pictures everyday to train a neuronal network on plant detection, I want to use those picture I make.
I switched from boroscope cam to the raspi cam for quality reasons and everything is working fine. Just the resolution is far lower than it should be. For some reasons, I don’t understand, the quality is 640x480 instead of 3280x2464, what could be supplied by the raspi cam v2.1. Is there a setting somewhere on the farmbot or webserver I can tweak to get a higher (best full) resolution from the raspi cam? Also is there a connection between the position the picture was taken and the name of the picture, or is there the position and name in one database for correlating those pictures to the plants on the picture? That would be necessary to use this pictures as a training set for a neuronal net.
Also could the way the pictures are stored be altered? Who needs all the lower resolutions anyways? It might save time and calculation power to only save it in original (highest) quality…?

Seeing forward to hear from you guys and get the farmbot to the next level :slight_smile:

3 Likes

Where is the code for the camera python script? Does not seem to be on the github page. Maybe I could look into that and understand myself?

Here is the relevant code. You are welcome to change or remove the image width and height settings and run it as a Farmware to experiment with higher resolutions.

from farmware_tools import device
import os, sys, time, subprocess
filename = '{}/{}.jpg'.format(os.environ['IMAGES_DIR'], int(time.time()))
ret = subprocess.call(['raspistill', '-w', '640', '-h', '480', '-o', filename])
if ret != 0:
    device.log('Problem getting image (error code: {}).'.format(ret), 'error')
    sys.exit(1)

Thanks a lot Gabriel.
So just to understand this a little better. This code snippet is part of the farmbot OS? That means the original farmwares are part of the farmbot OS and therefore not being somewhere seperately?

I also absolutely need the position where the picture was taken or more specific, I need the plant type that’s on that picture. Could you also tell me where to find this linking information. So I could write a farmware that takes a picture in highest possible resolution and safe the plant name/ position in the filename. That would be so helpful

This code is a simple script that can be used as a farmware. So its not part of the Farmbot-OS.

Those first-party farmwares that are made from the FarmBot developers are located in a different Github page called Farmbot-Labs (Take-Photo Farmware).

1 Like

Thanks Ascend

Image position is stored in the meta field of the saved resource at /api/images. It is also available within a Farmware via farmware_tools.device.get_current_position() as shown in the Farmware development documentation. Additionally, farmware_tools.app.get_plants() will return a list of plants and their positions.

What exactly do you mean by meta field? It’s not in the meta data (alias properties) of the jpg file… or?

GET /api/images

[{ "id": 1,
    "device_id": 2,
    "attachment_processed_at": null,
    "updated_at": "0000-00-00T00:00:00.000Z",
    "created_at": "0000-00-00T00:00:00.000Z",
    "attachment_url": "/system/images/attachments/00",
    "meta": {
      "x": 1,
      "y": 2,
      "z": 3 }}]

GET /api/points

[{ "id": 1,
    "created_at": "0000-00-00T00:00:00.000Z",
    "updated_at": "0000-00-00T00:00:00.000Z",
    "discarded_at": null,
    "device_id": 2,
    "meta": {},
    "name": "Cabbage",
    "openfarm_slug": "cabbage",
    "plant_stage": "planned",
    "planted_at": null,
    "pointer_type": "Plant",
    "radius": 50.0,
    "x": 100,
    "y": 100,
    "z": 0 }]

ok, get it. I was confused by the folders, thought you were talking about the picture files on the hard disk

Ascend is helping me trying to get a solution for that:


It’s not done yet, but came far already. I guess feedback and conribution is always helpful :wink:

1 Like

Could anyone with better coding skills than me please have a look. We are a little stuck atm, it’s working on Ascend’s system with the farmbot.org server, but not on my self hosted one. Must be something small, I guess. And then it should be usable for everybody :slight_smile:
@RickCarlino or @Gabriel

So after some experimenting, the farmware sometimes is running and sometimes seems to not find a plant at the specific place. So maybe there is an error in my plant database or with reading out of this database?

@derletztename I will take a look in a moment. Was the main issue a lack of photos in a self-hosted setup, or were there other issues with the script linked above?

Off the top of my head, I think some of the common issues a self-hoster will face with images are:

  1. Not running the background workers / crashed background worker.
  2. Accidentally setting the GCS_BUCKET ENV var (if this variable is missing, the server will default to storing images on the local server, which is desirable in most self-hosted setups).

As a side note, you mentioned that you want to use differntly sized images. The server currently stores images in several sizes (click the link to see sample size):

  • x1280 - Largest size we host.
  • x640 - Default size that most users see.
  • x320
  • x160
  • x80 - tiny size, optimal for thumbnail previews / icons.

(in the examples above, note the x123 portion of the URL).

It’s always exciting to see users creating 3rd-party scripts- thanks for sharing! :tada:

The only issue that still seems to be there, seems to be that at some places in the field it works perfectly, makes maximum resolution pictures with great naming, but on some places it can’t find any plants, even if there are plants in the farm designer.
As the farmbot does not get perfectly to the positions it may be .2 mm next to the original position and therefore not find the plant in the database. Ascend had repaired this by rounding the numbers, but still some plants can’t be fotographed this way. Even when I am putting them back on planned and planted again…
Maybe there is something wrong in the way the farmware looks into the database? or could my database be corrupted somehow? Could we test this?

Regarding the storage/uploading of the images. Could this be changed easily? We need the pictures with improved naming and it would be helpful to have just the best resolution picture in one folder. No different sizes needed. Could this be changed in the following snippet?

> def upload_path(filename):
>     'Filename with path for uploading an image.'
>     try:
>         images_dir = os.environ['IMAGES_DIR']
>     except KeyError:
>         images_dir = '/tmp/images'
>     path = images_dir + os.sep + filename
>     return path

It seems as the way pictures are safed cannot be changed with a farmware solely. Could you maybe give a little backround how pictures are “uploaded”/ stored in the farmbot OS @RickCarlino?

We need the pictures with improved naming and it would be helpful to have just the best resolution picture in one folder.

Could you maybe give a little backround how pictures are “uploaded”/ stored in the farmbot OS @RickCarlino

@derletztename The app is a Ruby on Rails application using the Paperclip plugin for image storage (image.rb is the only model that uses paperclip). Paperclip is in full control over which directory the final images are placed in. For our use case (hundreds of users on a shared server) the naming convention works fine. If you are running a server that only has one user and you would like to have all photos in one human-readable directory, It is theoretically possible to modify the code to store in different sizes and locations (See this section of the Paperclip docs), but it will require custom software development (changes to the API source code).

Alternatives:

  • If you are more comfortable programming in Python, a simple alternative would be to store images externally on a third party image server that offers more customization than the API can provide. A quick Google search has turned up some interesting solutions, but I have not used any of them personally.
  • You could write a script that manually moves your photos to a more convenient location using the image["attachment_url"] the REST API provides and a scripting language of your choice.

If you have any specific questions about how we use Paperclip, I would be happy to answer them to aid in your experimentation with image storage, but I cannot provide Ruby on Rails / Paperclip training. Please see the relevant documentation for such projects.

2 Likes

Thx Rick

1 Like