コード例 #1
0
ファイル: hello.c プロジェクト: oesmith/plates
int main(int argc, char** argv)
{
  int counter = 0;
  ccv_dense_matrix_t* image = 0;

  ccv_enable_default_cache();

  ccv_read(argv[1], &image, CCV_IO_GRAY | CCV_IO_ANY_FILE);
  if (image != 0)
  {
    ccv_array_t* words = ccv_swt_detect_words(image, ccv_swt_default_params);
    if (words)
    {
      int i;
      for (i = 0; i < words->rnum; i++)
      {
        char filename[256];
        ccv_matrix_t* box = 0;
        ccv_rect_t* rect = (ccv_rect_t*)ccv_array_get(words, i);
        ccv_slice(image, &box, 0, rect->y, rect->x, rect->height, rect->width);
        printf("%d %d %d %d\n", rect->x, rect->y, rect->width, rect->height);
        snprintf(filename, 256, "out-%d.png", ++counter);
        ccv_write(box, filename, NULL, CCV_IO_PNG_FILE, NULL);
      }
    }
    ccv_array_free(words);
  }

  ccv_drain_cache();
  return 0;
}
コード例 #2
0
ファイル: canny.c プロジェクト: patriot7/ccv
int
main(int argc, char** argv)
{
        printf("Edge Detection Benchmark ...\n");

	ccv_enable_default_cache();
        unsigned int elapsed_time;
        ccv_dense_matrix_t* yuv = 0;
        ccv_read(argv[1], &yuv, CCV_IO_GRAY | CCV_IO_ANY_FILE);

        /* ORIGIN */
        ccv_dense_matrix_t* canny = 0;
        elapsed_time = get_current_time();
        ccv_canny(yuv, &canny, 0, 3, 175, 320);
        elapsed_time = get_current_time() - elapsed_time;
        printf("origin: %ums\n", elapsed_time);
        ccv_matrix_free(canny);


        /* SLICE & DETECT */
        int X_SLICE = atoi(argv[2]), Y_SLICE = atoi(argv[3]);
        int i, count = X_SLICE * Y_SLICE;
        int slice_rows = yuv->rows / Y_SLICE;
        int slice_cols = yuv->cols / X_SLICE;
        ccv_dense_matrix_t* canny_arr[count];
        elapsed_time = get_current_time();
#pragma omp parallel for
        for (i = 0; i < count; i++) {
                int y = i / X_SLICE;
                int x = i - X_SLICE * y;
                ccv_dense_matrix_t* slice = 0;
                ccv_slice(yuv, (ccv_matrix_t**)&slice, 0, slice_rows * y, slice_cols * x, slice_rows, slice_cols);
#ifdef DEBUG
                cos_ccv_slice_output(slice, y, x);
#endif
                canny_arr[i] = 0;
                ccv_canny(slice, &canny_arr[i], 0, 3, 175, 320);
        }
        elapsed_time = get_current_time() - elapsed_time;
        printf("slice & detect: %ums\n", elapsed_time);

        unsigned int slice_time = elapsed_time; /* save to compute total time */

        /* MERGE */
        ccv_dense_matrix_t* final_output = 0;
        elapsed_time = get_current_time();
        cos_ccv_merge(canny_arr, &final_output, yuv->rows, yuv->cols, X_SLICE, Y_SLICE);
        elapsed_time = get_current_time() - elapsed_time;
        printf("merge: %ums\n", elapsed_time);
        ccv_matrix_free(final_output);

        printf("parallel total: %ums\n", slice_time + elapsed_time);

        ccv_matrix_free(yuv);
	ccv_disable_cache();

	return 0;
}
コード例 #3
0
ファイル: bbfdetect.c プロジェクト: patriot7/ccv
int
main(int argc, char** argv)
{
        printf("Face Detection Benchmark ...\n");
	ccv_enable_default_cache();

	ccv_dense_matrix_t* image = 0;
	ccv_bbf_classifier_cascade_t* cascade = ccv_bbf_read_classifier_cascade(argv[4]);
	ccv_read(argv[1], &image, CCV_IO_GRAY | CCV_IO_ANY_FILE);

        unsigned int elapsed_time;
        ccv_array_t* seq;

        elapsed_time = get_current_time();
        seq = ccv_bbf_detect_objects(image, &cascade, 1, ccv_bbf_default_params);
        elapsed_time = get_current_time() - elapsed_time;
        printf("origin: %d in %dms\n", seq->rnum, elapsed_time);
        ccv_array_free(seq);

        int X_SLICE = atoi(argv[2]), Y_SLICE = atoi(argv[3]);
        int sliced_total = 0;
        int slice_rows = image->rows / Y_SLICE;
        int slice_cols = image->cols / X_SLICE;
        int i, count = X_SLICE * Y_SLICE;
        elapsed_time = get_current_time();
#pragma omp parallel for shared(sliced_total)
        for (i = 0; i < count; i++) {
                int y = i / X_SLICE;
                int x = i - X_SLICE * y;
                ccv_dense_matrix_t* slice = 0;
                ccv_slice(image, (ccv_matrix_t**)&slice, 0, slice_rows * y, slice_cols * x, slice_rows, slice_cols);
                ccv_array_t* sseq = ccv_bbf_detect_objects(slice, &cascade, 1, ccv_bbf_default_params);
                sliced_total += sseq->rnum;
#ifdef DEBUG
                cos_ccv_slice_output(slice, y, x);
#endif
        }
        elapsed_time = get_current_time() - elapsed_time;
        printf("slice & detect: %d in %dms\n", sliced_total, elapsed_time);

        ccv_matrix_free(image);
	ccv_bbf_classifier_cascade_free(cascade);
	ccv_disable_cache();
	return 0;
}
コード例 #4
0
ファイル: nnc-e2e-verify.c プロジェクト: Corion/image-ccv
int main(int argc, char** argv)
{
	ccv_nnc_init();
	ccv_convnet_t* convnet = ccv_convnet_read(0, argv[2]);
	ccv_dense_matrix_t* image = 0;
	ccv_read(argv[1], &image, CCV_IO_ANY_FILE | CCV_IO_RGB_COLOR);
	if (image != 0)
	{
		ccv_dense_matrix_t* input = 0;
		ccv_convnet_input_formation(convnet->input, image, &input);
		ccv_matrix_free(image);
		ccv_dense_matrix_t* sliced = 0;
		ccv_slice(input, (ccv_matrix_t**)&sliced, 0, (input->rows - 225) / 2, (input->cols - 225) / 2, 225, 225);
		ccv_matrix_free(input);
		ccv_dense_matrix_t* b = 0;
		unsigned int elapsed_time = get_current_time();
		ccv_convnet_encode(convnet, &sliced, &b, 1);
		printf("ccv_convnet_encode %u ms\n", get_current_time() - elapsed_time);
		ccv_nnc_tensor_t* c = ccv_nnc_tensor_new(0, ONE_CPU_TENSOR(1000), 0);
		ccv_nnc_graph_exec_t source, dest;
		ccv_array_t* tensors = ccv_array_new(sizeof(ccv_nnc_tensor_t*), 1, 0);
		ccv_nnc_graph_t* graph = ccv_nnc_simple_graph(convnet, (ccv_nnc_tensor_t*)sliced, c, &source, &dest, tensors);
		elapsed_time = get_current_time();
		ccv_nnc_graph_run(graph, 0, &source, 1, &dest, 1);
		printf("ccv_nnc_graph_run %u ms\n", get_current_time() - elapsed_time);
		int i;
		for (i = 0; i < 1000; i++)
			if (fabsf(b->data.f32[i] - c->data.f32[i]) > 1e-4)
				printf("mis-match at %d: %f %f\n", i, b->data.f32[i], c->data.f32[i]);
		ccv_nnc_tensor_free(c);
		ccv_matrix_free(sliced);
		ccv_matrix_free(b);
		ccv_nnc_graph_free(graph);
		for (i = 0; i < tensors->rnum; i++)
			ccv_nnc_tensor_free(*(ccv_nnc_tensor_t**)ccv_array_get(tensors, i));
		ccv_array_free(tensors);
	}
	ccv_convnet_free(convnet);
	return 0;
}