guyver2
Posts: 30
Joined: Thu Feb 26, 2015 4:05 pm

Re: Volunteers to assist with this project: Honey Bee Counte

Fri Dec 04, 2015 9:45 am

well yeah, that's a strange behaviour :?
it almost seems like the entry box is not at the right position... Could you send me the original video, or even just a sample and also the position you gave to the box ?

elriri35
Posts: 10
Joined: Wed Dec 02, 2015 10:44 pm

Re: Volunteers to assist with this project: Honey Bee Counte

Fri Dec 04, 2015 9:47 am

Check in my code the positions:

Code: Select all

#Entry location
hive = Hive(0,0,50,480)
#drawing rectangle
cv2.rectangle(frame, (0, 0), (50, 480), (255,0,0), 2)
The size of the source video is: 176x144
guyver2 wrote: it almost seems like the entry box is not at the right position

If was the case, IN did not work as well no ?


guyver2
Posts: 30
Joined: Thu Feb 26, 2015 4:05 pm

Re: Volunteers to assist with this project: Honey Bee Counte

Fri Dec 04, 2015 10:22 am

if the video size is 176x144, why is the entry size bigger ? It doesn't matter for the code but it just make little sense :)

Looking at the start of your video we can see that the two first objects are well detected as going in. The counter increments once their track is lost (the code allows a window of 15 frames after losing a bee before closing its track).
Then at 13 seconds, we clearly see a new object being detected and poping out from the entrance, and the counter is not incremented... This is an issue, or maybe a bug.
I could look into it if you send me your video. Or you'll have to investigate it (you could try to print the coordinate of each new object and check by hand wether they should have been counted as OUT or not.

You can try to replace Hive.append function with this to print some information

Code: Select all

    # new bee, check if it came from the entrance
    def append(self, pt):
        # if a bee pops out from the hive entrance, then count it
        print "new bee at ", pt, ':',
        if pt[0] > self.x and pt[0] < self.x+self.w and pt[1] > self.y and pt[1] < self.y+self.h:
            self.OUT += 1
            print 'coming from the hive'
        else:
            print 'not coming the hive'

elriri35
Posts: 10
Joined: Wed Dec 02, 2015 10:44 pm

Re: Volunteers to assist with this project: Honey Bee Counte

Fri Dec 04, 2015 10:34 am

Really sorry, I thought the image was resized to 640x480.
I'm going to test with the correct format.

I know python and opencv since only two days ...

guyver2
Posts: 30
Joined: Thu Feb 26, 2015 4:05 pm

Re: Volunteers to assist with this project: Honey Bee Counte

Fri Dec 04, 2015 10:36 am

Well no, I'm the one being sorry... I forgot the image was resized to 640x480. When I wrote the code, I was working on much bigger images...

elriri35
Posts: 10
Joined: Wed Dec 02, 2015 10:44 pm

Re: Volunteers to assist with this project: Honey Bee Counte

Fri Dec 04, 2015 10:37 am

i just tried with 640x480 video but same result.

Outs are not counted.

elriri35
Posts: 10
Joined: Wed Dec 02, 2015 10:44 pm

Re: Volunteers to assist with this project: Honey Bee Counte

Fri Dec 04, 2015 1:26 pm

I found this error:

replace:

Code: Select all

 for i in xrange(len(freeKP)): # new keypoints
                    if freeKP[i]:
                        bees.append(Bee(keypoints[i].pt))
                        hive.append(kp.pt)  
by:

Code: Select all

 for i in xrange(len(freeKP)): # new keypoints
                    if freeKP[i]:
                        bees.append(Bee(keypoints[i].pt))
                        hive.append(keypoints[i].pt)  

guyver2
Posts: 30
Joined: Thu Feb 26, 2015 4:05 pm

Re: Volunteers to assist with this project: Honey Bee Counte

Fri Dec 04, 2015 1:31 pm

yep, that's a bug indeed. at this point kp is always the last blob detected. Thanks I'll update the code in github.

