Counting Eggs With A Webcam

You’ll have to dig out your French dictionary (or Google translate) for this one, but it is worth it. [Nicolas Giraud] has been experimenting with ways to use a webcam to detect the number of eggs chickens have laid in a chicken coop. This page documents these experiments using a number of different algorithms to automatically detect the number of eggs and notify the owner. The system is simple, built around a Pi running Debian Jesse Lite and a cheap USB webcam. An LED running off one of the GPIO pins illuminates the eggs, and the camera then captures the image for analysis.

[Nicolas] tried detecting colors and blob detection (used by microbiologists to count cells on slides), but they didn’t work well against the uneven background of the straw. Finally, he settled on using a technique called Local Binary Patterns, where the system looks at the relationship of an area and the areas around it, searching for a specific pattern created by the round shape and color gradient of the egg. After some tweaking, he claims a 100% success rate.

His work is part of a project called Eggs-iting, which is designing an easy to use chicken coop that anyone can build and use in their back yard. I’ve had chickens, and have traipsed out in the rain and snow to get the eggs, only to find that the hens were not in the mood and hadn’t laid yet. So, a simple system that lets me know how many eggs to expect sounds perfect.

 

14 thoughts on “Counting Eggs With A Webcam

  1. Haveing kept chickens for a number of years now.

    You learn pretty quickly when in the day they have laid and when to close the the egg reducing the need for a pointless trip.

    Nevertheless it was a neat project and a good experiment with image recognition.

  2. I don’t know a whole lot about chickens, but isn’t is possible to train them to stomp a hoof or bark for however many eggs they laid? You could incentivise them with a tuna treat or something.

    1. Hahaha. :P All they do is sh!t and crow. You can almost train them but almost isn’t good enough. Or maybe I just don’t have the patience to positively reenforce specific poultry behaviors at exactly the correct time.

      Also, eat the tuna; chickens love dried mealworms you just can’t give them too much. There is apparently something called ‘protein poisoning’, they can get sick from an excess; all things in moderation.

      P.S.: buck buck buck BUCCKAWW!

    2. Each chicken (excluding hybrid meat birds with messed-up metabolisms) lays at most one egg per day. You can train at least some of them to come report when they’ve laid that one egg, by giving them a treat when they do so. We’ve trained several that way — but we’ve also had a couple of clever gals realize they can go up on the nest, sit for a while, then leap down, run cackling to the nearest human, and receive their “well-earned” treat, all without actually laying an egg. In fact, they’ll do this several times in a row, if you let them. These ladies are now on a “trust, but verify” plan, where we pick them up, walk to the nest, confirm there’s a warm egg there, and then get them their treat. But this whole thing only works if the chickens have access to people, and I realize most people don’t spend all day in a shop with the doors open and free-range chickens freely ranging in and out. I don’t think I could train them to ring a bell when they lay an egg, without hooking the bell up to a treat dispenser — and all that’d accomplish is training them to ring the bell when they want a treat.

      (I’ve never tried tuna, but plain birdseed is pretty good, and 9 out of 10 chickens prefer hulled sunflower seeds to any other seed/grain. They all love plain white bread, most absolutely adore cheese puffs, and every single one goes insane at the sight of freeze-dried mealworms. Of these, birdseed, sunflower seeds (unsalted) and mealworms are the only ones even close to healthy, but even they should be limited, and the others are okay in severely limited quantities — fine for training, but not as a general, glad-to-see-you treat.)

      And as far as reporting the count of eggs already laid (by other hens): I don’t think chickens can count eggs, or anything else. (There is a nesting behavior commonly referred to as “counting eggs”, but everyone knows it’s really just rolling/pushing the eggs around.) A mother hen will sometimes notice when one of her chicks is absent (but not crying for help), but this appears to be based on knowing the chicks as individuals (“I don’t see Frank”), not on counting (“I see 3 chicks, but I’m supposed to have 4”). Of course, maybe they’d learn to count if you made it worth their while… hard to say without trying it, but I’m doubtful.

      I don’t know any of this, and I’m pretty sure some of it is biologically incorrect, but here’s a conceptual model that seems to correspond with observations when our hens (of diverse breeds) lay their eggs:
      A hen only starts producing an egg after laying the previous one, and from that point the new egg is not ready for a “fixed” (varying between breeds, between individuals, and gradually increasing over a hen’s life) delay of something like 24 hours; however, they can hold that egg for some hours if they need to. The breeds developed for laying (Leghorn, Australorp, Golden Comet, etc.) have a cycle shorter than 24 hours, so they end up locked to daylight, where they lay an egg every morning, about the same time. Breeds less well optimized for laying will have some individuals with short cycles, who behave as already described, but some/most will be a bit longer than 24 hours — these will lay a string of eggs, each a little later in the day, then skip a day (holding the egg overnight, and laying it as soon as possible in the morning). And some hens, especially older ones, from these breeds, can be so slow that they lay an egg every two days.

      So if you have a flock of dedicated layers, you can just come round at a certain time every morning (10 or 11 is a good guess, but it obviously shifts with “sunrise”, whether natural or artificial), and the eggs should all be there. But if you have a mixed flock chosen for appearance and personality (as we do), some of them will be laying at all hours of the day, and you either have to collect eggs multiple times per day or arrange your coop to minimize the chance of eggs freezing. Those cute nestboxes along the outside of the coop, so you can collect eggs from outside? Bad plan, unless you insulate them well. Put the nestboxes in the interior, with no contact to outside walls, and your eggs will stay unfrozen all day, you can get them once in the evening. Depends on your local climate, of course…

  3. These automated animal husbandry products (Eggs-citing, Flow Hive, etc) seem to really miss the mark IMO. Either you want to have chickens so you can live out your Charlotte’s Web dreams of a homestead on the range where you form a personal bond with the birds, or you just want the eggs without hassle – in which case, go to the store?

    Getting animals and then machines to care for the animals… I don’t get it.

        1. for me, it’s those days when it’s raining or you are in a hurry, it would be nice to know if it’s worth me getting all muddy and wet to tromp down the back of the garden. if you can get an egg into the fridge within the day it will last much longer than an egg that’s had a warm fat clucker sitting on it all night because you were too lazy to go and get it last night. A normal day, normal routine, yup i’ll go back there and say hello to the chickens and check everything is good.
          plus it’s quite cool to get a tweet (ha!) from your chicken saying she’s laid an egg.

  4. So he compares the four histograms of a new egg and those of trained pictures via SVM. But how does he get the positions of those new eggs in the picture?
    I do not think the SVM takes the whole picture to compare it with its trained histogram data. And just iterating through the picture by tanking smaller sectors and putting them into that SVM would take too long – so what is the trick?

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.