Close

Simpler Vision Control

A project log for Hacking the way to growing food

Using Technology And A Hackers Mindset To Grow Food. Last Updated [16/01/2021]

michael-ratcliffeMichael Ratcliffe 08/17/2015 at 20:220 Comments

Today while waiting for videos to upload to YouTube for the Best Product award I have been working on a simpler vision based control system suited to the smaller aquaponics guys using IBC's as ponds.

To keep Cost down and the ease of use up, we are going to have to drop the RapberyPi and the high end vision operations and go with some basic arduino based stuff.

Not having a Arduino camera at the moment we are proving the concept works using a linux desktop and processing environment:

How Does it work:

>Counts the number of food coloured pixels

>Removes the static pixels found at sartup/beginning of the day

>the remaining pixels are related to the amount of food in the cameras view

Here is the Code:

[Linux mint, processing 2.21]

/**
 *Pixel Count 
 * by Michael Ratcliffe. 
 *Released under GNU
 * Counts the number of red pixels in a frame
 */


import processing.video.*;        
PFont f;                          // Used For Displaying Data To Terminal
  
Capture video;

void setup() {
  size(640, 480);
  video = new Capture(this, width, height);
  video.start();  
  noStroke();
  smooth();
   f = createFont("Arial",16,true); 
  
}

void draw() {
  if (video.available()) {
    video.read();
    image(video, 0, 0, width, height); // Draw the webcam video onto the screen
    
    
    int foodCount=0;
      video.loadPixels();
    int index = 0;
    for (int y = 0; y < video.height; y++) {
      for (int x = 0; x < video.width; x++) {
        // Get the color stored in the pixel
        
       
        int pixelValue = video.pixels[index];
        int r = (pixelValue >> 16) & 0xff;
        int g = (pixelValue >> 8) & 0xff;
        int b = pixelValue & 0xff;

//******************************* Basic threshold for pixel Redness ***********************************//        
        if(r>1.6*g && r>1.2*b){
                   foodCount++ ;  //Adds to the pixel count for that frame 
                        
                        }
        index++;
      }
    }
    
//************************************Displays the PixelCount on the Screen as Text**********************//   
     textFont(f,32);                 
  fill(0);                       
  text("Pixels Of Food",10,100);  
     textFont(f,32);                
  fill(0);                       
  text(foodCount,10,140);  
   
  }
}
[This Is a rough Proof Of Concept, A better one with a youtube Video of how well it works will be added soon]

Work Done so Far:

Proved that this simple technique could be used

Work to Do:

-See if we can assess the camera data packets as they come in from the camera to the arduino to neglect the need to save the Image.

-Schedule a testing at the beginning of the day to assign a background pixel count. this will take care of any other food color objects in the view of the camera.

Discussions