elriri35
Posts: 10
Joined: Wed Dec 02, 2015 10:44 pm

Re: Volunteers to assist with this project: Honey Bee Counte

Mon Dec 07, 2015 10:48 pm

One question.

What is your setup? Because with my Pi2 and the picamera, i get only 2/3fps.

guyver2
Posts: 30
Joined: Thu Feb 26, 2015 4:05 pm

Re: Volunteers to assist with this project: Honey Bee Counte

Tue Dec 08, 2015 9:00 am

when I said the code run real time last summer, it was for the very first version reading from a video stream and with downsampled images.
When I actually ran it on my raspberry with the camera I got a huge frame drop. Since I do not have a beehive to get proper image feed I just updated the code to use the picamera module instead of reading from a file. I did not perform extensive testing and benchmarking.

Using smaller images (not only for processing but also when reading from the sensor), reducing the background history size are two parameters that would increase framerate with a tradeoff for result's quality.

look at these parameters :
SCALE and HISTSIZE
https://github.com/guyver2/beehive/blob ... ra.py#L150

elriri35
Posts: 10
Joined: Wed Dec 02, 2015 10:44 pm

Re: Volunteers to assist with this project: Honey Bee Counte

Fri Dec 25, 2015 5:15 pm

i had may be a solution if you want speed up your processing :

Code: Select all

import io
import time
import threading
import picamera

# Create a pool of image processors
done = False
lock = threading.Lock()
pool = []

class ImageProcessor(threading.Thread):
    def __init__(self):
        super(ImageProcessor, self).__init__()
        self.stream = io.BytesIO()
        self.event = threading.Event()
        self.terminated = False
        self.start()

    def run(self):
        # This method runs in a separate thread
        global done
        while not self.terminated:
            if self.event.wait(1):
                try:
                    self.stream.seek(0)
                    # Read the image and do some processing on it
                    #Image.open(self.stream)
                    #...
                    #...
                    # Set done to True if you want the script to terminate
                    # at some point
                    #done=True
                finally:
                    # Reset the stream and event
                    self.stream.seek(0)
                    self.stream.truncate()
                    self.event.clear()
                    # Return ourselves to the pool
                    with lock:
                        pool.append(self)

def streams():
    while not done:
        with lock:
            processor = pool.pop()
        yield processor.stream
        processor.event.set()

with picamera.PiCamera() as camera:
    pool = [ImageProcessor() for i in range (4)]
    camera.resolution = (640, 480)
    # Set the framerate appropriately; too fast and the image processors
    # will stall the image pipeline and crash the script
    camera.framerate = 10
    camera.start_preview()
    time.sleep(2)
    camera.capture_sequence(streams(), use_video_port=True)

# Shut down the processors in an orderly fashion
while pool:
    with lock:
        processor = pool.pop()
    processor.terminated = True
    processor.join()
With this code i can get 40fps (320x240) with opencv processing.

PeersC
Posts: 27
Joined: Fri Apr 01, 2016 6:35 pm

Re: Volunteers to assist with this project: Honey Bee Counte

Fri Apr 01, 2016 6:50 pm

Hi all.

This is a bit freaky cos my sister and I wanted to put a bee cam on her new hives - I reckoned the best was was with a Raspberry Pi which arrived a couple of days ago and I found this thread!!

We have one hive ready for a swarm and another is being made so no bees at moment. I have a number of spare HD webcams but my speciality is electronics. I am building battery packs that will keep our pi running in the trees in the orchard near our hives - I will just have to nip out every few days and put a freshly charged pack on.

Just need the software - got as far as downloading motion but not much further - I do know how to port forward and create exceptions on the firewall but just total newbie with PI o/s.

Happy to help and when I get it set up the stream will be available.

Peers and Justine

gtoal
Posts: 94
Joined: Sun Nov 18, 2012 12:02 am

Re: Volunteers to assist with this project: Honey Bee Counte

Fri Apr 01, 2016 11:00 pm

