element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Vertical Farming
  • Challenges & Projects
  • Design Challenges
  • Vertical Farming
  • More
  • Cancel
Vertical Farming
Blog Automated Green House Blog:5 - Vision Based Feeder Information
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: m.ratcliffe
  • Date Created: 20 Aug 2015 12:07 PM Date Created
  • Views 627 views
  • Likes 1 like
  • Comments 0 comments
  • adapted_greenhouse
Related
Recommended

Automated Green House Blog:5 - Vision Based Feeder Information

m.ratcliffe
m.ratcliffe
20 Aug 2015

Well I got my Competition Kit, Wow!! A lot of the components in the kits are a little smaller than what I'm used to working with, but damn that is a lot of stuff and the packaging is great. The next few tutorials after this will be on projects with the competition kit.

 

But For now I will just wrap up the automated feeder Blog with what I have done so far on the vision based feedback. The arduino one will be the next blog.

 

-Built the feeders themselves

-measured the federate of the feeders

-Made a decent script for detecting the food with the Pi and Camera.

 

Work to do:

-Add more species to the Open-Loop controller [Tilapia only at the moment]

-Add a timing module to implement feed schedules based of fish age

-Better Blob detection for the Pi camera and have a see if I can get it to read out the size of the fish to fully automate the feed schedules.

 

Codes, Codes , Codes

 

The Codes are only proof of concepts at the moment, if you want to use them in your set-up as a minimum you will need to implement a means of knowing the time to space the feedings. I will be posting updates on these once I have got the parts to implement this.

What you will need:

>RaspberyPi 2b

>USB Camera

>Opto Isolated Relay

 

First things first you will need to install OpenCV in the Pi  [ see Blog 6]

 

The Code:        [Is there a better way to Post Code to these blogs?]

Python Code

#!/usr/bin/python

 

 

##*********Explain a Little About the Codes Purpose *****************##

print("Vision Based Fish Feeder")

print("This code is the first of its kind, addresing fish feeding with an active feedback system")

print("Proof Of Concept Code,Under GNU, So Use it as you wish ")

print("10th/8/2015")

print("By Michael Ratcliffe")

print("Mike@MichaelRatcliffe.com")

 

 

##**********************Import Some Librays**************************##

import cv2

import numpy as np

import RPi.GPIO as GPIO

import time

 

 

print("Librarys Loaded")

 

 

##*** Creating Video Capture and Defining Pins and other variables **##

cap = cv2.VideoCapture(0)

butPin = 21 # Broadcom pin 21 (P1 pin xx)

motorPin = 18 # Broadcom pin 18 (P1 pin 12)

#dc = 20 # duty cycle (0-100) for PWM pin##not used unless pwm

 

 

GPIO.setmode(GPIO.BCM) # Broadcom pin-numbering scheme

GPIO.setup(motorPin, GPIO.OUT) # PWM pin set as output

#pwm = GPIO.PWM(pwmPin, 50)  # Initialize PWM on pwmPin 100Hz frequency

GPIO.setup(butPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Button pin set as input w/ pull-up

#pwm.start(0)

 

 

print("Definitions Finished and Entering Main Loop")

 

##*********************** Main Loop **********************************##

##      ##

## Runs Continuosly for testing purposes                              ##

## Eventualy It will Run every Hour 8am-8pm      ##

## Feeding the Fish as Much as thet Can Eat in 5-10 minutes      ##

##********************************************************************##

while(1):

     

##**************** Capturing Image From Webcam ***********************##

 

 

    _,frame = cap.read()

 

##***************** Bluring Image to unify color *********************##

 

    frame = cv2.blur(frame,(3,3))

 

  

##**************** Converting To Gray Scale **************************##

##      ##

##Simple Conversion Using RGB Works Empty Tank      ##

##Convert from One Channel to Cancel Noise from Fish Color if Needed  ##

##********************************************************************##

  

    gray= cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)

    thresh = cv2.adaptiveThreshold(

    gray,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,\

            cv2.THRESH_BINARY,75,20)

 

 

   

    thresh2 = thresh.copy()

 

 

 

 

 

##***************** Identify Pellets Of Food ************************##

 

 

    contours,hierarchy = cv2.findContours(thresh,cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)

 

 

 

 

 

 

##************ Simple Logic to Feed Fish on Demand ******************##

##     ##

## PWM PIN Used Later As Project Evloves                ##

## Most Likley Proportional+Intergral Control     ##

##*******************************************************************##

 

 

    if (len(contours) > 7 or GPIO.input(butPin)):

  print("Waiting for Fish to Eat")

  GPIO.output(motorPin,False);

 

    else: # button is pressed:

      

  print("Adding Food")

  GPIO.output(motorPin,True)

        time.sleep(0.01)

        GPIO.output(motorPin,False);

##************ Print Some Useful Things to the Screen ***************##

 

 

    print'Amount Of Food:  ',len(contours)-1,'  Pellets'

 

 

 

 

    cv2.imshow('Normal',frame)

    cv2.imshow('Gray',gray)

    cv2.imshow('Pellets',thresh2)

 

 

    time.sleep(0.1)

 

 

##**************** Checks If User Has Asked to Leave *****************##

 

 

    if cv2.waitKey(33)== 27:

        break

 

 

 

 

 

 

##************** Clean up everything before leaving *****************##

 

 

GPIO.cleanup() # cleanup all GPIO

cap.release()

cv2.destroyAllWindows()

 

 

To Run This you will need to:

 

-Wire up a button to earth and a opto isolated relay [see code for used pins]

-Download the file from [www.michaelratcliffe.com/projects]

-Unzip it into your home/pi folder.

-Locate the File "ProofofConcept.py" Right Click on the File Properties>Permissions and select everyone> OK

-Because we are using the GPIO pins. we must run it as root

-cd home/pi [or wherever your proofofconcept.py is located]

-sudo python ProofofConcept.py

 

Now if everything is working you will have three screen pop up and when you pres the button it will do its best to keep the set amout of food in the pond. As it stands this will not be enough to optimise your fish feeding, it still needs to be ran at the optimum times during the day and not left to run all day etc. But It should give you a little intro into how things are coming along.

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube