A Modern Computer Vision Library

View the Project on GitHub liuliu/ccv

Getting Started


ccv is very lightweight. There is no concept of ‘install’. If you want to use ccv, statically linking to it is sufficient. To the extreme, it is recommended to drop ccv source code into your project and use it directly.

For old-schooler, run ./configure && make in /lib directory will generate libccv.a for static linking with -lccv. For example, you have ccv source compiled in ~/ccv/, and you want to compile ~/studies/sift.c with ccv.

clang -L"~/ccv/lib" -I"~/ccv/lib" sift.c -lccv `cat ~/ccv/lib/.deps`

That it. The only magic sauce is ~/ccv/lib/.deps, which gives you all the dependencies you have to link to when you compile ccv the first time. If your ccv compiled with no dependency, it is empty (and ccv works with zero dependency).

Remember to checkout ./serve/makefile to see how a real-world program that uses ccv organizes.

Read a Photo

Let’s start with something small.

 1#include <ccv.h>
 3int main(int argc, char** argv)
 5        ccv_dense_matrix_t* image = 0;
 6        ccv_read(argv[1], &image, CCV_IO_GRAY | CCV_IO_ANY_FILE);
 7        ccv_write(image, argv[2], 0, CCV_IO_PNG_FILE, 0);
 8        return 0;

If your ccv build has dependency on libjpeg or libpng, the code above is sufficient to load any JPEG or PNG file into memory and save a grayscale version to the disk.

Detect a Face

Yes, knowing how to read a photo is sufficient to write an application that can do, for example, face detection.

 1#include <ccv.h>
 3int main(int argc, char** argv)
 5        ccv_dense_matrix_t* image = 0;
 6        ccv_read(argv[1], &image, CCV_IO_RGB_COLOR | CCV_IO_ANY_FILE);
 7        ccv_scd_classifier_cascade_t* cascade = ccv_scd_classifier_cascade_read(argv[2]);
 8        ccv_array_t* faces = ccv_scd_detect_objects(image, &cascade, 1, ccv_scd_default_params);
 9        int i;
10        for (i = 0; i < faces->rnum; i++)
11        {
12                ccv_comp_t* face = (ccv_comp_t*)ccv_array_get(faces, i);
13                printf("%d %d %d %d\n", face->rect.x, face->rect.y, face->rect.width, face->rect.height);
14        }
15        ccv_array_free(faces);
16        ccv_scd_classifier_cascade_free(cascade);
17        ccv_matrix_free(image);
18        return 0;

That’s it! You can run it in the command-line like this:

./detect image.png ~/ccv/samples/face.sqlite3

and it will output some regions of faces if there are some.

‹  back 

comments powered by Disqus