Thanks guys! The project started slowly because we were both finishing off a previous project, but we're getting properly underway again right now. In fact I've spent the last couple of days evaluating the new WD Pi Drive to record video of the hive on, and I'm setting up a system to see how long we can run off a battery without recharging. (My calculations say about 1 week, but I want to measure it in practice, and I haven't done anything yet to reduce power significantly - I'm hoping for more than the 7 or 8 days that the back of the envelope calculation suggests)

A quick question: you obviously don't have power to your hives. But are you in range of wifi or is running an ethernet cable an option? (either above-ground or buried)

Graham

PeersC
Posts: 27
Joined: Fri Apr 01, 2016 6:35 pm

Re: Volunteers to assist with this project: Honey Bee Counte

Sat Apr 02, 2016 4:35 am

Hi Graham,

Just give you a few ideas of our set up and my ideas thus far.

First off our hives are in wifi range of an wireless extender in my loft - running a Pi 3 with built in wifi but could add another wifi extender plugged into the Pi's RJ45 plug. I have a 1 TB external HD plugged into the USB port on my BT home hub that is shared on the network.

As regards batteries - I will explain in more detail. I fly model helicopters and when at the flying field I charge my batteries from a twelve volt gel battery (ex golf cart) using a balance charger - so to top up, the Pi I will have a charging lead and just need to wander down the garden with the battery and charger and plug in to recharge (no need to go climbing trees). I am using 12 x 2500 mah 1.2volt NiMh wired in 4 series x 3 parralel to give me total 7500 mah at 4.8 to 5.6 volt nominal could also use lipo's

All we need now is some Bees, the lure is in just waiting patiently or will resort to getting a queen from our local bee keeping club.
I will post some photos when I get chance.

Peers and Justine

gtoal
Posts: 94
Joined: Sun Nov 18, 2012 12:02 am

Re: Volunteers to assist with this project: Honey Bee Counte

Sat Apr 02, 2016 10:17 pm

We're looking at something similar by way of charging in the field for larger scale honey farming too. The questions we've been asking ourselves are how often it would need to be done and how long charging would take. If too long, then is swapping out a battery an option. Then there's lead-acid vs NiMH vs LiPo (LifePo4). There are also secondary considerations such as the cost of equipment/batteries and theft from rustlers. I'd put a smiley there if it wasn't for the fact that I'm quite serious. So having some sort of data link, even if low bandwidth, is probably essential if only for a tamper/theft alerting system. Disguising a central server (eg comms and data - perhaps one hard drive for a group of hives) as a beehive is an option but it's a bit of a giveaway if there's a big solar panel right next to one of the hives. These aspects may seem trivial or silly but we want to do our best to take all relevant factors into account from the start and if we came up with a great system that did everything we wanted but was trivially easy to make off with, the project would fail.

Anyway, let us know how long you can run off a charge. And whether you're stabilizing the power supply - if you're using a UBEC (5V step-down buck converter) typically used in RC aviation, it'll probably need an extra volt or more (ie 6V+) in order to guarantee a stable 5V output. If you're not using a constant voltage source, then I'd be a bit worried about the reliability of your raspberry pi? I would suggest looking at 12V SLA deep cycle batteries rather than 4S NiMH for both cost-effectiveness and that higher input voltage that would guarantee a steady 5.00 output... and maybe a system to allow hot-swapping a battery rather than recharging in the field?

On of the reasons for instrumenting a hive is so that the beekeeper can inspect the hive remotely or at least gather the data from the hive quickly without suiting up and spending hours on site. (A related issue being downloading data off a local disk drive, or swapping out an SD card etc etc) This isn't such a factor for a hobbyist but is quite important for a commercial beekeeper. So charging time vs swapping time may be a factor.

If you're close enough to your home that you can run wifi, you might want to look at Power over Ether to handle both your networking and powering the raspberry pi. The biggest investment is probably a couple of hours of spade work and a drum of direct burial grade cat5. The adapters themselves are cheap. That's what we're doing for our back yard hive. The battery stuff is for deployments in fields out in the countryside.

Graham

PeersC
Posts: 27
Joined: Fri Apr 01, 2016 6:35 pm

