Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
with ccv_color_transform and ccv_read prototype
added two new functions, ccv_color_transform and ccv_read with 6
parameters.

with the new ccv_read interface, I should be able to implement a interp
functions that will read buffer of image data sequence and emit
ccv_dense_matrix_t.
  • Loading branch information
liuliu committed Jul 15, 2012
1 parent d42b4f8 commit b8d6fb2
Show file tree
Hide file tree
Showing 8 changed files with 722 additions and 543 deletions.
48 changes: 26 additions & 22 deletions bin/msermatch.c
Expand Up @@ -15,38 +15,42 @@ int main(int argc, char** argv)
assert(argc == 3);
ccv_enable_default_cache();
ccv_dense_matrix_t* image = 0;
ccv_read(argv[1], &image, CCV_IO_COLOR | CCV_IO_ANY_FILE);
ccv_read(argv[1], &image, CCV_IO_RGB_COLOR | CCV_IO_ANY_FILE);
ccv_mser_param_t params = {
.min_area = 60,
.max_area = (int)(image->rows * image->cols * 0.3 + 0.5),
.min_diversity = 0.2,
.area_threshold = 1.01,
.min_margin = 0.003,
.max_evolution = 200,
.edge_blur_sigma = sqrt(5.0),
.edge_blur_sigma = sqrt(3.0),
};
ccv_dense_matrix_t* mser = 0;
ccv_array_t* mser_keypoint = ccv_mser(image, 0, &mser, 0, params);
ccv_dense_matrix_t* graph = ccv_dense_matrix_new(image->rows, image->cols, CCV_8U | CCV_C3, 0, 0);
ccv_matrix_free(image);
ccv_array_free(mser_keypoint);
int i, j;
for (i = 0; i < graph->rows; i++)
for (j = 0; j < graph->cols; j++)
{
if (mser->data.i32[i * mser->cols + j] == 0)
if (image)
{
ccv_dense_matrix_t* yuv = 0;
ccv_color_transform(image, &yuv, 0, CCV_RGB_TO_YUV);
unsigned int elapsed_time = get_current_time();
ccv_dense_matrix_t* mser = 0;
ccv_array_t* mser_keypoint = ccv_mser(yuv, 0, &mser, 0, params);
elapsed_time = get_current_time() - elapsed_time;
printf("total : %d in time %dms\n", mser_keypoint->rnum, elapsed_time);
ccv_array_free(mser_keypoint);
ccv_make_matrix_mutable(image);
int i, j;
for (i = 0; i < image->rows; i++)
for (j = 0; j < image->cols; j++)
{
graph->data.u8[i * graph->step + j * 3] =
graph->data.u8[i * graph->step + j * 3 + 1] =
graph->data.u8[i * graph->step + j * 3 + 2] = 255;
} else {
graph->data.u8[i * graph->step + j * 3] = colors[mser->data.i32[i * mser->cols + j] % 6][0];
graph->data.u8[i * graph->step + j * 3 + 1] = colors[mser->data.i32[i * mser->cols + j] % 6][1];
graph->data.u8[i * graph->step + j * 3 + 2] = colors[mser->data.i32[i * mser->cols + j] % 6][2];
if (mser->data.i32[i * mser->cols + j])
{
image->data.u8[i * image->step + j * 3] = colors[mser->data.i32[i * mser->cols + j] % 6][0];
image->data.u8[i * image->step + j * 3 + 1] = colors[mser->data.i32[i * mser->cols + j] % 6][1];
image->data.u8[i * image->step + j * 3 + 2] = colors[mser->data.i32[i * mser->cols + j] % 6][2];
}
}
}
ccv_write(graph, argv[2], 0, CCV_IO_PNG_FILE, 0);
ccv_matrix_free(graph);
ccv_write(image, argv[2], 0, CCV_IO_PNG_FILE, 0);
ccv_matrix_free(image);
ccv_matrix_free(yuv);
}
ccv_disable_cache();
return 0;
}
49 changes: 39 additions & 10 deletions lib/ccv.h
Expand Up @@ -252,17 +252,31 @@ void ccv_enable_cache(size_t size);

enum {
CCV_IO_GRAY = 0x100,
CCV_IO_COLOR = 0x300,
CCV_IO_RGB_COLOR = 0x300,
};

