Ejemplo n.º 1
0
//----------------------------------------------------------------------------------
int main(int argc,char* argv[])
{

	ofstream fut;
	fut.open("panProcess.dat", ios::binary | ios::out);
	fut.write((char*)'1', sizeof(char));
	fut.close();
	exit(1);
	Point matchLoc;
	char winname[] = "window";
	//^template matching params
	Mat background;
	Mat image;
	String file(argv[0]);
	/*cout << "enter the file name to be analyzed \t";
	cin >> file;*/
	file += argv[1];
	imgSample = imread(file, CV_LOAD_IMAGE_UNCHANGED);
	imgOriginal = imread(file, CV_LOAD_IMAGE_UNCHANGED);
	if (imgSample.data == NULL){ cout << "hi there"; return -1; }
	if (imgOriginal.data == NULL){ cout << "hi there"; return -1; }
	winarr[0] = 'w';//global window array
	winarr[1] = 'i';
	winarr[2] = 'n';
	winarr[3] = 't';
	winarr[4] = 't';
	winarr[5] = '.';
	winarr[6] = 'p';
	winarr[7] = 'n';
	winarr[8] = 'g';
	winarr[9] = '\0';
	
//
//if (choice == 2){
//		system("cls");
//		cout << "---------PAN CARD dataset creation-------";
//			vector<vector<Point>> namecont;
//			//create templates
//			cout << "--------CREATE Templates---------";
//			::i = 0;
//			winarr[3] = '5';
//			namedWindow(winname, WINDOW_AUTOSIZE);
//			setMouseCallback(winname, mcallback, NULL);
//			imshow(winname, imgOriginal);
//			waitKey(0);
//			Mat passer = imgOriginal.clone();
//			for (int c = 0; c < ::i; c++){
//				Mat imag = imgOriginal(Rect(points[c][0], points[c][2]));
//				//fillConvexPoly(passer, points[c], NUMPTS, Scalar(255, 255, 255));
//				winarr[4] = c + 48;
//				imwrite(winarr, imag);
//			}
//			system("pause");
//			cout << "creating the background interface data\n";
//			//getbkgd(passer, background, 1, 37, 31, 20);
//			//getcontours(passer, namecont);
//			cout << "got it";
//
//		}

	Methods S;
	datafile testout;
	PAN pan;
	Mat panimg = (imgOriginal.clone());
	PAN::Image output;
	vector<vector<Point>> contours;
	//detect text is required
	//local vars
	pan.init(&panimg, 0, panimg.cols, 0, panimg.rows, Point2f(0, 0));
	Mat snipped = pan.getcontours(contours, TEXT);//u get only text contours
	contours = pan.mergecontours(contours);
	OCRit(snipped, contours, testout.data, snipped, "eng");//global function
	pan.authenticate(argv[2]);
	testout.authenticity = pan.getauthenticity();
	//extract signature
	snipped = pan.getcontours(contours, SIGN);
	Mat sign = pan.extractSIGN(contours);
	imshow("sign", sign);
	waitKey();
	pan.showpan();
	//will use fake database too after sometime but not now
	//String FakeDatabase = CWD + "\\fake\\sign1" + (char)48 + ".png";

	//cout << OrigDatabase << "\n\n-----------\n\n";
	//cout << FakeDatabase << "\n\n-----------\n\n";
	//---------------------------------------------------------------------
	//ifstream sigfile("sig.dat", ios::binary | ios::in);
	vector<Methods::Image> *std = new vector<Methods::Image >();
	vector<FV::feature> *reference = new vector<FV::feature >();
	FV refV;
	FV tesV;
	float tolerance = (float)0.1;
	/*if (sigfile.is_open()){
		refV.load("sig.dat");
		}
		else*/{
		//Mat sign=imread("sign10.png");
		S.preprocess(&sign, std);
		S.partitionImage(&sign, NUMPART, std);
		S.calculateCOG(std);
		S.calculateCOGDistances(std);
		S.calculateCOGAngles(std);
		//S.showSubImages(std, &sign, "sign10.png");
		refV.add(std, reference);
	}
	float result = 0, count = 0, sum = 0;
	for (int i = 10; i < 19; i++){
		Methods T;
		vector<Methods::Image> *signtest = new vector<Methods::Image >();
		vector<FV::feature> *test = new vector<FV::feature >();
		String imagename(argv[0]);
		imagename =imagename + "signature//sign";
		imagename = imagename + (char)((i / 10) + 48) + (char)((i % 10) + 48) + ".png";
		Mat testsign = imread(imagename);
		//cout << OrigDatabase + imagename << "\n-------------------------\n";
		T.preprocess(&testsign, signtest);
		T.partitionImage(&testsign, NUMPART, signtest);
		T.calculateCOG(signtest);
		T.calculateCOGDistances(signtest);
		T.calculateCOGAngles(signtest);
		tesV.add(signtest, test);
		//T.showSubImages(signtest, &testsign, imagename);
		result = refV.compareNupdate(tesV.standard, tolerance, 70);
		if (result >= 70){ sum += result; count++; }
	}
	if (count != 0){
	sum /= count;
	cout << "good matches were " << count<<"\n";
	testout.sigverif = sum;
}
	else{ testout.sigverif = 0; }
	
	
	//---------------------------------------------------------------------
//write testout to a file
	ofstream fout;
	fout.open("panProcess.dat", ios::binary | ios::out);
	fout.write((char*)&testout, sizeof(testout));
	fout.close();
	}