Skip to content

Commit

Permalink
added test case for Canny detector, the test case will return error code
Browse files Browse the repository at this point in the history
if test fails.
  • Loading branch information
liuliu committed Feb 6, 2011
1 parent 670b271 commit 893dc57
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lib/ccv_basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* here includes 2 special case impl (for 1x3/3x1, 3x3) and one general impl */
void ccv_sobel(ccv_dense_matrix_t* a, ccv_dense_matrix_t** b, int type, int dx, int dy)
{
assert(a->type & CCV_C1);
char identifier[64];
memset(identifier, 0, 64);
snprintf(identifier, 64, "ccv_sobel(%d,%d)", dx, dy);
Expand Down Expand Up @@ -246,6 +247,7 @@ static void __ccv_atan2(float* x, float* y, float* angle, float* mag, int len)

void ccv_gradient(ccv_dense_matrix_t* a, ccv_dense_matrix_t** theta, int ttype, ccv_dense_matrix_t** m, int mtype, int dx, int dy)
{
assert(a->type & CCV_C1);
uint64_t tsig = (a->sig == 0) ? 0 : ccv_matrix_generate_signature("ccv_gradient_theta", 18, a->sig, 0);
uint64_t msig = (a->sig == 0) ? 0 : ccv_matrix_generate_signature("ccv_gradient_m", 14, a->sig, 0);
ccv_dense_matrix_t* dtheta = *theta = ccv_dense_matrix_renew(*theta, a->rows, a->cols, CCV_32F | CCV_C1, CCV_32F | CCV_C1, tsig);
Expand All @@ -269,6 +271,7 @@ void ccv_gradient(ccv_dense_matrix_t* a, ccv_dense_matrix_t** theta, int ttype,

void ccv_hog(ccv_dense_matrix_t* a, ccv_dense_matrix_t** b, int type, int size)
{
assert(a->type & CCV_C1);
int border_size = size / 2;
uint64_t sig = (a->sig == 0) ? 0 : ccv_matrix_generate_signature("ccv_hog", 7, a->sig, 0);
type = (type == 0) ? CCV_32S | CCV_C1 : CCV_GET_DATA_TYPE(type) | CCV_C1;
Expand Down Expand Up @@ -320,6 +323,7 @@ void ccv_hog(ccv_dense_matrix_t* a, ccv_dense_matrix_t** b, int type, int size)
* profiling, the current implementation still uses integer to speed up */
void ccv_canny(ccv_dense_matrix_t* a, ccv_dense_matrix_t** b, int type, int size, double low_thresh, double high_thresh)
{
assert(a->type & CCV_C1);
char identifier[64];
memset(identifier, 0, 64);
snprintf(identifier, 64, "ccv_canny(%d,%lf,%lf)", size, low_thresh, high_thresh);
Expand Down Expand Up @@ -448,7 +452,7 @@ void ccv_canny(ccv_dense_matrix_t* a, ccv_dense_matrix_t** b, int type, int size
for (i = 0; i < a->rows; i++) \
{ \
for (j = 0; j < a->cols; j++) \
__for_set(b_ptr, j, (map_ptr[j] >> 1), 0); \
__for_set(b_ptr, j, (map_ptr[j] == 2), 0); \
map_ptr += map_cols; \
b_ptr += db->step; \
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ccv_bbf.c
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ void ccv_bbf_classifier_cascade_new(ccv_dense_matrix_t** posimg, int posnum, cha
}
if (k > 0)
cacheK = k;
int rpos, rneg;
int rpos, rneg = 0;
if (bg)
{
sprintf(buf, "%s/negs.txt", dir);
Expand Down
Binary file added samples/blackbox.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions test/basic.tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,16 @@ TEST_CASE("flip operation")
ccv_garbage_collect();
}

TEST_CASE("canny edge detector")
{
ccv_dense_matrix_t* image = 0;
ccv_unserialize("../samples/blackbox.png", &image, CCV_SERIAL_GRAY | CCV_SERIAL_ANY_FILE);
ccv_dense_matrix_t* x = 0;
ccv_canny(image, &x, 0, 3, 36, 36 * 3);
REQUIRE_MATRIX_FILE_EQ(x, "data/blackbox.canny.bin", "Canny edge detector on artificial image");
ccv_matrix_free(image);
ccv_matrix_free(x);
ccv_garbage_collect();
}

#include "case_main.h"
2 changes: 1 addition & 1 deletion test/case_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ int main(int argc, char** argv)
printf("\033[0;32mall test case(s) passed, congratulations!\033[0;30m\n");
else
printf("\033[0;31m%d of %d test case(s) passed\033[0;30m\n", pass, fail + pass);
return 0;
return fail;
}

#endif
Binary file added test/data/blackbox.canny.bin
Binary file not shown.

0 comments on commit 893dc57

Please sign in to comment.