Re: Volunteers to assist with this project: Honey Bee Counte

Sun Apr 03, 2016 10:15 am

Two.Packs.on.Charge.jpg
2 x NiMH on charge
Two.Packs.on.Charge.jpg (33.02 KiB) Viewed 6327 times
Battery.Checker.3.jpg
Full view of two packs on Charge
Battery.Checker.3.jpg (42.61 KiB) Viewed 6327 times
Battery.Checker.jpg
status on one pack MiMh on checker unit
Battery.Checker.jpg (18.9 KiB) Viewed 6327 times
Hello Graham,

You are obviously well ahead of me as I only became a proud Pi owner a few days ago but have been thinking this through for a few month and you have raised quite a few issues that have been a concern for me.

First off I was told (by a Pi guru at Maplin that the Pi is very forgiving with small voltage fluctuations but no so with current. I have got a 5V 2A regulator and smoothing capacitor if I need it. I am really working with bits and bobs I have lying around rather than buying new. My 4S x3 packs deliver upto 6.3V on a full Charge down to 4.8V when in need of charging. I decided against the 12V lead acid as they are unsightly in our Garden - I can mount the LIPO,s or NiMH in the boughs of a tree and no-one will even know they are there. I have seen farmers with sheep in fields who have steel boxes built to protect the batteries that power their electric fences from thieves but I'll talk about security later.

If I can draw your attention to the photo labelled Battery Checker - I'll run a charging / checking lead down the tree from the pack then just plug in the checker, if I see the capacity down to say 30% then I know it's time to charge. In the picture charger setup you can see the charger which is dual supply (mains and 12V) so I can take the battery and charger and just plug in. As to how long well it depends. The charger is rated to 100 watts and can charge two outputs together so I can, charge one pack at 5.0 amps and a second at 2.0 amps - however that is quite strong and I would usually take longer at a lower charge rate. But if it's piddling down and you need to get indoors then fine.

Now security - I see the issue, little sods will pinch anything not nailed down. I have however just refurnished and 18th century coach house with a very definitely 21st Century alarm system. Manufactured by a company in Haslingden called Texecom it would, I believe offer you very robust protection against undesirables. This is down to it's wireless technology (Ricochet) where by each sensor acts as a relay station to those adjacent to it thus if point D is furthest away and out of range from the central panel A the signal still reaches the panel jumping across sensors B and C. The system also provides support for a 3G modem so can send you an SMS if something is amiss. There is I believe a combined magnetic / vibration sensor that would protect any cases or boxes used. Battery life I think is around three years.

I am sure there will be plenty more to discuss and I'll let you know when I am up and running, I am still working on getting video to work on the pi with a webcam LOL

Regards,

Peers & Justine

PeersC
Posts: 27
Joined: Fri Apr 01, 2016 6:35 pm

Re: Volunteers to assist with this project: Honey Bee Counte

Thu Apr 07, 2016 11:08 am

Hi Again,

Been a busy week but the Pi is taking video and streaming it - I can rip the vid from the pi's usb stick onto my network - still got a bit of work to do finalizing the power supply but still missing one part of the jigsaw - Bees. Hive is still sadly empty but we are seeing foragers from, we think at least 2 different hives. As they don't interact well (different hive scent).
rsz_2small_hive.jpg
rsz_2small_hive.jpg (57.97 KiB) Viewed 6259 times
Here is a photo of the first hive in the orchard where I am going to conceal the Pi. Have got a couple of questions though, as we only have the brood box out at the moment, does the software take into account the number of supers or the distance to the alighting board? Can the software be run under python for windows and is it python 2 or 3?

Thanks a lot

Peers & Justine

PeersC
Posts: 27
Joined: Fri Apr 01, 2016 6:35 pm

Re: Volunteers to assist with this project: Honey Bee Counte

Mon Apr 11, 2016 4:47 pm

Hello Again,

Tried a full up test today with the Pi out in the orchard running on battery power alone.

As we have no super yet only the brood box and no bees the focus was a bit down on the bluebells under the hive rather than on the alighting board - only shooting at 5 fps at moment reckon with the Pi 3 will be able to go to 20 fps if I need to.
02-20160411125935-00.jpg
first test with hive
02-20160411125935-00.jpg (37.26 KiB) Viewed 6196 times
Here is the first shot from the Pi in situ.

As regards the power issue - I have decided a three pronged solution - I am happy with the NiMh cells in the tree as they are small - compact and deliver enough current for the Pi. I will run a two way split off the power supply board that will a) run the pi off a 12 Volt supply and trickle charge the NiMh pack or can connect a solar panel to. b) charge the NiMh pack inteligently and ensure the pack is at it's optimum efficiency or c) do both at once.

