| 68 | | /** |
|---|
| 69 | | * cc3_track_color() |
|---|
| 70 | | * |
|---|
| 71 | | * This function takes parameters set in the cc3_track_pkt_t structure |
|---|
| 72 | | * and fills in the missing parameters with tracked color data. |
|---|
| 73 | | * This operates on the image directly from the FIFO. |
|---|
| 74 | | * |
|---|
| 75 | | * Returns: 0 if the bounds fail, 1 upon sucess |
|---|
| 76 | | * |
|---|
| 77 | | * Check if num_pixels is greater than 1 to see if an object was detected. |
|---|
| 78 | | * |
|---|
| 79 | | */ |
|---|
| 80 | | uint8_t cc3_track_color(cc3_track_pkt_t *pkt) |
|---|
| 81 | | { |
|---|
| 82 | | uint32_t mm_x,mm_y; |
|---|
| 83 | | int y, x; |
|---|
| 84 | | |
|---|
| 85 | | if( (pkt->lower_bound.channel[0]>pkt->upper_bound.channel[0]) || |
|---|
| 86 | | (pkt->lower_bound.channel[1]>pkt->upper_bound.channel[1]) || |
|---|
| 87 | | (pkt->lower_bound.channel[2]>pkt->upper_bound.channel[2]) ) return 0; |
|---|
| 88 | | pkt->num_pixels=0; |
|---|
| 89 | | pkt->x0=UINT16_MAX; |
|---|
| 90 | | pkt->y0=UINT16_MAX; |
|---|
| 91 | | pkt->x1=0; |
|---|
| 92 | | pkt->y1=0; |
|---|
| 93 | | mm_x=0; |
|---|
| 94 | | mm_y=0; |
|---|
| 95 | | |
|---|
| 96 | | cc3_pixbuf_load(); |
|---|
| 97 | | for(y=0; y<cc3_g_current_frame.height; y++ ) |
|---|
| 98 | | for(x=0; x<cc3_g_current_frame.width; x++ ) |
|---|
| 99 | | { |
|---|
| 100 | | bool pixel_good=0; |
|---|
| 101 | | cc3_pixbuf_read(); |
|---|
| 102 | | if(cc3_g_current_frame.coi==CC3_ALL ) { |
|---|
| 103 | | if(cc3_g_current_pixel.channel[0]>=pkt->lower_bound.channel[0] && |
|---|
| 104 | | cc3_g_current_pixel.channel[0]<=pkt->upper_bound.channel[0] && |
|---|
| 105 | | cc3_g_current_pixel.channel[1]>=pkt->lower_bound.channel[1] && |
|---|
| 106 | | cc3_g_current_pixel.channel[1]<=pkt->upper_bound.channel[1] && |
|---|
| 107 | | cc3_g_current_pixel.channel[2]>=pkt->lower_bound.channel[2] && |
|---|
| 108 | | cc3_g_current_pixel.channel[2]<=pkt->upper_bound.channel[2] ) pixel_good=1; |
|---|
| 109 | | } else |
|---|
| 110 | | { |
|---|
| 111 | | if(cc3_g_current_pixel.channel[cc3_g_current_frame.coi]>=pkt->lower_bound.channel[cc3_g_current_frame.coi] && |
|---|
| 112 | | cc3_g_current_pixel.channel[cc3_g_current_frame.coi]<=pkt->upper_bound.channel[cc3_g_current_frame.coi] ) pixel_good=1; |
|---|
| 113 | | } |
|---|
| 114 | | |
|---|
| 115 | | if(pixel_good) |
|---|
| 116 | | { |
|---|
| 117 | | pkt->num_pixels++; |
|---|
| 118 | | if(pkt->x0 > x ) pkt->x0=x; |
|---|
| 119 | | if(pkt->y0 > y ) pkt->y0=y; |
|---|
| 120 | | if(pkt->x1 < x ) pkt->x1=x; |
|---|
| 121 | | if(pkt->y1 < y ) pkt->y1=y; |
|---|
| 122 | | mm_x+=x; |
|---|
| 123 | | mm_y+=y; |
|---|
| 124 | | } |
|---|
| 125 | | } |
|---|
| 126 | | |
|---|
| 127 | | |
|---|
| 128 | | if(pkt->num_pixels>0 ) |
|---|
| 129 | | { |
|---|
| 130 | | // FIXME: Density hack to keep it an integer |
|---|
| 131 | | pkt->int_density=(pkt->num_pixels*1000) / ((pkt->x1 - pkt->x0)*(pkt->y1 - pkt->y0)); |
|---|
| 132 | | pkt->centroid_x= mm_x / pkt->num_pixels; |
|---|
| 133 | | pkt->centroid_y= mm_y / pkt->num_pixels; |
|---|
| 134 | | |
|---|
| 135 | | } |
|---|
| 136 | | else |
|---|
| 137 | | { |
|---|
| 138 | | pkt->int_density=0; |
|---|
| 139 | | pkt->x0=0; |
|---|
| 140 | | pkt->y0=0; |
|---|
| 141 | | pkt->x1=0; |
|---|
| 142 | | pkt->y1=0; |
|---|
| 143 | | pkt->centroid_x=0; |
|---|
| 144 | | pkt->centroid_y=0; |
|---|
| 145 | | |
|---|
| 146 | | } |
|---|
| 147 | | return 1; |
|---|
| 148 | | } |
|---|
| 149 | | |
|---|
| 150 | | uint8_t cc3_track_color_img(cc3_image_t *img, cc3_track_pkt_t *pkt) |
|---|
| 151 | | { |
|---|