static char* test_encode_and_decode_compressed_large()
{
    const int64_t limit = INT64_C(3600) * 1000 * 1000;
    struct hdr_histogram* actual = NULL;
    struct hdr_histogram* expected = NULL;
    uint8_t* buffer = NULL;
    size_t len = 0;
    int rc = 0;
    hdr_init(1, limit, 4, &expected);
    srand(5);

    int i;
    for (i = 0; i < 8070; i++)
    {
        hdr_record_value(expected, rand() % limit);
    }

    rc = hdr_encode_compressed(expected, &buffer, &len);
    mu_assert("Did not encode", validate_return_code(rc));

    rc = hdr_decode_compressed(buffer, len, &actual);
    mu_assert("Did not decode", validate_return_code(rc));

    mu_assert("Loaded histogram is null", actual != NULL);

    mu_assert(
        "Comparison did not match",
        compare_histogram(expected, actual));

    free(expected);
    free(actual);

    return 0;
}
static char* test_encode_and_decode_compressed2()
{
    load_histograms();

    uint8_t* buffer = NULL;
    size_t len = 0;
    int rc = 0;
    struct hdr_histogram* actual = NULL;
    struct hdr_histogram* expected = cor_histogram;

    rc = hdr_encode_compressed(expected, &buffer, &len);
    mu_assert("Did not encode", validate_return_code(rc));

    rc = hdr_decode_compressed(buffer, len, &actual);
    mu_assert("Did not decode", validate_return_code(rc));

    mu_assert("Loaded histogram is null", actual != NULL);

    mu_assert(
            "Comparison did not match",
            compare_histogram(expected, actual));

    free(actual);

    return 0;
}
Ejemplo n.º 3
0
void segment_matching()
{
    pcl::PointXYZ g1, g2;

    for(int i=0;i<Object_Map.size();i++){
        int c = 0;
        if(Object_Map[i].tf != 1) continue;
        g1 = Object_Map[i].g;

        for(int j=0;j<Object_Map.size();j++){
            if(Object_Map[j].tf != 2) continue;
            g2 = Object_Map[j].g;

            double dis;
            dis = sqrt((g2.x-g1.x)*(g2.x-g1.x)+(g2.y-g1.y)*(g2.y-g1.y));
            if(dis < 0.07) {

                if((abs(Object_Map[j].size_x - Object_Map[i].size_x) < 5) && (abs(Object_Map[j].size_y - Object_Map[i].size_y) < 5)){
                    double avg1, avg2;
                    avg1 = average(Object_Map[j]);
                    avg2 = average(Object_Map[i]);

                    if(abs(avg1 - avg2) < 1.5){

                        if(abs(sqrt((double)variance(Object_Map[j], avg1)) - sqrt((double)variance(Object_Map[i], avg2))) < 10){
                            //カラー情報の比較
                            //HSV
                            if(compare_histogram(i, j)){
                                std::cout << i << " " << j << " 同じ物品" << std::endl;
                                Object_Map[i].tf = 0;
                                Object_Map[j].tf = 0;
                                c = 1;
                                break;
                            }
                            else std::cout << i << " " << j << " 色が違う" << std::endl;
                        }
                        else std::cout << i << " " << j << " 高さの分散が違う" << std::endl;
                    }
                    else std::cout << i << " " << j << " 高さの平均が違う" << abs(avg1 - avg2) << " " << avg1 << " " << avg2 << std::endl;
                }
                else std::cout << i << " " << j << " 広さが違う" << abs(Object_Map[j].size_x - Object_Map[i].size_x) << " " << abs(Object_Map[j].size_y - Object_Map[i].size_y) << std::endl;
            }
            else std::cout << i << " " << j << " 近くではない" << dis << std::endl;
        }
        if(c == 0) std::cout << i << " 変化箇所" << std::endl;
    }

    return;
}
static char* test_encode_decode_empty()
{
    struct hdr_histogram *histogram, *hdr_new = NULL;
    hdr_alloc(INT64_C(3600) * 1000 * 1000, 3, &histogram);

    char *data;

    mu_assert("Failed to encode histogram data", hdr_log_encode(histogram, &data) == 0);
    mu_assert("Failed to decode histogram data", hdr_log_decode(&hdr_new, data, strlen(data)) == 0);
    mu_assert("Histograms should be the same", compare_histogram(histogram, hdr_new));
    // mu_assert("Mean different after encode/decode", compare_double(hdr_mean(histogram), hdr_mean(hdr_new), 0.001));
    free(histogram);
    free(hdr_new);
    free(data);
    return 0;
}
static char* test_string_encode_decode()
{
    struct hdr_histogram *histogram, *hdr_new = NULL;
    hdr_alloc(INT64_C(3600) * 1000 * 1000, 3, &histogram);

    for (int i = 1; i < 100; i++)
    {
        hdr_record_value(histogram, i*i);
    }

    char *data;

    mu_assert("Failed to encode histogram data", hdr_log_encode(histogram, &data) == 0);
    mu_assert("Failed to decode histogram data", hdr_log_decode(&hdr_new, data, strlen(data)) == 0);
    mu_assert("Histograms should be the same", compare_histogram(histogram, hdr_new));
    mu_assert("Mean different after encode/decode", compare_double(hdr_mean(histogram), hdr_mean(hdr_new), 0.001));

    return 0;
}
static char* test_string_encode_decode_2()
{
    struct hdr_histogram *histogram, *hdr_new = NULL;
    hdr_alloc(1000, 3, &histogram);

    int i;
    for (i = 1; i < histogram->highest_trackable_value; i++)
    {
        hdr_record_value(histogram, i);
    }

    char *data;

    mu_assert(
        "Failed to encode histogram data", validate_return_code(hdr_log_encode(histogram, &data)));
    mu_assert(
        "Failed to decode histogram data", validate_return_code(hdr_log_decode(&hdr_new, data, strlen(data))));
    mu_assert("Histograms should be the same", compare_histogram(histogram, hdr_new));
    mu_assert("Mean different after encode/decode", compare_double(hdr_mean(histogram), hdr_mean(hdr_new), 0.001));

    return 0;
}
static char* writes_and_reads_log()
{
    const char* file_name = "histogram.log";
    hdr_timespec timestamp;
    hdr_timespec interval;

    hdr_gettime(&timestamp);
    interval.tv_sec = 5;
    interval.tv_nsec = 2000000;

    struct hdr_log_writer writer;
    struct hdr_log_reader reader;
    hdr_log_writer_init(&writer);
    hdr_log_reader_init(&reader);
    int rc = 0;

    FILE* log_file = fopen(file_name, "w+");

    rc = hdr_log_write_header(&writer, log_file, "Test log", &timestamp);
    mu_assert("Failed header write", validate_return_code(rc));
    hdr_log_write(&writer, log_file, &timestamp, &interval, cor_histogram);
    mu_assert("Failed corrected write", validate_return_code(rc));
    hdr_log_write(&writer, log_file, &timestamp, &interval, raw_histogram);
    mu_assert("Failed raw write", validate_return_code(rc));

    fprintf(log_file, "\n");

    fflush(log_file);
    fclose(log_file);

    log_file = fopen(file_name, "r");

    struct hdr_histogram* read_cor_histogram = NULL;
    struct hdr_histogram* read_raw_histogram = NULL;

    rc = hdr_log_read_header(&reader, log_file);
    mu_assert("Failed header read", validate_return_code(rc));
    mu_assert("Incorrect major version", compare_int(reader.major_version, 1));
    mu_assert("Incorrect minor version", compare_int(reader.minor_version, 2));
    mu_assert(
        "Incorrect start timestamp",
        compare_timespec(&reader.start_timestamp, &timestamp));

    hdr_timespec actual_timestamp;
    hdr_timespec actual_interval;

    rc = hdr_log_read(
        &reader, log_file, &read_cor_histogram,
        &actual_timestamp, &actual_interval);
    mu_assert("Failed corrected read", validate_return_code(rc));
    mu_assert(
        "Incorrect first timestamp", compare_timespec(&actual_timestamp, &timestamp));
    mu_assert(
        "Incorrect first interval", compare_timespec(&actual_interval, &interval));

    rc = hdr_log_read(&reader, log_file, &read_raw_histogram, NULL, NULL);
    mu_assert("Failed raw read", validate_return_code(rc));

    mu_assert(
        "Histograms do not match",
        compare_histogram(cor_histogram, read_cor_histogram));

    mu_assert(
        "Histograms do not match",
        compare_histogram(raw_histogram, read_raw_histogram));

    rc = hdr_log_read(&reader, log_file, &read_cor_histogram, NULL, NULL);
    mu_assert("No EOF at end of file", rc == EOF);

    fclose(log_file);
    remove(file_name);

    return 0;
}