Go to the documentation of this file.
41 #define strncasecmp _strnicmp
42 #define strdup _strdup
52 return(w*(2*x + w-1) / 2);
57 inline num
max(num a,num b)
59 return((a > b)? a : b);
64 inline num
min(num a,num b)
66 return((a < b)? a : b);
71 0, 1, 2,27, 3,24,28, 0, 4,17,25,31,29,12, 0,14, 5, 8,18,
72 0,26,23,32,16,30,11,13, 7, 0,22,15,10, 6,21, 9,20,19
119 map[i] = aclas[p.
a] & bclas[p.
b];
155 while(row[x] == m) x++;
191 x1 +=
map[l1++].length;
201 if((x1>=x2 && x1<x2+r2.
length) || (x2>=x1 && x2<x1+r1.
length)){
208 while(n !=
map[n].parent) n =
map[n].parent;
210 while(p !=
map[p].parent) p =
map[p].parent;
233 for(i=0; i<num; i++){
236 while(p !=
map[p].parent) p =
map[p].parent;
239 map[i].parent =
map[p].parent;
259 for(i=0; i<num; i++){
273 reg[b].sum_y = y * r.
length;
274 reg[b].average = black;
284 reg[b].x1 =
min(x,reg[b].x1);
287 reg[b].sum_y += y * r.
length;
306 reg[i].cen_x = (float)reg[i].sum_x / a;
307 reg[i].cen_y = (float)reg[i].sum_y / a;
325 int sum_l,sum_a,sum_b;
332 for(i=0; i<num_reg; i++){
343 for(i=0; i<num_runs; i++){
361 sum_l = sum_a = sum_b = 0;
385 reg[b].sum_x += sum_l;
386 reg[b].sum_y += sum_a;
387 reg[b].sum_z += sum_b;
405 for(i=0; i<num_reg; i++){
407 avg.
l = reg[i].sum_x / area;
408 avg.
a = reg[i].sum_y / area;
409 avg.
b = reg[i].sum_z / area;
427 reg[i].average = avg;
450 for(i=0; i<num; i++){
454 if(area > max_area) max_area = area;
471 #define CMV_RADIX (1 << CMV_RBITS)
472 #define CMV_RMASK (CMV_RADIX-1)
483 if(!list || !list->next)
return(list);
488 for(i=0; i<passes; i++){
548 while(p && merged<num){
561 if((
double)(p->
area + q->
area) / a > density_thresh){
606 #define ZERO(x) memset(x,0,sizeof(x))
646 for(i=l; i<r; i++) arr[i] |= k;
658 for(i=l; i<r; i++) arr[i] &= k;
661 #define CMV_STATE_SCAN 0
662 #define CMV_STATE_COLORS 1
663 #define CMV_STATE_THRESH 2
664 #define CMV_MAX_BUF 256
683 in = fopen(filename,
"rt");
684 if(!in)
return(
false);
706 n = sscanf(buf,
"[%s", str);
712 }
else if (!strncasecmp(str,
"thresholds]",
CMV_MAX_BUF)) {
716 printf(
"CMVision: Ignoring unknown option header '%s'.\n", str);
721 n = sscanf(buf,
"(%d,%d,%d) %lf %d %s", &r, &g, &b, &merge, &exp_num, str);
730 c->
name = strdup(str);
735 printf(
"CMVision: Too many colors, ignoring '%s'.\n", str);
742 n = sscanf(buf,
"(%d:%d,%d:%d)", &a1, &a2, &b1, &b2);
756 printf(
"CMVision: Too many thresholds.\n");
782 out = fopen(filename,
"wt");
783 if(!out)
return(
false);
785 fprintf(out,
"[Colors]\n");
789 fprintf(out,
"(%3d,%3d,%3d) %6.4f %d %s\n",
795 fprintf(out,
"\n[Thresholds]\n");
799 fprintf(out,
"(%3d:%3d,%3d:%3d)\n",
817 return(opt == valid);
827 return(opt == valid);
844 if(!image || !out)
return(
false);
852 while(i<
s && !
map[i]){
856 while(i<
s &&
map[i]){
866 int &a_low,
int &a_high,
867 int &b_low,
int &b_high)
881 int a_low,
int a_high,
882 int b_low,
int b_high)
912 if(!image)
return(
false);
943 if(!
map)
return(
false);
void classifyFrame(image_pixel *restrict img, unsigned *restrict map)
bool saveOptions(char *filename)
#define CMV_VALID_OPTIONS
#define CMV_DENSITY_MERGE
bool initialize(int nwidth, int nheight)
bool setThreshold(int color, int a_low, int a_high, int b_low, int b_high)
void connectComponents(rle *restrict map, int num)
unsigned a_class[CMV_COLOR_LEVELS]
bool getThreshold(int color, int &a_low, int &a_high, int &b_low, int &b_high)
bool enable(unsigned opt)
region region_table[CMV_MAX_REGIONS]
void calcAverageColors(region *restrict reg, int num_reg, image_pixel *restrict img, rle *restrict rmap, int num_runs)
int region_count[CMV_MAX_COLORS]
bool loadOptions(const char *filename)
int separateRegions(region *restrict reg, int num)
region * region_list[CMV_MAX_COLORS]
int encodeRuns(rle *restrict out, unsigned *restrict map)
region * sortRegionListByArea(region *restrict list, int passes)
int range_sum(int x, int w)
void sortRegions(int max_area)
int extractRegions(region *restrict reg, rle *restrict rmap, int num)
color_info colors[CMV_MAX_COLORS]
bool processFrame(image_pixel *image)
region * getRegions(int color_id)
bool disable(unsigned opt)
unsigned b_class[CMV_COLOR_LEVELS]
void set_bits(num *arr, int len, int l, int r, num k)
int numRegions(int color_id)
#define CMV_COLOR_AVERAGES
bool testClassify(rgb *restrict out, image_pixel *restrict image)
void clear_bits(num *arr, int len, int l, int r, num k)
cmvision
Author(s): Nate Koenig, Nate Koenig
autogenerated on Wed Mar 2 2022 00:03:25