<commit_before>#include <opencv2/opencv.hpp>
#include <opencv2/objdetect/objdetect.hpp>

#include <cmath>
#include <iostream>
#include <vector>


const double hairOffset = 0.12;
const double scale = 1.1;
const int neighbors = 4;
const int minSize = 64;
const int maxCorners = 20;
const double qualityLevel = 0.05;
const int minDistance = 30;
const int featureSize = 15;

const char *faceCascade = "/usr/share/opencv/lbpcascades/lbpcascade_frontalface.xml";
const char *profCascade = "/usr/share/opencv/haarcascades/haarcascade_profileface.xml";


void display(std::vector<cv::Rect> &rects, const char *type) {
	cv::groupRectangles(rects, 0);
	for (cv::Rect rect : rects) {
		std::cout
			<< rect.x << " "
			<< rect.y << " "
			<< rect.width << " "
			<< rect.height << " "
			<< type << std::endl;
	}

}


int main(int argc, const char **argv) {
	if (argc < 2) {
		std::cerr << "Usage: fnf-detect <image>" << std::endl;
		return -1;
	}

	const char *filename = argv[1];
	cv::Mat img = imread(filename, cv::IMREAD_GRAYSCALE);
	if (img.empty())
	{
		std::cerr << "Cannot read" << filename << std::endl;
		return -1;
	}
	cv::equalizeHist(img, img);

	double length = sqrt(img.size().area());
	cv::Size min = cv::Size(minSize, minSize);
	cv::Size max = cv::Size(length / 3, length / 3);
	std::vector<cv::Rect> rects;

	cv::CascadeClassifier faceClassifier = cv::CascadeClassifier(faceCascade);
	faceClassifier.detectMultiScale(img, rects, scale, neighbors, 0, min, max);
	if (rects.size() > 0) {
		for (cv::Rect rect : rects) {
			rect.y -= rect.height * hairOffset;
			if (rect.y < 0) rect.y = 0;
		}
		display(rects, "face");
		return 0;
	}

	cv::CascadeClassifier profClassifier = cv::CascadeClassifier(profCascade);
	profClassifier.detectMultiScale(img, rects, scale, neighbors, 0, min, max);
	if (rects.size() > 0) {
		display(rects, "profile");
		return 0;
	}

	std::vector<cv::Point2f> corners;
	goodFeaturesToTrack(img, corners, maxCorners, qualityLevel, minDistance);
	for (cv::Point2f corner : corners) {
		rects.push_back(cv::Rect(corner.x - featureSize/2,
		                         corner.y - featureSize/2,
			                 featureSize,
			                 featureSize));
		display(rects, "feature");
	}

	return 0;
}<commit_msg>Fix: don't display features several times<commit_after>#include <opencv2/opencv.hpp>
#include <opencv2/objdetect/objdetect.hpp>

#include <cmath>
#include <iostream>
#include <vector>


const double hairOffset = 0.12;
const double scale = 1.1;
const int neighbors = 4;
const int minSize = 64;
const int maxCorners = 20;
const double qualityLevel = 0.05;
const int minDistance = 30;
const int featureSize = 3;

const char *faceCascade = "/usr/share/opencv/lbpcascades/lbpcascade_frontalface.xml";
const char *profCascade = "/usr/share/opencv/haarcascades/haarcascade_profileface.xml";


void display(std::vector<cv::Rect> &rects, const char *type) {
	cv::groupRectangles(rects, 0);
	for (cv::Rect rect : rects) {
		std::cout
			<< rect.x << " "
			<< rect.y << " "
			<< rect.width << " "
			<< rect.height << " "
			<< type << std::endl;
	}

}


int main(int argc, const char **argv) {
	if (argc < 2) {
		std::cerr << "Usage: fnf-detect <image>" << std::endl;
		return -1;
	}

	const char *filename = argv[1];
	cv::Mat img = imread(filename, cv::IMREAD_GRAYSCALE);
	if (img.empty())
	{
		std::cerr << "Cannot read" << filename << std::endl;
		return -1;
	}
	cv::equalizeHist(img, img);

	double length = sqrt(img.size().area());
	cv::Size min = cv::Size(minSize, minSize);
	cv::Size max = cv::Size(length / 3, length / 3);
	std::vector<cv::Rect> rects;

	cv::CascadeClassifier faceClassifier = cv::CascadeClassifier(faceCascade);
	faceClassifier.detectMultiScale(img, rects, scale, neighbors, 0, min, max);
	if (rects.size() > 0) {
		for (cv::Rect rect : rects) {
			rect.y -= rect.height * hairOffset;
			if (rect.y < 0) rect.y = 0;
		}
		display(rects, "face");
		return 0;
	}

	cv::CascadeClassifier profClassifier = cv::CascadeClassifier(profCascade);
	profClassifier.detectMultiScale(img, rects, scale, neighbors, 0, min, max);
	if (rects.size() > 0) {
		display(rects, "profile");
		return 0;
	}

	std::vector<cv::Point2f> corners;
	goodFeaturesToTrack(img, corners, maxCorners, qualityLevel, minDistance);
	for (cv::Point2f corner : corners) {
		rects.push_back(cv::Rect(corner.x - featureSize/2,
		                         corner.y - featureSize/2,
			                 featureSize,
			                 featureSize));
	}
	display(rects, "feature");

	return 0;
}
{'fraction_non_alphanumeric': 0.162677304964539, 'fraction_numerical': 0.017065602836879433, 'mean_word_length': 3.8579117330462864, 'pattern_counts': {'":': 0, '<': 85, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '2303507', 'n_tokens_mistral': 1785, 'n_tokens_neox': 1632, 'n_words': 379}