No problems with the Wifi connection can stream to my mobile phone if I need to all working as I intended.

Still looking for some insight into the bee counting software (not that we have any bees to count yet) but when I download from the Pi - can I use python for windows to run the software or will it only work in real time - I am only taking things one step at a time at moment and the most important is to get the video feed up and running - which is just about done.


Thanks

Peers & Justine :)

gtoal
Posts: 94
Joined: Sun Nov 18, 2012 12:02 am

Re: Volunteers to assist with this project: Honey Bee Counte

Wed Apr 20, 2016 1:23 am

I've posted the initial hardware part of our project to http://www.instructables.com/id/The-Electric-Hive/.

gtoal
Posts: 94
Joined: Sun Nov 18, 2012 12:02 am

Re: Volunteers to assist with this project: Honey Bee Counte

Mon May 09, 2016 5:08 am

gtoal wrote:I've posted the initial hardware part of our project to http://www.instructables.com/id/The-Electric-Hive/.
A small update on our project...

With help from some of the denizens of this site, we've worked out how to add air pressure and humidity sensors. (Both of these can measure temperature too, although the DS18B20 one-wire sensors that we tested earlier are probably what we'll actually use for temperature, as it's easier to install several of them and that will let us build a map of temperature throughout the hive).

Code: Select all

[email protected]:~/bin $ ./bmp280
Pressure: 1009.50hPa - Temperature: 26.35°C

[email protected]:~/bin $ sudo ./dht22 22 22
Temp=25.7*  Humidity=59.9%
We're still managing to keep the project costs low - the pressure sensor costs $1.89 and the humidity one costs $4.29

Also... this is fun... (not) - I finally bit the bullet and just applied brute force and ignorance to break the glue seal on the NOIR camera lens so we could focus it close than the hard-wired minimum. That was scary and the lens holder did end up a bit chewed up, but it worked. (I used a couple of dental picks to get the torque to twist the lens cover.) Then I cockily tried the same thing on my other NOIR camera. This was one of the Chinese clones that supports the two little IR LED boards on the side. Bad move. This lens isn't constructed the same way as the official one. Forcing it to turn didn't break the seal because there's no seal to break - instead, it broke the lens itself which was a sealed assembly with lots of little components inside :-( A real shame since the actual camera was better quality than the official one - much less video noise in the image (before I broke it).

G

gtoal
Posts: 94
Joined: Sun Nov 18, 2012 12:02 am

Re: Volunteers to assist with this project: Honey Bee Counte

Sat May 21, 2016 3:36 pm

guyver2 wrote:when I said the code run real time last summer, it was for the very first version reading from a video stream and with downsampled images.
When I actually ran it on my raspberry with the camera I got a huge frame drop. Since I do not have a beehive to get proper image feed I just updated the code to use the picamera module instead of reading from a file. I did not perform extensive testing and benchmarking.

Using smaller images (not only for processing but also when reading from the sensor), reducing the background history size are two parameters that would increase framerate with a tradeoff for result's quality.

look at these parameters :
SCALE and HISTSIZE
https://github.com/guyver2/beehive/blob ... ra.py#L150
Our hive is now live, and you are welcome to grab our video files to use for data:

http://hive.honeybeegardens.net/hive0001/ (Please don't spider the lot, we have very little bandwidth. Sort the folder by date and view the most recent ones manually...)

