Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 2 of 2

Thread: color detection using camera

  1. #1
    Junior Member
    Join Date
    Nov 2020
    Posts
    4

    color detection using camera

    hi,

    i would like to do simple environment color detection using a cheap and small camera - which would be the best approach?
    i was thinking about a halloween costume which could detect surrounding colours and adapt them to LEDs.
    i'm aware of raspberry + openCV but afaik there's nothing like that for arduino - there's a camera module called OPENMV CAM H7 PLUS which features an ARM Cortex M7 cpu running at 480 MHz but it's pretty expensive ..
    shouldn't it be possible with the teensy 4.1's fast cpu? it should use a small + cheap cam (or even several) which simple read out color information in realtime - is there a arduino library for handling video streams / color- and object detection?

    thanks!

  2. #2
    Senior Member pictographer's Avatar
    Join Date
    May 2013
    Location
    San Jose, CA
    Posts
    681
    If you think of a photodiode as a single pixel camera, you can make a very low resolution color detector by using three of them. Either get ones that target the color frequencies you care about or get ones that sense full spectrum daylight and put translucent gel in front of each to allow you to measure the red, green, and blue. Normally, an op amp circuit is recommended for conditioning the photodiode output, but if you don't need high precision or high speed, you can do pretty well with the photodiodes connected directly to analog inputs. I've built a couple of gadgets for measuring the level of illumination in a skylight or indoors this way.

    Code:
    void setup() {
      pinMode(PHOTODIODE_CATHODE_RED, INPUT_PULLDOWN);
      pinMode(PHOTODIODE_ANODE_BLACK, OUTPUT);
      digitalWriteFast(PHOTODIODE_ANODE_BLACK, 0);
    }
    
    
    int readLight() {
      const auto count = 1024L;
      digitalWriteFast(PHOTODIODE_ANODE_BLACK, 1);
      auto sum = 0L;
      for (auto i = 0L; i < count; ++i) {
        sum += analogRead(PHOTODIODE_CATHODE_RED);
      }
      digitalWriteFast(PHOTODIODE_ANODE_BLACK, 0);
      return sum / count;
    }
    The photodiode I'm using is an ancient PBX81-1.

    Note, I do not know if this would work as well on a T4.1 as it does in my case. I've done this with T3 and T LC.
    Last edited by pictographer; 11-10-2020 at 07:13 PM. Reason: Added T3

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •