<commit_before>﻿#ifdef _DEBUG
#include "testdatapath.h"
#endif 

#include <opencv2/opencv.hpp>
#include <iostream>
#include <string>

#include <qdir.h>
#include <qstringlist.h>

#include "cvutils.h"
#include "ImageScrap.h"

using namespace std;

int main(int argc, char** argv)
{
#ifdef _DEBUG
	//コマンドライン引数の解析。デバッグの時は使わない
	string commandArgs =
		"@input |  | processing one image or image named serial number"
		;

	cv::CommandLineParser parser(argc, argv, commandArgs);

	string src = parser.get<string>(0);
#else
	//string src = TEST_DATA_0;
	string src = "C:\\Users\\kyokushin\\Pictures\\testData\\";
#endif

	QDir dir(src.c_str());
	if (!dir.exists()) {
		cerr << "failed to find files" << endl;
		return 1;
	}

	QFileInfoList fileList = dir.entryInfoList(QDir::Files);
	fileList.size();

	cout << "input file:" << src << endl;

	int waitTime = 10;

	vector<int> imageHeights;
	vector<cv::Mat> pageNumbers;
	cv::Mat rowImage(1, 1, CV_8UC1);
	cv::Mat image;
	for (int i = 0; i < fileList.size(); i++){
		string fname = fileList[i].absoluteFilePath().toStdString();
		cout << fname << endl;
		cv::Mat colorImage = cv::imread(fname);

		//画像の読み込み。グレースケール画像として読み込む
		cv::cvtColor(colorImage, image, CV_BGR2GRAY);

		ImageScrap scrapImage(image, ImageScrap::RANGE_ALL);
		//scrapImage.show();

		scrapImage.getRow(0).copyTo(rowImage);
		imageHeights.push_back(rowImage.rows);//ページ番号と思われる領域を保存
		pageNumbers.push_back(rowImage);

		cout << "height:" << rowImage.rows << endl;
		showImage(rowImage, waitTime);
	}
<commit_msg>コマンドライン引数の追加と日本語対応<commit_after>﻿#ifdef _DEBUG
#include "testdatapath.h"
#endif 

#include <opencv2/opencv.hpp>
#include <iostream>
#include <string>

#include <qdir.h>
#include <qstring.h>
#include <qstringlist.h>

#include "cvutils.h"
#include "ImageScrap.h"

using namespace std;

enum PagePosition {
	TOP = 0,
	BOTTOM = 1
};

int main(int argc, char** argv)
{
	PagePosition pagePos;
#ifndef _DEBUG
	//コマンドライン引数の解析。デバッグの時は使わない
	const string commandArgs =
		"{@input |  | directory including ebook (jpg or png)}"
		"{position | top | page number position. top or bottom}"
		;

	cv::CommandLineParser parser(argc, argv, commandArgs);

	string src = parser.get<string>(0);
	string posStr = parser.get<string>("position");
	if (posStr == "top") {
		pagePos = PagePosition::TOP;
		cout << "page number top" << endl;
	}
	else if (posStr == "bottom") {
		pagePos = PagePosition::BOTTOM;
		cout << "page number bottom" << endl;
	}
	else {
		cerr << "error: page position is incorrect. specify top or bottom. specified:" << posStr << endl;
		return 1;
	}
#else
	//string src = TEST_DATA_0;
	//string src = "C:\\Users\\kyokushin\\Pictures\\testData_Top\\";
	string src = "C:\\Users\\kyokushin\\Pictures\\testData_Bottom\\";
	pagePos = PagePosition::BOTTOM;
#endif

	QDir dir(QString::fromLocal8Bit(src.c_str()));//Qt用の文字コードに変換
	if (!dir.exists()) {
		cerr << "error directory not exists. entered directory is \"" << src << "\"" << endl;
		return 1;
	}

	QFileInfoList fileList = dir.entryInfoList(QDir::Files);
	fileList.size();

	cout << "input file:" << src << endl;

	int waitTime = 10;


	vector<int> imageHeights;
	vector<cv::Mat> pageNumbers;
	cv::Mat rowImage(1, 1, CV_8UC1);
	cv::Mat image;
	for (int i = 0; i < fileList.size(); i++){
		string fname(fileList[i].absoluteFilePath().toLocal8Bit().constData());
		cout << fname << endl;
		cv::Mat colorImage = cv::imread(fname);

		//画像の読み込み。グレースケール画像として読み込む
		cv::cvtColor(colorImage, image, CV_BGR2GRAY);

		ImageScrap scrapImage(image, ImageScrap::RANGE_ALL);
		//scrapImage.show();

		if (pagePos == PagePosition::TOP) {
			scrapImage.getRow(0).copyTo(rowImage);
		}
		else {
			scrapImage.getRow(scrapImage.getRows() - 1).copyTo(rowImage);
		}
		imageHeights.push_back(rowImage.rows);//ページ番号と思われる領域を保存
		pageNumbers.push_back(rowImage);

		cout << "height:" << rowImage.rows << endl;
		showImage(rowImage, waitTime);
	}

{'fraction_non_alphanumeric': 0.16328626444159178, 'fraction_numerical': 0.008215661103979461, 'mean_word_length': 4.597701149425287, 'pattern_counts': {'":': 0, '<': 81, '<?xml version=': 0, '>': 21, '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': '3980920', 'n_tokens_mistral': 1634, 'n_tokens_neox': 1550, 'n_words': 317}