8 static int edge_pair(IplImage *im,
int sum[],
int _a[2],
int _b[2],
int _c[2],
int _d[2])
39 int y_start = MAX(a[1], c[1]);
40 int y_stop = MIN(b[1], d[1]);
42 if (y_start >= y_stop)
return 0;
48 if (y_stop >= im->height) {
50 y_stop = im->height - 1;
53 float slope1 = float(b[0] - a[0])/float(b[1]-a[1]);
54 float delta1 = a[0] - slope1*a[1];
56 float slope2 = float(d[0] - c[0])/float(d[1]-c[1]);
57 float delta2 = c[0] - slope2*c[1];
59 int x_step = im->nChannels;
60 assert (im->depth == IPL_DEPTH_8U);
64 for (
int y = y_start; y<y_stop; ++y) {
67 float x1 = slope1 * fy + delta1;
68 float x2 = slope2 * fy + delta2;
69 float minx = (x1 < x2 ? x1 : x2);
70 int maxx = (int)(x1 > x2 ? x1 : x2);
71 if (maxx < 0)
continue;
72 int x_start = (int)minx;
73 if (x_start > im->width) {
82 if (maxx >= im->width) maxx=im->width-1;
83 int len = maxx-x_start;
86 unsigned char *ptr = (
unsigned char *)im->imageData + y*im->widthStep + x_start*x_step;
89 for (
int x=0; x<len; ++x) {
90 for (
int c=0;c<im->nChannels;++c) {
95 for (
int x=0; x<len; ++x)
116 int sum[3] = {0,0,0};
118 int a =
edge_pair(im, sum, pts[0], pts[1], pts[0], pts[2]);
119 int b =
edge_pair(im, sum, pts[0], pts[1], pts[1], pts[2]);
120 int c =
edge_pair(im, sum, pts[1], pts[2], pts[0], pts[2]);
123 if (a==0 || b==0 || c==0) tot=0;
126 float ftot = (float)tot;
127 avg[0] = float(sum[0])/ftot;
128 avg[1] = float(sum[1])/ftot;
129 avg[2] = float(sum[2])/ftot;
131 avg[0] = avg[1] = avg[2] = -1;
133 if (im->nChannels==1) {
134 avg[1] = avg[2] = -1;