<commit_before>// Copyright (c) 2015, <NAME>

#include "fys.hpp"
#include "util.hpp"
#include "json_base.hpp"
#include "json_images.hpp"
#include "json_features.hpp"
#include "test.hpp"

using namespace std;
using namespace cv;

namespace fys {

void testSIFT(string featuresFile, string imagesFile)
{
    std::cout << "==== Test Start: SIFT Demo ====" << std::endl;

    Mat query = imread("../OneWaySignal/1.jpg", 0); // read gray image
    Mat test1 = imread("../OneWaySignal/2.jpg", 0);
    Mat test2 = imread("../OneWaySignal/5.jpg", 0);
    Mat test3 = imread("../OneWaySignal/9.jpg", 0);

    JsonFeatures jf(featuresFile);
    SIFT detectAndExtractor(jf.genSIFT());

    // Read images json file
    JsonImages ji(imagesFile);
    ImageObject ob = ji.getObjectByID(ji.doc, TRAIN_TYPE, 0, 0);

    vector<KeyPoint> queryKeys;
    vector<KeyPoint> testKeys;
    vector<KeyPoint> reducedKeys;
    Mat queryDescriptors, testDescriptors;
    BFMatcher matcher(jf.genBFMatcher());
    vector<DMatch> matches;
    Mat output;
    ImageRegion reg;
    Scalar color(0, 0, 255);
    
    detectAndExtractor.detect(query, queryKeys);

    // Delete the points outside the object region
    queryKeys = pointsInObject(queryKeys, ob);
    detectAndExtractor.compute(query, queryKeys, queryDescriptors);
    
    detectAndExtractor.detect(test1, testKeys);
    detectAndExtractor.compute(test1, testKeys, testDescriptors);

    matcher.match(queryDescriptors, testDescriptors, matches);

    // Delete unmatched points in train image
    reducedKeys = matchedPoints(testKeys, matches, TRAIN_PART_TYPE);
    reg = locateDenseRegion(reducedKeys, 0.05);

    drawMatches(query, queryKeys, test1, testKeys, matches, output);
    rectangle(output, Point(reg.xmin + query.cols, reg.ymin), Point(reg.xmax + query.cols, reg.ymax), color, 2);

#if 0
    imwrite("1-2.jpg", output);

    
    detectAndExtractor.detect(test2, testKeys);
    detectAndExtractor.compute(test2, testKeys, testDescriptors);

    matcher.match(queryDescriptors, testDescriptors, matches);

    drawMatches(query, queryKeys, test2, testKeys, matches, output);
    imwrite("1-5.jpg", output);


    detectAndExtractor.detect(test3, testKeys);
    detectAndExtractor.compute(test3, testKeys, testDescriptors);

    matcher.match(queryDescriptors, testDescriptors, matches);

    drawMatches(query, queryKeys, test3, testKeys, matches, output);
    imwrite("1-9.jpg", output);
#endif

    namedWindow("window");
    imshow("window", output); 
    waitKey(0);

    std::cout << "==== Test End: SIFT Demo ====" << std::endl;
}

}
<commit_msg>update parameters and save to image files<commit_after>// Copyright (c) 2015, <NAME>

#include "fys.hpp"
#include "util.hpp"
#include "json_base.hpp"
#include "json_images.hpp"
#include "json_features.hpp"
#include "test.hpp"

using namespace std;
using namespace cv;

namespace fys {

void testSIFT(string featuresFile, string imagesFile)
{
    std::cout << "==== Test Start: SIFT Demo ====" << std::endl;

    Mat query = imread("../OneWaySignal/1.jpg", 0); // read gray image
    Mat test1 = imread("../OneWaySignal/2.jpg", 0);
    Mat test2 = imread("../OneWaySignal/5.jpg", 0);
    Mat test3 = imread("../OneWaySignal/9.jpg", 0);

    JsonFeatures jf(featuresFile);
    SIFT detectAndExtractor(jf.genSIFT());

    // Read images json file
    JsonImages ji(imagesFile);
    ImageObject ob = ji.getObjectByID(ji.doc, TRAIN_TYPE, 0, 0);

    vector<KeyPoint> queryKeys;
    vector<KeyPoint> testKeys;
    vector<KeyPoint> reducedKeys;
    Mat queryDescriptors, testDescriptors;
    BFMatcher matcher(jf.genBFMatcher());
    vector<DMatch> matches;
    Mat output;
    ImageRegion reg;
    Scalar color(0, 0, 255);
    
    detectAndExtractor.detect(query, queryKeys);

    // Delete the points outside the object region
    queryKeys = pointsInObject(queryKeys, ob);
    detectAndExtractor.compute(query, queryKeys, queryDescriptors);
    
    detectAndExtractor.detect(test1, testKeys);
    detectAndExtractor.compute(test1, testKeys, testDescriptors);

    matcher.match(queryDescriptors, testDescriptors, matches);

    // Delete unmatched points in train image
    reducedKeys = matchedPoints(testKeys, matches, TRAIN_PART_TYPE);
    reg = locateDenseRegion(reducedKeys, 0.2);

    drawMatches(query, queryKeys, test1, testKeys, matches, output);
    rectangle(output, Point(reg.xmin + query.cols, reg.ymin), Point(reg.xmax + query.cols, reg.ymax), color, 2);

    imwrite("1-2.jpg", output);

    
    detectAndExtractor.detect(test2, testKeys);
    detectAndExtractor.compute(test2, testKeys, testDescriptors);

    matcher.match(queryDescriptors, testDescriptors, matches);
    reducedKeys = matchedPoints(testKeys, matches, TRAIN_PART_TYPE);
    reg = locateDenseRegion(reducedKeys, 0.2);

    drawMatches(query, queryKeys, test2, testKeys, matches, output);
    rectangle(output, Point(reg.xmin + query.cols, reg.ymin), Point(reg.xmax + query.cols, reg.ymax), color, 2);
    imwrite("1-5.jpg", output);


    detectAndExtractor.detect(test3, testKeys);
    detectAndExtractor.compute(test3, testKeys, testDescriptors);

    matcher.match(queryDescriptors, testDescriptors, matches);
    reducedKeys = matchedPoints(testKeys, matches, TRAIN_PART_TYPE);
    reg = locateDenseRegion(reducedKeys, 0.2);

    drawMatches(query, queryKeys, test3, testKeys, matches, output);
    rectangle(output, Point(reg.xmin + query.cols, reg.ymin), Point(reg.xmax + query.cols, reg.ymax), color, 2);
    imwrite("1-9.jpg", output);

    //namedWindow("window");
    //imshow("window", output); 
    //waitKey(0);

    std::cout << "==== Test End: SIFT Demo ====" << std::endl;
}

}

{'fraction_non_alphanumeric': 0.13605921748325697, 'fraction_numerical': 0.015861825872400422, 'mean_word_length': 4.187385740402194, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7210424', 'n_tokens_mistral': 1917, 'n_tokens_neox': 1855, 'n_words': 415}