int main(void) { PuzzleContext context; PuzzleCvec cvec; PuzzleCompressedCvec compressed_cvec; unsigned int sum; puzzle_init_context(&context); puzzle_init_compressed_cvec(&context, &compressed_cvec); puzzle_init_cvec(&context, &cvec); if (puzzle_fill_cvec_from_file(&context, &cvec, "pics/luxmarket_tshirt01.jpg") != 0) { fprintf(stderr, "File not found\n"); exit(0); } puzzle_compress_cvec(&context, &compressed_cvec, &cvec); puzzle_free_cvec(&context, &cvec); puzzle_init_cvec(&context, &cvec); puzzle_uncompress_cvec(&context, &compressed_cvec, &cvec); puzzle_cvec_cksum(&context, &cvec, &sum); puzzle_free_cvec(&context, &cvec); puzzle_free_compressed_cvec(&context, &compressed_cvec); puzzle_free_context(&context); printf("%u %u\n", sum, (unsigned int) EXPECTED_RESULT); return sum != EXPECTED_RESULT; }
int main(int argc, char *argv[]) { Opts opts; PuzzleContext context; PuzzleCvec cvec1, cvec2; double d; puzzle_init_context(&context); parse_opts(&opts, &context, argc, argv); puzzle_init_cvec(&context, &cvec1); puzzle_init_cvec(&context, &cvec2); if (puzzle_fill_cvec_from_file(&context, &cvec1, opts.file1) != 0) { fprintf(stderr, "Unable to read [%s]\n", opts.file1); return 1; } if (puzzle_fill_cvec_from_file(&context, &cvec2, opts.file2) != 0) { fprintf(stderr, "Unable to read [%s]\n", opts.file2); return 1; } d = puzzle_vector_normalized_distance(&context, &cvec1, &cvec2, opts.fix_for_texts); puzzle_free_cvec(&context, &cvec1); puzzle_free_cvec(&context, &cvec2); puzzle_free_context(&context); if (opts.exit == 0) { printf("%g\n", d); return 0; } if (d >= opts.similarity_threshold) { return 20; } return 10; }
int main(int argc, char* argv[]) { if (argc < 2) { printf("usage: %s <image_fpath>\n", argv[0]); return 1; } char* img_fpath = argv[1]; PuzzleContext context; PuzzleCvec cvec; puzzle_init_context(&context); puzzle_init_cvec(&context, &cvec); if (puzzle_fill_cvec_from_file(&context, &cvec, img_fpath) != 0) { fprintf(stderr, "Unable to read [%s]\n", img_fpath); return 1; } int i; for (i = 0; i < cvec.sizeof_vec; i++) { printf("%d ", cvec.vec[i]); } printf("\n"); puzzle_free_cvec(&context, &cvec); puzzle_free_context(&context); return 0; }
double puzzle_vector_normalized_distance(PuzzleContext * const context, const PuzzleCvec * const cvec1, const PuzzleCvec * const cvec2, const int fix_for_texts) { PuzzleCvec cvecr; double dt, dr; puzzle_init_cvec(context, &cvecr); puzzle_vector_sub(context, &cvecr, cvec1, cvec2, fix_for_texts); dt = puzzle_vector_euclidean_length(context, &cvecr); puzzle_free_cvec(context, &cvecr); dr = puzzle_vector_euclidean_length(context, cvec1) + puzzle_vector_euclidean_length(context, cvec2); if (dr == 0.0) { return 0.0; } return dt / dr; }