Repository navigation
Expand file tree
/
Copy pathrecognizer.cpp
More file actions
executable file
·846 lines (735 loc) · 28.1 KB
/
Copy pathrecognizer.cpp
File metadata and controls
executable file
·846 lines (735 loc) · 28.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
#include "recognizer.h"
#include "ui_recognizer.h"
#include "QDebug"
const QList<QSize> Recognizer::RESOLUTION = QList<QSize> ()
<< QSize(600,480)
<< QSize(800,600)
<< QSize(1024,768)
<< QSize(1280,1024)
<< QSize(1680,1050)
<< QSize(1920,1080)
<< QSize(2160,1440);
const QList<QString> ColorAlgorithmString = QList<QString> ()
<< "Not using any color detection"
<< "Perform color classifer on entire image"
<< "Perform color classifier only on identified object"
<< "Calculate color percentage occupied on identified object";
Recognizer::Recognizer(QWidget *parent) :
QMainWindow(parent),
settingsUI(new Ui::Recognizer)
{
settingsUI->setupUi(this);
LoadSettings();
Initialization();
onOpSel();
this->adjustSize();
}
Recognizer::~Recognizer()
{
delete statProgress;
delete detector;
delete settingsUI;
}
//turn visibility based on user's intended operation
void Recognizer::onOpSel(){
settingsUI->groupBox_CamSet->setVisible(false);
settingsUI->groupBox_preparation->setVisible(false);
settingsUI->groupBox_ObjDet->setVisible(false);
settingsUI->groupBox_FacialRec->setVisible(false);
settingsUI->groupBox_prediction->setVisible(false);
settingsUI->groupBox_colorClassifier->setVisible(false);
settingsUI->groupBox_XML_creator->setVisible(false);
emit settingsUI->comboBox_colorClassifierAlgorithm->currentIndexChanged(
settingsUI->comboBox_colorClassifierAlgorithm->currentIndex());
if(settingsUI->pushButton_liveFacial->isChecked()){
settingsUI->groupBox_CamSet->setVisible(true);
settingsUI->groupBox_preparation->setVisible(true);
settingsUI->groupBox_ObjDet->setVisible(true);
settingsUI->groupBox_FacialRec->setVisible(true);
StackWidgetIndex = TAB_LIVEFACIAL;
} else if(settingsUI->pushButton_stillFacial->isChecked()){
settingsUI->groupBox_preparation->setVisible(true);
settingsUI->groupBox_ObjDet->setVisible(true);
settingsUI->groupBox_FacialRec->setVisible(true);
settingsUI->groupBox_prediction->setVisible(true);
StackWidgetIndex = TAB_STILLFACIAL;
} else if(settingsUI->pushButton_stillObject->isChecked()){
settingsUI->groupBox_preparation->setVisible(true);
settingsUI->groupBox_ObjDet->setVisible(true);
StackWidgetIndex = TAB_STILLOBJECT;
} else if(settingsUI->pushButton_XMLcreator->isChecked()){
settingsUI->groupBox_XML_creator->setVisible(true);
StackWidgetIndex = TAB_XMLCREATOR;
} else {
StackWidgetIndex = TAB_EMPTY;
}
}
bool Recognizer::passParaToOp(){
if(settingsUI->stackedWidget->currentIndex() == StackWidgetIndex)
return false;
if(StackWidgetIndex == TAB_LIVEFACIAL)
{
detector->setCameraDevice(settingsUI->CameraNumber->value());
detector->setCameraResolution(settingsUI->comboBox_CameraResolution->currentData().toSize());
detector->setModels(settingsUI->LBPH_checkBox->isChecked(),LBPHModel,settingsUI->EigenFace_checkBox->isChecked(),EigenFaceModel,settingsUI->FisherFace_checkBox->isChecked(),FisherFaceModel);
detector->setImageHeight(img_height);
detector->setImageWidth(img_width);
detector->setUpdatingTime(settingsUI->CameraUpdateTime->value());
detector->setClassifierDuration(settingsUI->ClassifierDuration->value());
detector->setColorBound(settingsUI->spinBox_LH->value(),
settingsUI->spinBox_LS->value(),
settingsUI->spinBox_LV->value(),
settingsUI->spinBox_UH->value(),
settingsUI->spinBox_US->value(),
settingsUI->spinBox_UV->value());
if(!ClassifierPath.isEmpty()){
if(!detector->setClassifier(ClassifierPath))
qDebug() << "detector Classifier not set";
}
if(!ColorClassifierPath.isEmpty()){
if(!detector->setColorClassifier(ColorClassifierPath))
qDebug() << "detector Color Classifier not set";
}
detector->Capturing();
}
else if(StackWidgetIndex == TAB_STILLOBJECT){
if(!ClassifierPath.isEmpty())
if(!stillObject->setClassifier(ClassifierPath))
qDebug() << "stillObject classifier not set";
if(!ColorClassifierPath.isEmpty())
if(!stillObject->setColorClassifier(ColorClassifierPath))
qDebug() << "stillObject color classifier not set";
}
else if(StackWidgetIndex == TAB_XMLCREATOR){
if(settingsUI->lineEdit_XMLObjectName->text().isEmpty() ||
settingsUI->lineEdit_XMLObjectFolder->text().isEmpty() ||
settingsUI->lineEdit_XMLPositivePath->text().isEmpty()){
QMessageBox::information(this,"Wait","Missing information");
return false;
}
}
else
{
detector->Stop();
}
settingsUI->stackedWidget->setCurrentIndex(StackWidgetIndex);
return true;
}
void Recognizer::Initialization()
{
//create a progressbar next to the status bar
statProgress = new QProgressBar(this);
statProgress->setMaximumWidth(120);
settingsUI->statusBar->addPermanentWidget(statProgress);\
statProgress->setTextVisible(false);
//Initialize FaceRecognizer models
LBPHModel = createLBPHFaceRecognizer();
EigenFaceModel = createEigenFaceRecognizer();
FisherFaceModel = createFisherFaceRecognizer();
//Update GUI
on_LBPH_checkBox_clicked(false);
on_EigenFace_checkBox_clicked(false);
on_FisherFace_checkBox_clicked(false);
on_UpdateExisting_checkBox_clicked(false);
//For TrainingThread communication
connect(this,SIGNAL(TrainingObjects(QString)),this,SLOT(onTrainingObjects(QString)));
TabsInit();
// Camera Resolution
foreach(QSize a, RESOLUTION)
{
QString text = QString::number(a.width()) + " x " + QString::number(a.height());
settingsUI->comboBox_CameraResolution->addItem(text,QVariant(a));
}
foreach(QString s, ColorAlgorithmString)
settingsUI->comboBox_colorClassifierAlgorithm->addItem(s);
img_height = img_width = 0;
StackWidgetIndex = TAB_EMPTY;
}
//construct all other tabs
void Recognizer::TabsInit(){
//Camera
detector = new Detector(this);
settingsUI->stackedWidget->insertWidget(TAB_LIVEFACIAL,detector);
settingsUI->pushButton_setting->setVisible(false);
QPalette Pal;
Pal.setColor(QPalette::Background,Qt::black);
settingsUI->stackedWidget->widget(TAB_LIVEFACIAL)->setAutoFillBackground(true);
settingsUI->stackedWidget->setPalette(Pal);
//stillObject
stillObject = new StillObject(this);
settingsUI->stackedWidget->insertWidget(TAB_STILLOBJECT,stillObject);
//xml creator
xml_creator = new XML_creator(this);
settingsUI->stackedWidget->insertWidget(TAB_XMLCREATOR,xml_creator);
}
Mat Recognizer::norm_0_255(InputArray _src) {
Mat src = _src.getMat();
// Create and return normalized image:
Mat dst;
switch(src.channels()) {
case 1:
cv::normalize(_src, dst, 0, 255, NORM_MINMAX, CV_8UC1);
break;
case 3:
cv::normalize(_src, dst, 0, 255, NORM_MINMAX, CV_8UC3);
break;
default:
src.copyTo(dst);
break;
}
return dst;
}
//given the locations of files, put those in vector<Mat> and vector<int> for later training
void Recognizer::read_csv(const string& filename, vector<Mat>& images, vector<int>& labels, char separator) {
std::ifstream file(filename.c_str(), ifstream::in);
if (!file) {
string error_message = "No valid input file was given, please check the given filename.";
CV_Error(CV_StsBadArg, error_message);
}
string line, path, classlabel;
while (getline(file, line)) {
stringstream liness(line);
getline(liness, path, separator);
getline(liness, classlabel);
if(!path.empty() && !classlabel.empty()) {
images.push_back(imread(path, 0));
labels.push_back(atoi(classlabel.c_str()));
}
}
img_width = images[0].cols;
img_height = images[0].rows;
}
//For Other thread to train the model, prevents freezing GUI
void Recognizer::Training()
{
//For communicating the main thread. (update GUI)
emit Recognizer::TrainingObjects("Begin");
if(settingsUI->LBPH_checkBox->isChecked())
{
emit Recognizer::TrainingObjects("LBPH");
LBPHModel->train(images,labels);
}
if(settingsUI->EigenFace_checkBox->isChecked())
{
emit Recognizer::TrainingObjects("EigenFace");
EigenFaceModel->train(images, labels);
}
if(settingsUI->FisherFace_checkBox->isChecked())
{
emit Recognizer::TrainingObjects("FisherFace");
FisherFaceModel->train(images, labels);
}
emit Recognizer::TrainingObjects("End");
}
//save path (mostly) for next time
void Recognizer::SaveSettings()
{
QSettings settings("Settings.ini",QSettings::IniFormat);
settings.beginGroup("FileLocation");
settings.setValue("Target Path",Target_Path);
settings.setValue("CVS Path",CVS_Path);
settings.setValue("Classifier Path",ClassifierPath);
if(settingsUI->LBPH_checkBox->isChecked())
settings.setValue("LBPH Path",LBPHPath);
if(settingsUI->EigenFace_checkBox->isChecked())
settings.setValue("EigenFace Path",EigenFacePath);
if(settingsUI->EigenFace_checkBox->isChecked())
settings.setValue("FisherFace Path",FisherFacePath);
settings.endGroup();
}
//load path from last time
void Recognizer::LoadSettings()
{
QSettings settings("Settings.ini",QSettings::IniFormat);
settings.beginGroup("FileLocation");
settingsUI->Target_lineEdit->setText(settings.value("Target Path").toString());
settingsUI->CVS_Path_lineEdit->setText(settings.value("CVS Path").toString());
settingsUI->ClassifierLineEdit->setText(settings.value("Classifier Path").toString());
settingsUI->LBPH_lineEdit->setText(settings.value("LBPH Path").toString());
settingsUI->EigenFace_location_lineEdit->setText(settings.value("EigenFace Path").toString());
settingsUI->FisherFace_location_lineEdit->setText(settings.value("FisherFace Path").toString());
settings.endGroup();
}
//get CVS Path
void Recognizer::on_CVS_Path_Button_clicked()
{
QString tempPath;
tempPath = QFileDialog::getOpenFileName(this,"Select CVS File",CVS_Path,"Text Files (*.txt)");
if(QFileDialog::Accepted && !tempPath.isNull())
{
CVS_Path = tempPath;
settingsUI->CVS_Path_lineEdit->setText(CVS_Path);
}
}
void Recognizer::on_CVS_Path_lineEdit_textChanged(const QString &arg1)
{
CVS_Path = arg1;
}
//predict the person in given image from existing labels.
void Recognizer::on_Predict_Button_clicked()
{
SaveSettings();
try{
testSample = imread(Target_Path.toStdString(),0);
} catch (Exception e)
{
QMessageBox::critical(this,"ERROR","Check your path");
}
String result_message;
try{
if(settingsUI->LBPH_checkBox->isChecked())
{
int LBPHPredictedLabel = LBPHModel->predict(testSample);
result_message.append("LBPH Predicted Class = ");
result_message.append(QString::number(LBPHPredictedLabel).toStdString());
result_message.append("\t");
}
if(settingsUI->EigenFace_checkBox->isChecked())
{
int EigenFacePredictedLabel = EigenFaceModel->predict(testSample);
result_message.append("EigenFace Predicted Class = ");
result_message.append(QString::number(EigenFacePredictedLabel).toStdString());
result_message.append("\t");
}
if(settingsUI->FisherFace_checkBox->isChecked())
{
int FisherFacePredictedLabel = FisherFaceModel->predict(testSample);
result_message.append("FisherFace Predicted Class = ");
result_message.append(QString::number(FisherFacePredictedLabel).toStdString());
result_message.append("\t");
}
} catch (Exception e)
{
QMessageBox::critical(this,"ERROR","Did you train it yet?");
}
settingsUI->Predition_Result->setText(QString::fromStdString(result_message));
}
//start training by running another thread.
void Recognizer::on_Train_Button_clicked()
{
SaveSettings();
// Get the path to your CSV.
string fn_csv = CVS_Path.toStdString();
// These vectors hold the images and corresponding labels.
// Read in the data. This can fail if no valid
// input filename is given.
try {
read_csv(fn_csv, images, labels);
} catch (cv::Exception& e) {
cerr << "Error opening file \"" << fn_csv << "\". Reason: " << e.msg << endl;
// nothing more we can do
exit(1);
}
// Quit if there are not enough images for this demo.
if(images.size() <= 1) {
string error_message = "This demo needs at least 2 images to work. Please add more images to your data set!";
cout << error_message;
}
QFuture<void> t1 = QtConcurrent::run(this,&Recognizer::Training);
}
//For training thread use, to show the progress of training.
void Recognizer::onTrainingObjects(QString type)
{
if(type == "Begin")
{
statProgress->setValue(100);
}
else if(type == "LBPH")
settingsUI->statusBar->showMessage("Training LBPH..");
else if(type == "EigenFace")
settingsUI->statusBar->showMessage("Training EigenFace..");
else if(type == "FisherFace")
settingsUI->statusBar->showMessage("Training FisherFace..");
else
{
settingsUI->statusBar->showMessage("");
statProgress->setValue(0);
}
}
//TO create a cvs file
void Recognizer::on_CreateCVS_Button_clicked()
{
QString tempPath;
tempPath = QFileDialog::getExistingDirectory(this,"Picture Database Directory",CVS_Path,QFileDialog::ShowDirsOnly);
if(QFileDialog::Accepted && !tempPath.isNull())
{
QString cvspath;
cvspath = QFileDialog::getSaveFileName(this,"Ouput Location for CVS",tempPath,"Text Files(*.txt)");
if(QFileDialog::Accepted && !cvspath.isNull())
{
QFile file(cvspath);
file.open(QIODevice::WriteOnly | QIODevice::Text);
QTextStream output(&file);
QDirIterator Folders(tempPath,QDir::AllDirs | QDir::NoDot | QDir::NoDotDot);
int label = 1;
while(Folders.hasNext())
{
QDirIterator Files(Folders.next(),QDir::Files | QDir::NoDot | QDir::NoDotDot);
while(Files.hasNext())
{
output << Files.next() << ";" << label << "\n";
}
label++;
}
file.close();
settingsUI->statusBar->showMessage(QFileInfo(cvspath).fileName() + " Created Successfully",3000);
settingsUI->CVS_Path_lineEdit->setText(file.fileName());
}
}
}
void Recognizer::on_Target_lineEdit_textChanged(const QString &arg1)
{
Target_Path = arg1;
}
void Recognizer::on_Target_toolButton_clicked()
{
QString tempPath;
tempPath = QFileDialog::getOpenFileName(this,"Select Target Image",Target_Path,"Images (*.pgm)");
if(QFileDialog::Accepted && !tempPath.isNull())
{
Target_Path = tempPath;
settingsUI->Target_lineEdit->setText(Target_Path);
}
}
void Recognizer::on_LBPH_lineEdit_textChanged(const QString &arg1)
{
LBPHPath = arg1;
}
void Recognizer::on_EigenFace_location_lineEdit_textChanged(const QString &arg1)
{
EigenFacePath = arg1;
}
void Recognizer::on_FisherFace_location_lineEdit_textChanged(const QString &arg1)
{
FisherFacePath = arg1;
}
//for GUI, if the algorithm is not use, its components are not available for use.
void Recognizer::on_LBPH_checkBox_clicked(bool checked)
{
if(checked == true)
{
settingsUI->LBPH_lineEdit->setEnabled(true);
settingsUI->LBPH_toolButton->setEnabled(true);
settingsUI->groupBox_LBPHupdate->setVisible(true);
}else
{
settingsUI->LBPH_lineEdit->setEnabled(false);
settingsUI->LBPH_toolButton->setEnabled(false);
settingsUI->groupBox_LBPHupdate->setVisible(false);
}
AlgorithmChecked();
}
//for GUI, if the algorithm is not use, its components are not available for use.
void Recognizer::on_EigenFace_checkBox_clicked(bool checked)
{
if(checked == true)
{
settingsUI->EigenFace_location_lineEdit->setEnabled(true);
settingsUI->EigenFace_location_toolButton->setEnabled(true);
}else
{
settingsUI->EigenFace_location_lineEdit->setEnabled(false);
settingsUI->EigenFace_location_toolButton->setEnabled(false);
}
AlgorithmChecked();
}
//for GUI, if the algorithm is not use, its components are not available for use.
void Recognizer::on_FisherFace_checkBox_clicked(bool checked)
{
if(checked == true)
{
settingsUI->FisherFace_location_lineEdit->setEnabled(true);
settingsUI->FisherFace_location_toolButton->setEnabled(true);
}else
{
settingsUI->FisherFace_location_lineEdit->setEnabled(false);
settingsUI->FisherFace_location_toolButton->setEnabled(false);
}
AlgorithmChecked();
}
//for GUI, if the algorithms are not use, their components are not available for use.
void Recognizer::AlgorithmChecked()
{
if(settingsUI->LBPH_checkBox->isChecked() || settingsUI->EigenFace_checkBox->isChecked() || settingsUI->FisherFace_checkBox->isChecked())
{
settingsUI->Train_Button->setEnabled(true);
settingsUI->Predict_Button->setEnabled(true);
settingsUI->SaveTrainedModel_pushButton->setEnabled(true);
settingsUI->LoadTrainedModel_pushButton->setEnabled(true);
}else{
settingsUI->Train_Button->setEnabled(false);
settingsUI->Predict_Button->setEnabled(false);
settingsUI->SaveTrainedModel_pushButton->setEnabled(false);
settingsUI->LoadTrainedModel_pushButton->setEnabled(false);
}
}
//For loading/saving model
void Recognizer::on_LBPH_toolButton_clicked()
{
QString tempPath;
tempPath = QFileDialog::getSaveFileName(this,"Save or Select LBPH File",LBPHPath,"XML (*.xml);;YAML (*.YAML)");
if(QFileDialog::Accepted && !tempPath.isNull())
{
LBPHPath = tempPath;
settingsUI->LBPH_lineEdit->setText(tempPath);
}
}
//For loading/saving model
void Recognizer::on_EigenFace_location_toolButton_clicked()
{
QString tempPath;
tempPath = QFileDialog::getSaveFileName(this,"Save or Select EigenFace File",EigenFacePath,"XML (*.xml);;YAML (*.YAML)");
if(QFileDialog::Accepted && !tempPath.isNull())
{
EigenFacePath = tempPath;
settingsUI->EigenFace_location_lineEdit->setText(tempPath);
}
}
//For loading/saving model
void Recognizer::on_FisherFace_location_toolButton_clicked()
{
QString tempPath;
tempPath = QFileDialog::getSaveFileName(this,"Save or Select FisherFace File",FisherFacePath,"XML (*.xml);;YAML (*.YAML)");
if(QFileDialog::Accepted && !tempPath.isNull())
{
FisherFacePath = tempPath;
settingsUI->FisherFace_location_lineEdit->setText(tempPath);
}
}
//For loading/saving model
void Recognizer::on_SaveTrainedModel_pushButton_clicked()
{
settingsUI->statusBar->showMessage("Saving models..");
statProgress->setValue(100);
if(settingsUI->LBPH_checkBox->isChecked())
LBPHModel->save(LBPHPath.toStdString());
if(settingsUI->EigenFace_checkBox->isChecked())
EigenFaceModel->save(EigenFacePath.toStdString());
if(settingsUI->FisherFace_checkBox->isChecked())
FisherFaceModel->save(FisherFacePath.toStdString());
settingsUI->statusBar->showMessage("");
statProgress->setValue(0);
}
//For loading/saving model
void Recognizer::on_LoadTrainedModel_pushButton_clicked()
{
settingsUI->statusBar->showMessage("Loading models..");
statProgress->setValue(100);
try{
if(settingsUI->LBPH_checkBox->isChecked())
LBPHModel->load(LBPHPath.toStdString());
if(settingsUI->EigenFace_checkBox->isChecked())
EigenFaceModel->load(EigenFacePath.toStdString());
if(settingsUI->FisherFace_checkBox->isChecked())
FisherFaceModel->load(FisherFacePath.toStdString());
} catch (Exception e)
{
QMessageBox::critical(this,"ERROR","Invalid Path");
}
settingsUI->statusBar->showMessage("");
statProgress->setValue(0);
}
//for Updating LBPH
void Recognizer::on_UpdateExisting_checkBox_clicked(bool checked)
{
if(checked == true)
{
settingsUI->UpdateExisting_spinBox->setEnabled(true);
settingsUI->UpdateLocation_lineEdit->setEnabled(true);
settingsUI->UpdateLocation_toolButton->setEnabled(true);
settingsUI->TrainNew_pushButton->setEnabled(true);
}else{
settingsUI->UpdateExisting_spinBox->setEnabled(false);
settingsUI->UpdateLocation_lineEdit->setEnabled(false);
settingsUI->UpdateLocation_toolButton->setEnabled(false);
settingsUI->TrainNew_pushButton->setEnabled(false);
}
}
//for Updating LBPH
void Recognizer::on_UpdateLocation_lineEdit_textChanged(const QString &arg1)
{
UpdateExistingDirectory = arg1;
}
//for Updating LBPH
void Recognizer::on_UpdateLocation_toolButton_clicked()
{
QString tempPath;
tempPath = QFileDialog::getExistingDirectory(this,"Updating Directory",UpdateExistingDirectory,QFileDialog::ShowDirsOnly);
if(QFileDialog::Accepted && !tempPath.isNull())
{
UpdateExistingDirectory = tempPath;
settingsUI->UpdateLocation_lineEdit->setText(UpdateExistingDirectory);
}
}
//for Updating LBPH
void Recognizer::on_TrainNew_pushButton_clicked()
{
QString cvspath = QDir::currentPath() + "/updating.txt";
QFile file(cvspath);
file.open(QIODevice::WriteOnly | QIODevice::Text);
QTextStream output(&file);
QDirIterator Files(UpdateExistingDirectory,QDir::Files | QDir::NoDot | QDir::NoDotDot);
int label = settingsUI->UpdateExisting_spinBox->value();
while(Files.hasNext())
{
output << Files.next() << ";" << label << "\n";
}
file.close();
try{
string fn_csv = cvspath.toStdString();
if(fn_csv != "")
{
vector<Mat> updatingImages;
vector<int> updatingLabels;
try {
read_csv(fn_csv, updatingImages, updatingLabels);
} catch (cv::Exception& e) {
cerr << "Error opening file \"" << fn_csv << "\". Reason: " << e.msg << endl;
// nothing more we can do
exit(1);
}
LBPHModel->update(updatingImages,updatingLabels);
}
} catch(Exception e)
{
QMessageBox::critical(this,"ERROR","Check your location");
}
}
void Recognizer::on_ClassifierLineEdit_textChanged(const QString &arg1)
{
ClassifierPath = arg1;
}
void Recognizer::on_ClassifierPath_toolButton_clicked()
{
QString tempPath;
tempPath = QFileDialog::getOpenFileName(this,"Select Classifier XML Files",ClassifierPath,"XML Files (*.xml)");
if(QFileDialog::Accepted && !tempPath.isNull())
{
ClassifierPath = tempPath;
settingsUI->ClassifierLineEdit->setText(ClassifierPath);
}
}
void Recognizer::on_lineEdit_colorClassifier_textChanged(const QString &arg1)
{
if(arg1.isNull() || arg1.isEmpty())
return;
ColorClassifierPath = arg1;
}
void Recognizer::on_toolButton_colorClassifier_clicked()
{
QString tempPath;
tempPath = QFileDialog::getOpenFileName(this,"Select Color Classifier XML Files",ColorClassifierPath,"XML Files (*.xml)");
if(QFileDialog::Accepted && !tempPath.isNull())
{
ColorClassifierPath = tempPath;
settingsUI->lineEdit_colorClassifier->setText(ColorClassifierPath);
}
}
void Recognizer::on_pushButton_liveFacial_clicked()
{
onOpSel();
}
void Recognizer::on_pushButton_stillFacial_clicked()
{
onOpSel();
}
void Recognizer::on_pushButton_stillObject_clicked()
{
onOpSel();
}
//the blue right arrow on the bottom
void Recognizer::on_pushButton_action_clicked()
{
if(passParaToOp()){
settingsUI->pushButton_action->setVisible(false);
settingsUI->pushButton_setting->setVisible(true);
}
}
//the blue left arrow on the bottom, which always back to setting when clicked
void Recognizer::on_pushButton_setting_clicked()
{
StackWidgetIndex = TAB_EMPTY;
if(passParaToOp()){
settingsUI->pushButton_action->setVisible(true);
settingsUI->pushButton_setting->setVisible(false);
}
onOpSel();
}
void Recognizer::on_pushButton_XMLcreator_clicked()
{
onOpSel();
}
void Recognizer::on_toolButton_XMLPositive_clicked()
{
QString filename;
filename = QFileDialog::getExistingDirectory(this,"Positive images folder");
if(filename.isNull() || filename.isEmpty() || QFileDialog::Rejected)
return;
settingsUI->lineEdit_XMLPositivePath->setText(filename);
xml_creator->SetPositivePath(filename);
}
void Recognizer::on_toolButton_XMLNegative_clicked()
{
QString filename;
filename = QFileDialog::getExistingDirectory(this,"Negative images folder");
if(filename.isNull() || filename.isEmpty() || QFileDialog::Rejected)
return;
settingsUI->lineEdit_XMLNegativePath->setText(filename);
xml_creator->SetNegativePath(filename);
}
void Recognizer::on_lineEdit_XMLObjectName_textChanged(const QString &arg1)
{
xml_creator->setObjectName(arg1);
}
void Recognizer::on_toolButton_XMLObjectFolder_clicked()
{
QString tempPath;
tempPath = QFileDialog::getExistingDirectory
(this,"Root folder","",QFileDialog::ShowDirsOnly);
if(QFileDialog::Rejected || tempPath.isNull() || tempPath.isEmpty())
return;
QString ObjectName = settingsUI->lineEdit_XMLObjectName->text();
if(ObjectName.isEmpty()){
QMessageBox::information(this,"Missing Object name", "Please put your object's name first");
return;
}
QString ObjectPath = tempPath + "/" + ObjectName;
QDir ObjectFolder(ObjectPath + "/");
xml_creator->SetObjectPath(ObjectFolder);
settingsUI->lineEdit_XMLObjectFolder->setText(ObjectPath);
}
void Recognizer::on_comboBox_colorClassifierAlgorithm_currentIndexChanged(int index)
{
if(index == ColorAlgorithm::NOTUSE){
settingsUI->groupBox_colorClassifier->setVisible(false);
return;
} else if (index == ColorAlgorithm::CLASS1_COLORPERCENTAGE){
settingsUI->label_colorPercentage->setVisible(true);
settingsUI->spinBox_colorPercentage->setVisible(true);
settingsUI->label_colorClassifier->setVisible(false);
settingsUI->lineEdit_colorClassifier->setVisible(false);
settingsUI->toolButton_colorClassifier->setVisible(false);
} else {
settingsUI->label_colorPercentage->setVisible(false);
settingsUI->spinBox_colorPercentage->setVisible(false);
settingsUI->label_colorClassifier->setVisible(true);
settingsUI->lineEdit_colorClassifier->setVisible(true);
settingsUI->toolButton_colorClassifier->setVisible(true);
}
settingsUI->groupBox_colorClassifier->setVisible(true);
ColorAlgorithm c;
switch(index){
case 1: c = CLASS2_ENTIRE;
break;
case 2: c = CLASS2_RECTONLY;
break;
case 3: c = CLASS1_COLORPERCENTAGE;
break;
default: c = NOTUSE;
}
detector->setColorAlgorithm(c);
}
void Recognizer::on_spinBox_colorPercentage_valueChanged(int arg1)
{
detector->setColorPercentage(arg1);
}