Permalink
Browse files

support soft-bin in ccv_hog

  • Loading branch information...
1 parent 405fb77 commit e2e2dc0941acd1aa14a1004a7aeb58dca3476051 @liuliu committed Apr 5, 2012
Showing with 43 additions and 32 deletions.
  1. +1 −1 bin/dpmdetect.c
  2. +7 −6 lib/ccv.h
  3. +21 −8 lib/ccv_basic.c
  4. +4 −7 lib/ccv_dpm.c
  5. +9 −9 lib/ccv_numeric.c
  6. 0 samples/{person.m → pedestrian.m}
  7. +1 −1 test/numeric.tests.c
View
@@ -20,7 +20,7 @@ int main(int argc, char** argv)
if (image != 0)
{
unsigned int elapsed_time = get_current_time();
- ccv_dpm_param_t params = { .interval = 8, .min_neighbors = 2, .flags = 0, .threshold = -1.0 };
+ ccv_dpm_param_t params = { .interval = 8, .min_neighbors = 2, .flags = 0, .threshold = -0.3 };
ccv_array_t* seq = ccv_dpm_detect_objects(image, &model, 1, params);
elapsed_time = get_current_time() - elapsed_time;
if (seq)
View
@@ -293,12 +293,13 @@ int ccv_write(ccv_dense_matrix_t* mat, char* out, int* len, int type, void* conf
double ccv_trace(ccv_matrix_t* mat);
enum {
- CCV_L2_NORM = 0x01, // |dx| + |dy|
- CCV_L1_NORM = 0x02, // sqrt(dx^2 + dy^2)
- CCV_GSEDT = 0x04, // Generalized Squared Euclidean Distance Transform:
- // a * dx + b * dy + c * dx^2 + d * dy^2, when combined with CCV_L1_NORM:
- // a * |dx| + b * |dy| + c * dx^2 + d * dy^2
- CCV_NEGATE = 0x08, // negate distance computation (from positive (min) to negative (max))
+ CCV_L2_NORM = 0x01, // |dx| + |dy|
+ CCV_L1_NORM = 0x02, // sqrt(dx^2 + dy^2)
+ CCV_GSEDT = 0x04, // Generalized Squared Euclidean Distance Transform:
+ // a * dx + b * dy + c * dx^2 + d * dy^2, when combined with CCV_L1_NORM:
+ // a * |dx| + b * |dy| + c * dx^2 + d * dy^2
+ CCV_NEGATIVE = 0x08, // negative distance computation (from positive (min) to negative (max))
+ CCV_POSITIVE = 0x00, // positive distance computation (the default)
};
enum {
View
@@ -311,10 +311,11 @@ void ccv_hog(ccv_dense_matrix_t* a, ccv_dense_matrix_t** b, int b_type, int sbin
mgv = mgp[j * ch + k];
agv = agp[j * ch + k];
}
- double agr = (ccv_clamp(agv, 0, 359.99) / 360.0) * (sbin * 2);
- int ag = (int)(agr + 0.5);
- if (ag == sbin * 2)
- ag = 0;
+ double agr0 = (ccv_clamp(agv, 0, 359.99) / 360.0) * (sbin * 2);
+ int ag0 = (int)agr0;
+ int ag1 = (ag0 + 1 < sbin * 2) ? ag0 + 1 : 0;
+ agr0 = agr0 - ag0;
+ double agr1 = 1.0 - agr0;
mgv = mgv / 255.0;
double yp = ((double)i + 0.5) / (double)size - 0.5;
double xp = ((double)j + 0.5) / (double)size - 0.5;
@@ -327,13 +328,25 @@ void ccv_hog(ccv_dense_matrix_t* a, ccv_dense_matrix_t** b, int b_type, int sbin
double vy1 = 1.0 - vy0;
double vx1 = 1.0 - vx0;
if (ixp >= 0 && iyp >= 0)
- cnp[iyp * cn->cols * sbin * 2 + ixp * sbin * 2 + ag] += vx1 * vy1 * mgv;
+ {
+ cnp[iyp * cn->cols * sbin * 2 + ixp * sbin * 2 + ag0] += agr1 * vx1 * vy1 * mgv;
+ cnp[iyp * cn->cols * sbin * 2 + ixp * sbin * 2 + ag1] += agr0 * vx1 * vy1 * mgv;
+ }
if (ixp + 1 < cn->cols && iyp >= 0)
- cnp[iyp * cn->cols * sbin * 2 + (ixp + 1) * sbin * 2 + ag] += vx0 * vy1 * mgv;
+ {
+ cnp[iyp * cn->cols * sbin * 2 + (ixp + 1) * sbin * 2 + ag0] += agr1 * vx0 * vy1 * mgv;
+ cnp[iyp * cn->cols * sbin * 2 + (ixp + 1) * sbin * 2 + ag1] += agr0 * vx0 * vy1 * mgv;
+ }
if (ixp >= 0 && iyp + 1 < cn->rows)
- cnp[(iyp + 1) * cn->cols * sbin * 2 + ixp * sbin * 2 + ag] += vx1 * vy0 * mgv;
+ {
+ cnp[(iyp + 1) * cn->cols * sbin * 2 + ixp * sbin * 2 + ag0] += agr1 * vx1 * vy0 * mgv;
+ cnp[(iyp + 1) * cn->cols * sbin * 2 + ixp * sbin * 2 + ag1] += agr0 * vx1 * vy0 * mgv;
+ }
if (ixp + 1 < cn->cols && iyp + 1 < cn->rows)
- cnp[(iyp + 1) * cn->cols * sbin * 2 + (ixp + 1) * sbin * 2 + ag] += vx0 * vy0 * mgv;
+ {
+ cnp[(iyp + 1) * cn->cols * sbin * 2 + (ixp + 1) * sbin * 2 + ag0] += agr1 * vx0 * vy0 * mgv;
+ cnp[(iyp + 1) * cn->cols * sbin * 2 + (ixp + 1) * sbin * 2 + ag1] += agr0 * vx0 * vy0 * mgv;
+ }
}
agp += a->cols * ch;
mgp += a->cols * ch;
View
@@ -112,7 +112,7 @@ ccv_array_t* ccv_dpm_detect_objects(ccv_dense_matrix_t* a, ccv_dpm_mixture_model
ccv_flatten(response, (ccv_matrix_t**)&feature, 0, 0);
ccv_matrix_free(response);
part_feature[k] = dx[k] = dy[k] = 0;
- ccv_distance_transform(feature, &part_feature[k], 0, &dx[k], 0, &dy[k], 0, part->dx, part->dy, part->dxx, part->dyy, CCV_NEGATE | CCV_GSEDT);
+ ccv_distance_transform(feature, &part_feature[k], 0, &dx[k], 0, &dy[k], 0, part->dx, part->dy, part->dxx, part->dyy, CCV_NEGATIVE | CCV_GSEDT);
ccv_matrix_free(feature);
int offy = part->y + part->w->rows / 2 - rwh * 2;
int miny = part->w->rows / 2, maxy = part_feature[k]->rows - part->w->rows / 2;
@@ -194,22 +194,19 @@ ccv_array_t* ccv_dpm_detect_objects(ccv_dense_matrix_t* a, ccv_dpm_mixture_model
ccv_root_comp_t r1 = *(ccv_root_comp_t*)ccv_array_get(seq, i);
int idx = *(int*)ccv_array_get(idx_seq, i);
- if (comps[idx].neighbors == 0)
- comps[idx].confidence = r1.confidence;
-
- ++comps[idx].neighbors;
-
comps[idx].rect.x += r1.rect.x;
comps[idx].rect.y += r1.rect.y;
comps[idx].rect.width += r1.rect.width;
comps[idx].rect.height += r1.rect.height;
comps[idx].id = r1.id;
comps[idx].pnum = r1.pnum;
- if (r1.confidence > comps[idx].confidence)
+ if (r1.confidence > comps[idx].confidence || comps[idx].neighbors == 0)
{
comps[idx].confidence = r1.confidence;
memcpy(comps[idx].part, r1.part, sizeof(ccv_comp_t) * CCV_DPM_PART_MAX);
}
+
+ ++comps[idx].neighbors;
}
// calculate average bounding box
View
@@ -916,7 +916,7 @@ void ccv_distance_transform(ccv_dense_matrix_t* a, ccv_dense_matrix_t** b, int t
double s; \
for (;;) \
{ \
- s = ((_negate _for_get_a(a_ptr, j, 0) + dxx * j * j - dx * j) - (_negate _for_get_a(a_ptr, v[k], 0) + dxx * v[k] * v[k] - dx * v[k])) / (2.0 * dxx * (j - v[k])); \
+ s = ((SGN _for_get_a(a_ptr, j, 0) + dxx * j * j - dx * j) - (SGN _for_get_a(a_ptr, v[k], 0) + dxx * v[k] * v[k] - dx * v[k])) / (2.0 * dxx * (j - v[k])); \
if (s > z[k]) break; \
--k; \
} \
@@ -932,7 +932,7 @@ void ccv_distance_transform(ccv_dense_matrix_t* a, ccv_dense_matrix_t** b, int t
{ \
while (z[k + 1] < j) \
++k; \
- _for_set_b(b_ptr, j, dx * (j - v[k]) + dxx * (j - v[k]) * (j - v[k]) _negate _for_get_a(a_ptr, v[k], 0), 0); \
+ _for_set_b(b_ptr, j, dx * (j - v[k]) + dxx * (j - v[k]) * (j - v[k]) SGN _for_get_a(a_ptr, v[k], 0), 0); \
x_ptr[j] = j - v[k]; \
} \
x_ptr += mx->cols; \
@@ -941,7 +941,7 @@ void ccv_distance_transform(ccv_dense_matrix_t* a, ccv_dense_matrix_t** b, int t
{ \
while (z[k + 1] < j) \
++k; \
- _for_set_b(b_ptr, j, dx * (j - v[k]) + dxx * (j - v[k]) * (j - v[k]) _negate _for_get_a(a_ptr, v[k], 0), 0); \
+ _for_set_b(b_ptr, j, dx * (j - v[k]) + dxx * (j - v[k]) * (j - v[k]) SGN _for_get_a(a_ptr, v[k], 0), 0); \
} \
} \
a_ptr += a->step; \
@@ -952,7 +952,7 @@ void ccv_distance_transform(ccv_dense_matrix_t* a, ccv_dense_matrix_t** b, int t
for (i = 0; i < a->rows; i++) \
{ \
for (j = 0; j < a->cols; j++) \
- _for_set_b(b_ptr, j, _negate _for_get_a(a_ptr, j, 0), 0); \
+ _for_set_b(b_ptr, j, SGN _for_get_a(a_ptr, j, 0), 0); \
for (j = 1; j < a->cols; j++) \
_for_set_b(b_ptr, j, ccv_min(_for_get_b(b_ptr, j, 0), _for_get_b(b_ptr, j - 1, 0) + dx), 0); \
for (j = a->cols - 2; j >= 0; j--) \
@@ -1016,15 +1016,15 @@ void ccv_distance_transform(ccv_dense_matrix_t* a, ccv_dense_matrix_t** b, int t
_for_set_b(b_ptr + i * db->step, j, ccv_min(_for_get_b(b_ptr + i * db->step, j, 0), _for_get_b(b_ptr + (i + 1) * db->step, j, 0) - dy), 0); \
} \
}
- if (flag & CCV_NEGATE)
+ if (flag & CCV_NEGATIVE)
{
-#define _negate -
+#define SGN -
ccv_matrix_setter_getter(db->type, ccv_matrix_getter, a->type, for_block);
-#undef _negate
+#undef SGN
} else {
-#define _negate +
+#define SGN +
ccv_matrix_setter_getter(db->type, ccv_matrix_getter, a->type, for_block);
-#undef _negate
+#undef SGN
}
#undef for_block
}
File renamed without changes.
View
@@ -313,7 +313,7 @@ TEST_CASE("ccv_distance_transform to compute max distance")
double dy = 0;
double dxx = 1;
double dyy = 1;
- ccv_distance_transform(geometry, &distance, 0, 0, 0, 0, 0, dx, dy, dxx, dyy, CCV_NEGATE | CCV_GSEDT);
+ ccv_distance_transform(geometry, &distance, 0, 0, 0, 0, 0, dx, dy, dxx, dyy, CCV_NEGATIVE | CCV_GSEDT);
ccv_dense_matrix_t* ref = 0;
daq_max_distance_transform(geometry, &ref, dx, dy, dxx, dyy);
ccv_matrix_free(geometry);

0 comments on commit e2e2dc0

Please sign in to comment.