Simple Get Mean

This is a very simple example of how to use the cc3-ilp to get color information. The output on a terminal program (115,200 8N1) will look something like this:

min = [23,16,16] mean = [104,99,64] max = [240,200,129] deviation = [108,92,56]
min = [28,16,16] mean = [106,100,63] max = [236,197,130] deviation = [104,90,57]
min = [25,16,16] mean = [102,99,66] max = [240,202,130] deviation = [107,93,57]
min = [22,16,16] mean = [103,98,61] max = [240,191,120] deviation = [109,87,52]
min = [21,16,16] mean = [102,98,64] max = [240,201,120] deviation = [109,92,52]
min = [27,17,16] mean = [104,100,64] max = [240,194,123] deviation = [106,88,53]
min = [25,16,16] mean = [102,98,64] max = [230,201,127] deviation = [102,92,55]

The code looks like this:

 1#include <stdio.h>
 2#include <stdlib.h>
 3#include <cc3.h>
 4#include <cc3_ilp.h>
 5#include <cc3_color_info.h>
 6
 7void simple_get_mean(cc3_color_info_pkt_t * s_pkt);
 8
 9int main(void) {
10  cc3_color_info_pkt_t s_pkt;
11
12  cc3_uart_init (0, 
13         CC3_UART_RATE_115200,
14         CC3_UART_MODE_8N1,
15         CC3_UART_BINMODE_TEXT);
16
17  cc3_camera_init ();
18
19  //cc3_camera_set_colorspace(CC3_COLORSPACE_YCRCB);
20  cc3_camera_set_resolution(CC3_CAMERA_RESOLUTION_LOW);
21  //cc3_pixbuf_frame_set_subsample(CC3_SUBSAMPLE_NEAREST, 2, 2);
22  cc3_camera_set_auto_exposure (true);
23  cc3_camera_set_auto_white_balance (true);
24
25  cc3_led_set_state (0, false);
26  printf ("Waiting for image to stabilize\n");
27  cc3_timer_wait_ms (2000);
28  cc3_led_set_state (0, true);
29  cc3_camera_set_auto_exposure (false);
30  cc3_camera_set_auto_white_balance (false);
31
32  while(true) {
33    simple_get_mean(&s_pkt);
34    printf( "min = [%d,%d,%d] mean = [%d,%d,%d] max = [%d,%d,%d] deviation = [%d,%d,%d]\n",
35            s_pkt.min.channelr0,
36            s_pkt.min.channelr1,
37            s_pkt.min.channelr2,
38            s_pkt.mean.channelr0,
39            s_pkt.mean.channelr1,
40            s_pkt.mean.channelr2,
41            s_pkt.max.channelr0,
42            s_pkt.max.channelr1,
43            s_pkt.max.channelr2,
44            s_pkt.deviation.channelr0,
45            s_pkt.deviation.channelr1,
46            s_pkt.deviation.channelr2
47            );
48
49   }
50
51}
52
53void simple_get_mean (cc3_color_info_pkt_t * s_pkt)
54{
55  cc3_image_t img;
56  img.channels = 3;
57  img.width = cc3_g_pixbuf_frame.width;
58  img.height = 1;               // image will hold just 1 row for scanline processing
59  img.pix = malloc (3 * img.width);
60
61  cc3_pixbuf_load ();
62  if (cc3_color_info_scanline_start (s_pkt) != 0) {
63    while (cc3_pixbuf_read_rows (img.pix, 1)) {
64      cc3_color_info_scanline (&img, s_pkt);
65    }
66    cc3_color_info_scanline_finish (s_pkt);
67  }
68  free (img.pix);
69}
70