Author Topic: Using the camera for specific colour/object detection  (Read 8831 times)

rish

  • Full Member
  • ***
  • Posts: 11
  • Karma: +0/-0
Using the camera for specific colour/object detection
« on: March 16, 2016, 07:55:36 AM »
Hi,

I am trying to use detect specific colour/coloured object (red or blue) captured by the khepera's camera. What is the best possible way to do this?

Some of the articles online suggested using OpenCV for colour detection. Does this method involves installing the OpenCV library in the khepera?

Please advise.

kteam

  • Administrator
  • Hero Member
  • *****
  • Posts: 379
  • Karma: +7/-1
Re: Using the camera for specific colour/object detection
« Reply #1 on: March 17, 2016, 10:02:40 AM »
Hi,

there's already an example of colour detection in the libkhepera.
This example is include in the khepera4_test software.

If this is not enough for your application, maybe OpenCV is a good alternative. In this case you will need to install it on the OnBoard Gumstix.

Best regards

rish

  • Full Member
  • ***
  • Posts: 11
  • Karma: +0/-0
Re: Using the camera for specific colour/object detection
« Reply #2 on: March 18, 2016, 09:55:47 AM »
Thank you for the quick reply. I have gone through the example of colour detection in the khepera4_test but I am not very sure what the program is doing.

When I launched the camera demo under khepera4_test, I received the following details:

Multi frames example

keys:
      anykey to stop
      i for toggling display of ascii image
      d for toggling default (green) and custom detection :current: DEFAULT
        (custom parameters: Red:103 Green:127 Blue: 83 Threshold: 40%)
      r/t change red detection
      g/h change green detection
      b/n change blue detection
      c/v change detection threshold

 move the object in front of the camera (default: green STABILO BOSS (R))...

--------------------------
|*                    ** |
|*                     * |
|  *                     |
| **                     |
| ***                    |
|*   *   *               |
|        *              *|
|    *****              *|
|*   *   *               |
|*                       |
|                        |
|    *** *               |
|                        |
|         ***          * |
|           ************ |
|*                       |
|*                       |
|**                      |
--------------------------

I selected option 'd' to break the default detection and selected 'b'  to detect blue and placed a blue object in front of the robot. Once I terminated the program, I received several images captured by the camera where the area surrounding the blue object is highlighted, clearly showing the presences of the blue object.

For my experiment, I need to robot to be able to identify the object in front is of a certain colour. For example, if object in front is detected as blue, it will print "Blue object found". Any suggestions how to achieve this?

« Last Edit: March 18, 2016, 10:05:58 AM by rish »

rish

  • Full Member
  • ***
  • Posts: 11
  • Karma: +0/-0
Re: Using the camera for specific colour/object detection
« Reply #3 on: March 22, 2016, 11:00:14 AM »
Managed to play around with the codes gives from the camera_example().

For those working on this, the best thing to do is to observe the if-else statement at the line:

else
{
   // if in R range
       if ( ((buffer>(1-DETECTION_THRESHOLD/100.0)*SELECTED_COLOR[0]) &&  (buffer<(1+DETECTION_THRESHOLD/100.0)*SELECTED_COLOR[0]))
        // and in G range
   && ((buffer[i+1]>(1-DETECTION_THRESHOLD/100.0)*SELECTED_COLOR[1]) &&  (buffer[i+1 <(1+DETECTION_THRESHOLD/100.0)*SELECTED_COLOR[1]))
   // and in B range
    && ((buffer[i+2]>(1-DETECTION_THRESHOLD/100.0)*SELECTED_COLOR[2]) &&  (buffer[i+2]<(1+DETECTION_THRESHOLD/100.0)*SELECTED_COLOR[2])) )
   ret = 1;
}

Adjust the DETECTION_THRESHOLD value according to suit your work. Also mute the other if conditions (in my case since I am working on blue detection, I had to mute the conditoin on Red and Green in range) you are targeting to detect specific colour.