main.cpp
/**
 * Thread function for compare images.
 */
Thread function for compare images.
Thread function for compare images .
void *ThreadFunction(void *arg) {
    ThreadArgs* args = reinterpret_cast<ThreadArgs*>(arg);
    std::vector<std::string> images = args->images;
    int size = args->images.size();
    ResultStruct* result = new ResultStruct();
    std::vector<std::string> result_images;
    std::vector<double> result_diffs;
    double compare_diff;
    CompareArgs small_compare_args;
    small_compare_args.width = args->small_width;
    small_compare_args.height = args->small_height;
    small_compare_args.range = args->small_range;
    small_compare_args.pixels = args->small_pixels;
    CompareArgs compare_args;
    compare_args.width = args->width;
    compare_args.height = args->height;
    compare_args.range = args->range;
    compare_args.pixels = args->pixels;
    Image compare_image;
    try {
        for (int i = 0; i < size; i++) {
            std::string filename = images[i];
            std::string similar_image_dir = args->similar_image_dir;
            std::string image_path = similar_image_dir + "/" + filename;
            std::string small_image_path = similar_image_dir + "/4x4/" + filename;
            compare_image.read(small_image_path);
            small_compare_args.compare_image = compare_image;
            compare_diff = ImagesCompare(small_compare_args);
            if (compare_diff <= 0.15) {
                compare_image.read(image_path);
                compare_args.compare_image = compare_image;
                compare_diff = ImagesCompare(compare_args);
                if (compare_diff <= 0.07) {
                    result_images.push_back(filename);
                    result_diffs.push_back(compare_diff);
                }
            }
        }
    }
    catch(Exception &error_) { 
        cout << "Caught exception: " << error_.what() << endl;
        compare_diff = -1;
    }
    result->images = result_images;
    result->diffs = result_diffs;
    return (void *) result;
}
void * ThreadFunction ( void * arg ) { ThreadArgs * args = reinterpret_cast < ThreadArgs * > ( arg ) ; std :: vector < std :: string > images = args -> images ; int size = args -> images . size ( ) ; ResultStruct * result = new ResultStruct ( ) ; std :: vector < std :: string > result_images ; std :: vector < double > result_diffs ; double compare_diff ; CompareArgs small_compare_args ; small_compare_args . width = args -> small_width ; small_compare_args . height = args -> small_height ; small_compare_args . range = args -> small_range ; small_compare_args . pixels = args -> small_pixels ; CompareArgs compare_args ; compare_args . width = args -> width ; compare_args . height = args -> height ; compare_args . range = args -> range ; compare_args . pixels = args -> pixels ; Image compare_image ; try { for ( int i = 0 ; i < size ; i ++ ) { std :: string filename = images [ i ] ; std :: string similar_image_dir = args -> similar_image_dir ; std :: string image_path = similar_image_dir + " " + filename ; std :: string small_image_path = similar_image_dir + " " + filename ; compare_image . read ( small_image_path ) ; small_compare_args . compare_image = compare_image ; compare_diff = ImagesCompare ( small_compare_args ) ; if ( compare_diff <= 0.15 ) { compare_image . read ( image_path ) ; compare_args . compare_image = compare_image ; compare_diff = ImagesCompare ( compare_args ) ; if ( compare_diff <= 0.07 ) { result_images . push_back ( filename ) ; result_diffs . push_back ( compare_diff ) ; } } } } catch ( Exception & error_ ) { cout << " " << error_ . what ( ) << endl ; compare_diff = -1 ; } result -> images = result_images ; result -> diffs = result_diffs ; return ( void * ) result ; }
Thread function for compare images.
Thread function for compare images .
// Our result struct. // Read a file into image object.