The actual hive itself is storing about 3 days worth of video locally on a PiDrive 314Gb, but I don't have much quota on that web site where I'm uploading the most recent images in real time. Because our bandwidth is lower than the recording bandwidth, not every recording is uploaded - it's about 1 in 4 - and we're continually purging the oldest images as we upload new ones, so the disk never fills.

The recording parameters are:

PARAMS="-roi 0.25,0.3,0.7,0.7 -sh 70 -co 35 -br 50"
raspivid $PARAMS -fps 30 -t 60000 -f -o /mnt/tmp/$DATE.h264 -b 8000000
MP4Box -fps 30 -add /mnt/tmp/$DATE.h264 /home/pi/hive0001/tmp-$DATE.mp4

I've positioned the image manually using -roi around the hive entrance and the recording is at quite a high resolution. We can tweak any recording or encoding parameters as necessary once we understand what's sufficient, but I thought that to begin with we should start with the best quality video we can get.

For now we are not using IR at night as there is an open question of whether it is disturbing the bees significantly. We're currently establishing a baseline of default behaviour (and giving them time to adjust to the recent changes to the hive) before turning on the LEDs. Bees *should* not be sensitive to IR but in all our previous experiments they appear to have been kept awake all night by it, and go into fanning overtime.

We're hoping to collaborate with someone who has video processing experience, and as well as implementing the bee counting that you've already coded, we want to examine individual bees and categorise by worker/drone/queen, and identify mites on their backs and if possible quantify the amount of pollen being brought in, in their pollen sacs. This ought to be possible with the quality of these images.

One issue we have that you'll see on our videos is that the camera seems to be more responsive to IR than visible light. The images have that IR tint and are almost monochrome. You only see colour if you shine a bright flashlight at the subject. I don't know how much the lack of yellow in the image will affect the ability to recognise pollen sacs. We may need to try a different camera, but this one was chosen specifically for the focusable M12 lens and ability to easily add IR led modules so I'm inclined to make do with it if possible.

Incidentally the hive also can read ambient temperature, pressure, and humidity, (And we have a thermometer attached to the PiDrive to keep an eye on it since it gets pretty hot here in Texas in the summer) I don't yet have those readings saved to a database but I'll add that soon.

You're all welcome to download our videos and experiment with them, and anyone who wants to actively collaborate should get in touch with me and I'll be able to customise the recordings etc for you on the fly as they're saved.

By the way the strange 'poles' in the image are an experiment we're doing to stop the bees from flying straight in to the hive, which results in just one or two blurry frames with a bee in it... by using the cage, we make them slow down and walk in, which gives us much better quality video to analyse. This does not appear to disturb bee behaviour in any significant way.

Graham

gtoal
Posts: 94
Joined: Sun Nov 18, 2012 12:02 am

Re: Volunteers to assist with this project: Honey Bee Counte

Sat May 21, 2016 4:20 pm

Finally spotted some pollen coming in: http://hive.honeybeegardens.net/hive000 ... 161018.mp4 at 10 seconds.

PeersC
Posts: 27
Joined: Fri Apr 01, 2016 6:35 pm

Re: Volunteers to assist with this project: Honey Bee Counte

Thu Jul 07, 2016 6:24 pm

Hi everyone,

We Got bees!!!!!!

Going to leave them alone for a while to settle down then will put pi and camera on stream.

Thanks for all the help.

Peers and Justine Cawley

PeersC
Posts: 27
Joined: Fri Apr 01, 2016 6:35 pm

Re: Volunteers to assist with this project: Honey Bee Counte

Fri Jul 22, 2016 7:02 am

Got Bees - But the darned things swarmed after only ten days.

Fortunately we collected the swarm and introduced them to the second hive.

So we have two active hives ready to introduce camera but want to a little bit more work on the power supply - I think a solar panel to do the recharge will be better.

Keep you informed.

Peers & Justine

Return to “Camera board”

Who is online

Users browsing this forum: PhilE and 5 guests