enum {
// read self-describe in-memory data
CCV_IO_ANY_STREAM = 0x010,
CCV_IO_PLAIN_STREAM = 0x011,
CCV_IO_DEFLATE_STREAM = 0x012,
CCV_IO_JPEG_STREAM = 0x013,
CCV_IO_PNG_STREAM = 0x014,
// read self-describe on-disk data
CCV_IO_ANY_FILE = 0x020,
CCV_IO_BMP_FILE = 0x021,
CCV_IO_JPEG_FILE = 0x022,
CCV_IO_PNG_FILE = 0x023,
CCV_IO_BINARY_FILE = 0x024,
// read not-self-describe in-memory data (a.k.a. raw data)
// you need to specify rows, cols, or scanline for these data
CCV_IO_RGB_RAW = 0x031,
CCV_IO_RGBA_RAW = 0x032,
CCV_IO_ARGB_RAW = 0x033,
CCV_IO_BGR_RAW = 0x034,
CCV_IO_BGRA_RAW = 0x035,
CCV_IO_ABGR_RAW = 0x036,
CCV_IO_GRAY_RAW = 0x037,
};

enum {
Expand All @@ -272,7 +286,14 @@ enum {
CCV_IO_ATTEMPTED,
};

int ccv_read(const char* in, ccv_dense_matrix_t** x, int type);
int ccv_read_impl(const char* in, ccv_dense_matrix_t** x, int type, int rows, int cols, int scanline);
#define ccv_read_n(in, x, type, rows, cols, scanline, ...) \
ccv_read_impl(in, x, type, rows, cols, scanline)
#define ccv_read(in, x, type, ...) \
ccv_read_n(in, x, type, ##__VA_ARGS__, 0, 0, 0)
// this is a way to implement function-signature based dispatch, you can call either
// ccv_read(in, x, type) or ccv_read(in, x, type, rows, cols, scanline)
// notice that you can implement this with va_* functions, but that is not type-safe
int ccv_write(ccv_dense_matrix_t* mat, char* out, int* len, int type, void* conf);

/* basic algebra algorithms ccv_algebra.c */
Expand Down Expand Up @@ -454,6 +475,22 @@ void ccv_compressive_sensing_reconstruct(ccv_matrix_t* a, ccv_matrix_t* x, ccv_m
void ccv_sobel(ccv_dense_matrix_t* a, ccv_dense_matrix_t** b, int type, int dx, int dy);
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);

enum {
CCV_FLIP_X = 0x01,
CCV_FLIP_Y = 0x02,
};

void ccv_flip(ccv_dense_matrix_t* a, ccv_dense_matrix_t** b, int btype, int type);
void ccv_blur(ccv_dense_matrix_t* a, ccv_dense_matrix_t** b, int type, double sigma);

enum {
CCV_RGB_TO_YUV = 0x01,
};

void ccv_color_transform(ccv_dense_matrix_t* a, ccv_dense_matrix_t** b, int type, int flag);

/* resample algorithms ccv_resample.c */

enum {
CCV_INTER_AREA = 0x01,
CCV_INTER_LINEAR = 0X02,
Expand All @@ -465,14 +502,6 @@ void ccv_resample(ccv_dense_matrix_t* a, ccv_dense_matrix_t** b, int btype, int
void ccv_sample_down(ccv_dense_matrix_t* a, ccv_dense_matrix_t** b, int type, int src_x, int src_y);
void ccv_sample_up(ccv_dense_matrix_t* a, ccv_dense_matrix_t** b, int type, int src_x, int src_y);

enum {
CCV_FLIP_X = 0x01,
CCV_FLIP_Y = 0x02,
};

void ccv_flip(ccv_dense_matrix_t* a, ccv_dense_matrix_t** b, int btype, int type);
void ccv_blur(ccv_dense_matrix_t* a, ccv_dense_matrix_t** b, int type, double sigma);

/* classic computer vision algorithms ccv_classic.c */

void ccv_hog(ccv_dense_matrix_t* a, ccv_dense_matrix_t** b, int b_type, int sbin, int size);
Expand Down

0 comments on commit b8d6fb2

Please sign in to comment.