00001 #include "mainFrame.h"
00002
00003 Tracking MainFrame::track;
00004
00005 MainFrame::MainFrame(QWidget *parent, Qt::WFlags flags)
00006 : QMainWindow(parent, flags) {
00007 ui.setupUi(this);
00008 sSeparator="----------------------------------------------------------------";
00010
00011 connect(ui.actionOpenDirectory, SIGNAL(triggered()), this, SLOT(openDir()));
00013
00014 connect(ui.actionLaplace_4, SIGNAL(triggered()), this, SLOT(loadPreLaplace4()));
00015 connect(ui.actionLaplace_8, SIGNAL(triggered()), this, SLOT(loadPreLaplace8()));
00016 connect(ui.actionSobel_X, SIGNAL(triggered()), this, SLOT(loadPreSobelX()));
00017 connect(ui.actionSobel_Min, SIGNAL(triggered()), this, SLOT(loadPreSobelMin()));
00018 connect(ui.actionGaussian_LoG, SIGNAL(triggered()), this, SLOT(loadPreGaussianLoG()));
00019 connect(ui.actionLoG, SIGNAL(triggered()), this, SLOT(loadPreLoG()));
00020 connect(ui.actionThreshold, SIGNAL(triggered()), this, SLOT(loadPreThres()));
00021 connect(ui.actionCanny, SIGNAL(triggered()), this, SLOT(loadPreCanny()));
00022 connect(ui.actionInitPre, SIGNAL(triggered()), this, SLOT(initPre()));
00023
00024 connect(ui.actionContourThres, SIGNAL(triggered()), this, SLOT(loadSegContourThres()));
00025 connect(ui.actionContourSnake, SIGNAL(triggered()), this, SLOT(loadSegContourSnake()));
00026 connect(ui.actionHoughStdCanny, SIGNAL(triggered()), this, SLOT(loadSegHoughStdCanny()));
00027 connect(ui.actionHoughProCanny, SIGNAL(triggered()), this, SLOT(loadSegHoughProCanny()));
00028 connect(ui.actionScaleSpace, SIGNAL(triggered()), this, SLOT(loadSegScaleSpace()));
00029 connect(ui.actionScaleSpaceThres, SIGNAL(triggered()), this, SLOT(loadSegScaleSpaceThres()));
00030 connect(ui.actionBlobsThres, SIGNAL(triggered()), this, SLOT(loadSegBlobsThres()));
00031 connect(ui.actionBlobsCanny, SIGNAL(triggered()), this, SLOT(loadSegBlobsCanny()));
00032 connect(ui.actionInitSeg, SIGNAL(triggered()), this, SLOT(initSeg()));
00033
00034
00035 connect(ui.actionMatrix, SIGNAL(triggered()), this, SLOT(openDialogMatrix()));
00036
00037 connect(ui.action_About, SIGNAL(triggered()), this, SLOT(showAbout()));
00038
00040
00041 connect(ui.loadImageSeq, SIGNAL(clicked()), this, SLOT(loadImageSeq()));
00042 connect(ui.showSeq, SIGNAL(clicked()), this, SLOT(loadAutoSeq()));
00043 connect(ui.showStepByStep, SIGNAL(clicked()), this, SLOT(loadStepSeq()));
00044 connect(ui.showBackStep, SIGNAL(clicked()), this, SLOT(loadBackSeq()));
00045 connect(ui.showNextStep, SIGNAL(clicked()), this, SLOT(loadNextSeq()));
00046
00047 connect(ui.checkContour, SIGNAL(toggled(bool)), this, SLOT(changeContourCheck(bool)));
00048 connect(ui.checkContourRect, SIGNAL(toggled(bool)), this, SLOT(changeContourCheck(bool)));
00049
00050 connect(ui.comboHough, SIGNAL(currentIndexChanged(int)), this, SLOT(changeHoughParam(int)));
00051
00052 connect(ui.checkBlobslib, SIGNAL(toggled(bool)), this, SLOT(changeBlobToTrack(bool)));
00053 connect(ui.checkBlobTrack, SIGNAL(toggled(bool)), this, SLOT(changeBlobKalmanOpts(bool)));
00054
00055 connect(ui.butKalmanSel, SIGNAL(clicked()), this, SLOT(addKalmanPrediction()));
00056 connect(ui.butKalmanUpd, SIGNAL(clicked()), this, SLOT(updateKalmanPrediction()));
00057 connect(ui.butKalmanClean, SIGNAL(clicked()), this, SLOT(clearKalman()));
00058 connect(ui.butKalmanBlobSel, SIGNAL(clicked()), this, SLOT(addKalmanBlobPrediction()));
00059 connect(ui.butKalmanBlobUpd, SIGNAL(clicked()), this, SLOT(updateKalmanBlobPrediction()));
00060 connect(ui.butKalmanBlobClean, SIGNAL(clicked()), this, SLOT(clearBlobKalman()));
00061
00062
00063 closeCvWindow=0;
00064
00065 qPathLoaded="";
00066
00067 initFilterMatrix();
00068 }
00069
00070 void MainFrame::showAbout() {
00071 QMessageBox msgBox;
00072 msgBox.setText("Release 0.3.\nDeveloped by: Fernando Aparicio Galisteo\nhttp://artificialvis.sourceforge.net");
00073 msgBox.exec();
00074 }
00075
00076 void MainFrame::closeEvent(QCloseEvent *event) {
00077 dlgMat.close();
00078 cvDestroyAllWindows();
00079 exit(0);
00080 }
00081
00082 void MainFrame::openDir() {
00083 QString dirName = QFileDialog::getExistingDirectory(this);
00084 if (!dirName.isEmpty())
00085 ui.lePathSeq->setText(dirName);
00086 }
00087
00088
00089 void MainFrame::initFilterMatrix() {
00090 filterData[0]=1;filterData[1]=0;filterData[2]=0;
00091 filterData[3]=0;filterData[4]=1;filterData[5]=0;
00092 filterData[6]=0;filterData[7]=0;filterData[8]=1;
00093 }
00094
00095 void MainFrame::initPre(){
00096 initFilterMatrix();
00097 ui.checkNoise1->setChecked(false); ui.checkNoise2->setChecked(false);
00098 ui.checkNoise3->setChecked(false); ui.checkSobelx->setChecked(false);
00099 ui.checkSobely->setChecked(false); ui.checkLaplace->setChecked(false);
00100 ui.checkMatrix->setChecked(false); ui.checkLoG->setChecked(false);
00101 ui.checkThreshold->setChecked(false); ui.checkCanny->setChecked(false);
00102 ui.comboKernelNoise->setCurrentIndex(0);
00103 ui.leSigmaNoise->setText("0");
00104 }
00105
00106 void MainFrame::initSeg(){
00107 ui.checkContour->setChecked(false); ui.leDivSnakeContour->setText("5");
00108 ui.comboHough->setCurrentIndex(0); ui.leThresHough->setText("70");
00109 ui.leRhoHough->setText("1"); ui.leThetaHough->setText("1");
00110 ui.leMinLineHough->setText("30"); ui.leGapHough->setText("10");
00111 ui.leRadialResHough->setText("30"); ui.leAngleResHough->setText("30");
00112 ui.checkScale->setChecked(false); ui.comboSizeScale->setCurrentIndex(9);
00113 ui.leThres1Scale->setText("30"); ui.leThres2Scale->setText("50");
00114 ui.leThres3Scale->setText("100"); ui.leNonmaxScale->setText("4");
00115 ui.checkBlobslib->setChecked(false);
00116 ui.leBlobsMinArea->setText("20"); ui.leBlobsMaxArea->setText("2000");
00117 ui.leBlobsMinRough->setText("0.9"); ui.leBlobsMaxRough->setText("1.2");
00118 }
00119
00120 void MainFrame::loadPreLaplace4() {
00121 initPre();
00122 ui.checkNoise1->setChecked(true);
00123 ui.checkNoise2->setChecked(true);
00124 ui.checkNoise3->setChecked(true);
00125 filterData[0]=0;filterData[1]=1;filterData[2]=0;
00126 filterData[3]=1;filterData[4]=-4;filterData[5]=1;
00127 filterData[6]=0;filterData[7]=1;filterData[8]=0;
00128 ui.checkMatrix->setChecked(true);
00129 ui.checkThreshold->setChecked(true);
00130 ui.leThreshold->setText("10");
00131 }
00132
00133 void MainFrame::loadPreLaplace8() {
00134 initPre();
00135 ui.checkNoise1->setChecked(true);
00136 ui.checkNoise2->setChecked(true);
00137 ui.checkNoise3->setChecked(true);
00138 filterData[0]=1;filterData[1]=1;filterData[2]=1;
00139 filterData[3]=1;filterData[4]=-8;filterData[5]=1;
00140 filterData[6]=1;filterData[7]=1;filterData[8]=1;
00141 ui.checkMatrix->setChecked(true);
00142 ui.leThreshold->setText("20");
00143 ui.checkThreshold->setChecked(true);
00144 }
00145
00146 void MainFrame::loadPreSobelX() {
00147 initPre();
00148 ui.checkNoise1->setChecked(true);
00149 ui.checkNoise2->setChecked(true);
00150 ui.checkNoise3->setChecked(true);
00151 ui.checkSobelx->setChecked(true);
00152 ui.checkThreshold->setChecked(true);
00153 ui.leThreshold->setText("40");
00154 }
00155
00156 void MainFrame::loadPreSobelMin() {
00157 initPre();
00158 ui.checkNoise1->setChecked(true);
00159 ui.checkNoise2->setChecked(true);
00160 ui.checkNoise3->setChecked(true);
00161 ui.checkSobelx->setChecked(true);
00162 ui.checkSobely->setChecked(true);
00163 ui.checkThreshold->setChecked(true);
00164 ui.leThreshold->setText("30");
00165 }
00166
00167 void MainFrame::loadPreGaussianLoG() {
00168 initPre();
00169 ui.checkNoise1->setChecked(true);
00170 ui.checkNoise2->setChecked(true);
00171 ui.checkNoise3->setChecked(true);
00172 ui.checkLoG->setChecked(true);
00173 ui.checkThreshold->setChecked(true);
00174 ui.leThreshold->setText("35");
00175 }
00176
00177 void MainFrame::loadPreLoG() {
00178 initPre();
00179 ui.checkNoise1->setChecked(true);
00180 ui.checkNoise2->setChecked(true);
00181 ui.checkLoG->setChecked(true);
00182 ui.checkThreshold->setChecked(true);
00183 ui.leThreshold->setText("60");
00184 }
00185
00186 void MainFrame::loadPreThres() {
00187 initPre();
00188 ui.checkNoise1->setChecked(true);
00189 ui.checkNoise2->setChecked(true);
00190 ui.checkNoise3->setChecked(true);
00191 ui.checkThreshold->setChecked(true);
00192 ui.leThreshold->setText("220");
00193 }
00194
00195 void MainFrame::loadPreCanny() {
00196 initPre();
00197 ui.checkNoise3->setChecked(true);
00198 ui.checkCanny->setChecked(true);
00199 ui.leThreshold1->setText("150");
00200 ui.leThreshold2->setText("250");
00201 }
00202
00203 void MainFrame::loadSegContourThres(){
00204 initSeg();
00205 loadPreThres();
00206 ui.checkContour->setChecked(true);
00207 }
00208
00209 void MainFrame::loadSegContourSnake(){
00210 initSeg();
00211 loadPreThres();
00212 ui.checkContour->setChecked(true);
00213 ui.checkContourRect->setChecked(true);
00214 ui.checkContourSnake->setChecked(true);
00215 ui.leDivSnakeContour->setText("5");
00216 }
00217
00218 void MainFrame::loadSegHoughStdCanny(){
00219 initSeg();
00220 loadPreCanny();
00221 ui.comboHough->setCurrentIndex(1);
00222 }
00223
00224 void MainFrame::loadSegHoughProCanny(){
00225 initSeg();
00226 loadPreCanny();
00227 ui.comboHough->setCurrentIndex(2);
00228 ui.leThresHough->setText("50");
00229 ui.leMinLineHough->setText("20");
00230 ui.leGapHough->setText("50");
00231 }
00232
00233 void MainFrame::loadSegScaleSpace(){
00234 initSeg();
00235 initPre();
00236 ui.checkScale->setChecked(true);
00237 ui.comboSizeScale->setCurrentIndex(1);
00238 ui.leThres1Scale->setText("20"); ui.leThres2Scale->setText("100");
00239 ui.leThres3Scale->setText("100"); ui.leNonmaxScale->setText("2");
00240 }
00241
00242 void MainFrame::loadSegScaleSpaceThres(){
00243 initSeg();
00244 loadPreThres();
00245 ui.checkScale->setChecked(true);
00246 ui.comboSizeScale->setCurrentIndex(8);
00247 ui.leThres1Scale->setText("100"); ui.leThres2Scale->setText("200");
00248 ui.leThres3Scale->setText("50"); ui.leNonmaxScale->setText("2");
00249 }
00250
00251 void MainFrame::loadSegBlobsThres(){
00252 initSeg();
00253 loadPreThres();
00254 ui.checkBlobslib->setChecked(true);
00255 }
00256
00257 void MainFrame::loadSegBlobsCanny(){
00258 initSeg();
00259 loadPreCanny();
00260 ui.checkBlobslib->setChecked(true);
00261 ui.leBlobsMinArea->setText("10"); ui.leBlobsMaxArea->setText("2000");
00262 ui.leBlobsMinRough->setText("0.9"); ui.leBlobsMaxRough->setText("3");
00263 }
00264
00265 void MainFrame::openDialogMatrix() {
00266
00267 for (int i=0;i<9;i++)
00268 dlgMat.cdata[i]=filterData[i];
00269 dlgMat.initArray();
00270
00271 dlgMat.show();
00272 dlgMat.exec();
00273
00274 getDlgMatrixValues();
00275 }
00276
00277 void MainFrame::getDlgMatrixValues(){
00278 for (int i=0; i<9;i++){
00279 filterData[i]=dlgMat.cdata[i];
00280 }
00281 }
00282
00283 void MainFrame::changeContourCheck(bool bCheckContour){
00284 if (!bCheckContour){
00285 ui.checkContourRect->setChecked(false);
00286 ui.checkContourSnake->setChecked(false);
00287 }
00288 }
00289
00290 void MainFrame::changeHoughParam(int index){
00291
00292 if (index<2){
00293 ui.leMinLineHough->setEnabled(false);
00294 ui.leRadialResHough->setEnabled(false);
00295 ui.leGapHough->setEnabled(false);
00296 ui.leAngleResHough->setEnabled(false);
00297 }else if(index==2){
00298 ui.leMinLineHough->setEnabled(true);
00299 ui.leRadialResHough->setEnabled(false);
00300 ui.leGapHough->setEnabled(true);
00301 ui.leAngleResHough->setEnabled(false);
00302 }else if(index==3){
00303 ui.leMinLineHough->setEnabled(false);
00304 ui.leRadialResHough->setEnabled(true);
00305 ui.leGapHough->setEnabled(false);
00306 ui.leAngleResHough->setEnabled(true);
00307 }
00308 }
00309
00310 void MainFrame::changeBlobToTrack(bool bCheck){
00311 if (!bCheck)
00312 ui.checkBlobTrack->setChecked(false);
00313 }
00314
00315 void MainFrame::changeBlobKalmanOpts(bool bCheck){
00316 ui.comboBlobs->clear();
00317
00318 clearBlobKalman();
00319 ui.butKalmanSel->setEnabled(!bCheck);
00320 ui.butKalmanBlobSel->setEnabled(bCheck);
00321 ui.comboBlobs->setEnabled(bCheck);
00322 }
00323
00324 IplImage* MainFrame::paintCutImage(IplImage* src) {
00325 IplImage* dst;
00326 if (cvGetElemType(src)==0){
00327 dst = cvCreateImage(cvGetSize(src), 8, 3 );
00328 cvCvtColor( src, dst, CV_GRAY2BGR );
00329 } else
00330 dst=cvCloneImage(src);
00331 int wOrig=cvGetSize(src).width;
00332 int hOrig=cvGetSize(src).height;
00333 int w=wOrig;
00334 int h=hOrig;
00335 int lineHeight=3;
00336 if (ui.comboCutImage->currentIndex()==1){
00337 h=(hOrig/2);
00338 cvLine(dst, cvPoint(0,h),cvPoint(w,h), CV_RGB(0,255,0),lineHeight);
00339 }else if(ui.comboCutImage->currentIndex()==2){
00340 h=(hOrig/3);
00341 cvLine(dst, cvPoint(0,h),cvPoint(w,h), CV_RGB(0,255,0),lineHeight);
00342 }
00343 if (ui.checkROI->isChecked())
00344 cvSetImageROI(dst, cvRect(0,h+lineHeight,w,hOrig-h));
00345
00346 cvReleaseImage(&src);
00347 return dst;
00348 }
00349
00350 void MainFrame::addKalmanPrediction(){
00351 cvSetMouseCallback("image",onMouseSelect,&ui);
00352 }
00353 void MainFrame::addKalmanBlobPrediction(){
00354 if (ui.comboBlobs->count()>0) {
00355 blobBegin=filterBlobs.GetBlob(ui.comboBlobs->currentIndex());
00356 track.addKalmanPrediction(blobBegin);
00357
00358
00359 CvPoint blobCenter=track.getKalmanPoints().back();
00360 ui.comboKalmanBlobSelected->addItem(QString("(%1,%2)").arg(blobCenter.x).arg(blobCenter.y));
00361
00362
00363 ui.butKalmanBlobUpd->setEnabled(true);
00364 ui.comboKalmanBlobSelected->setEnabled(true);
00365 ui.butKalmanBlobClean->setEnabled(true);
00366
00367 ui.checkKalmanAlignX->setEnabled(true);
00368 ui.checkKalmanAlignY->setEnabled(true);
00369 ui.checkKalmanPaint->setEnabled(true);
00370 ui.comboKalmanPaint->setEnabled(true);
00371 }
00372 }
00373
00374 void MainFrame::onMouseSelect(int event, int x, int y, int flags, void* param) {
00375 if( event == CV_EVENT_LBUTTONUP ) {
00376 Ui::mainFrameClass *uinow=(Ui::mainFrameClass*)param;
00377 uinow->comboKalmanSelected->addItem(QString("(%1,%2)").arg(x).arg(y));
00378 MainFrame::track.addKalmanPrediction((float)x,(float)y);
00379 if (uinow->comboLog->currentIndex()>0)
00380 uinow->txInform->append(QString("Added point (%1,%2) to kalman prediction").arg(x).arg(y));
00381
00382
00383 uinow->butKalmanUpd->setEnabled(true);
00384 uinow->comboKalmanSelected->setEnabled(true);
00385 uinow->butKalmanClean->setEnabled(true);
00386 uinow->checkKalmanAlignX->setEnabled(true);
00387 uinow->checkKalmanAlignY->setEnabled(true);
00388 uinow->checkKalmanPaint->setEnabled(true);
00389 uinow->comboKalmanPaint->setEnabled(true);
00390 cvSetMouseCallback("image",NULL,0);
00391 }
00392 }
00393
00394 void MainFrame::updateKalmanPrediction(){
00395 cvSetMouseCallback("image",onMouseUpdate,&ui);
00396 }
00397
00398 void MainFrame::updateKalmanBlobPrediction(){
00399 CBlob blobUpdate=filterBlobs.GetBlob(ui.comboBlobs->currentIndex());
00400 track.updateKalmanPrediction(blobUpdate,ui.comboKalmanBlobSelected->currentIndex());
00401 CvPoint pointUpdated=track.getLastPointUpdate()[ui.comboKalmanBlobSelected->currentIndex()];
00402 ui.leKalmanBlobUpdate->setText(QString("(%1,%2)").arg(pointUpdated.x).arg(pointUpdated.y));
00403 }
00404
00405 void MainFrame::onMouseUpdate(int event, int x, int y, int flags, void* param) {
00406 if( event == CV_EVENT_LBUTTONUP ) {
00407 Ui::mainFrameClass *uinow=(Ui::mainFrameClass*)param;
00408 try{
00409 int iPointToUpdate=uinow->comboKalmanSelected->currentIndex();
00410 float iXUpd=(float)x;
00411 float iYUpd=(float)y;
00412
00413 std::vector<CvPoint> ptUpd=MainFrame::track.getKalmanPoints();
00414 if (uinow->checkKalmanAlignX->isChecked()){
00415 iXUpd=ptUpd[iPointToUpdate].x;
00416 if (uinow->comboLog->currentIndex()>0)
00417 uinow->txInform->append(QString(" Standing original x: %1").arg(iXUpd));
00418 }
00419 else if (uinow->checkKalmanAlignY->isChecked()){
00420 iYUpd=ptUpd[iPointToUpdate].y;
00421 if (uinow->comboLog->currentIndex()>0)
00422 uinow->txInform->append(QString(" Standing original y: %1").arg(iYUpd));
00423 }
00424 MainFrame::track.updateKalmanPrediction((float)iXUpd,(float)iYUpd,iPointToUpdate);
00425
00426 uinow->leKalmanUpdate->setText(QString("(%1,%2)").arg(iXUpd).arg(iYUpd));
00427 if (uinow->comboLog->currentIndex()>0)
00428 uinow->txInform->append(QString(" Point (%1,%2) updated to (%3,%4)")
00429 .arg(ptUpd[iPointToUpdate].x).arg(ptUpd[iPointToUpdate].y).arg(iXUpd).arg(iYUpd));
00430 }catch(std::bad_alloc&) {
00431 uinow->txInform->append("Memory Exception updating kalman vector");
00432 }catch(...){
00433 uinow->txInform->append("Other Exception updating kalman vector");
00434 }
00435
00436
00437
00438 }
00439 }
00440
00441 void MainFrame::clearKalman(){
00442 track.clearKalman();
00443
00444 ui.comboKalmanSelected->clear();
00445 ui.leKalmanUpdate->clear();
00446
00447 ui.butKalmanSel->setEnabled(true);
00448 ui.butKalmanUpd->setEnabled(false);
00449 ui.comboKalmanSelected->setEnabled(false);
00450 ui.butKalmanClean->setEnabled(false);
00451
00452 clearCommonKalman();
00453
00454 cvSetMouseCallback("image",NULL,0);
00455 }
00456
00457 void MainFrame::clearBlobKalman(){
00458 track.clearKalman();
00459
00460 ui.comboKalmanBlobSelected->clear();
00461 ui.leKalmanBlobUpdate->clear();
00462
00463 ui.checkKalmanAlignX->setChecked(false);
00464 ui.checkKalmanAlignY->setChecked(false);
00465 ui.checkKalmanPaint->setChecked(false);
00466
00467 ui.butKalmanBlobSel->setEnabled(true);
00468 ui.butKalmanBlobUpd->setEnabled(false);
00469 ui.comboKalmanBlobSelected->setEnabled(false);
00470 ui.butKalmanBlobClean->setEnabled(false);
00471
00472 clearCommonKalman();
00473 }
00474
00475 void MainFrame::clearCommonKalman(){
00476 ui.checkKalmanAlignX->setEnabled(false);
00477 ui.checkKalmanAlignX->setChecked(false);
00478 ui.checkKalmanAlignY->setEnabled(false);
00479 ui.checkKalmanAlignY->setChecked(false);
00480 ui.checkKalmanPaint->setEnabled(false);
00481 ui.checkKalmanPaint->setChecked(false);
00482 ui.comboKalmanPaint->setEnabled(false);
00483 ui.comboKalmanPaint->setCurrentIndex(0);
00484 }
00485
00486 void MainFrame::loadStepImage(int imageListCount){
00487 if (ui.comboLog->currentIndex()>0){
00488 ui.txInform->append(sSeparator);
00489 ui.txInform->append(QString("Treating Image: %1 ...").arg(fileList.at(imageListCount)));
00490 ui.txInform->repaint();
00491 }
00492 QDir dirSeq(qPathLoaded);
00493 ui.leBaseSeq->setText(fileList.at(imageListCount));
00494 IplImage* src_image;
00495 src_image = cvLoadImage(dirSeq.filePath(fileList.at(imageListCount)).toAscii().constData(), CV_LOAD_IMAGE_ANYCOLOR );
00497
00498 if (ui.comboCutImage->currentIndex()>0)
00499 src_image=paintCutImage(src_image);
00500
00502 Preprocess pre(ui);
00503 try {
00504
00505
00506 if (ui.checkNoise1->isChecked())
00507 src_image=pre.applyNoise(getGrayImage(src_image), CV_BLUR);
00508 if (ui.checkNoise2->isChecked())
00509 src_image=pre.applyNoise(getGrayImage(src_image), CV_MEDIAN);
00510 if (ui.checkNoise3->isChecked())
00511 src_image=pre.applyNoise(getGrayImage(src_image), CV_GAUSSIAN);
00512
00513 if (ui.checkSobelx->isChecked() && !ui.checkSobely->isChecked())
00514 src_image=pre.applySobelx(getGrayImage(src_image));
00515 else if (ui.checkSobely->isChecked() && !ui.checkSobelx->isChecked())
00516 src_image=pre.applySobely(getGrayImage(src_image));
00517 else if (ui.checkSobelx->isChecked() && ui.checkSobely->isChecked())
00518 src_image=pre.applySobel(getGrayImage(src_image));
00519 if (ui.checkLaplace->isChecked())
00520 src_image=pre.applyLaplace(getGrayImage(src_image));
00521 if (ui.checkMatrix->isChecked())
00522 src_image=pre.applyMatrix(getGrayImage(src_image),filterData);
00523 if (ui.checkLoG->isChecked())
00524 src_image=pre.applyMatrixLoG(getGrayImage(src_image));
00525 if (ui.checkThreshold->isChecked())
00526 src_image=pre.applyThreshold(getGrayImage(src_image));
00527 if (ui.checkCanny->isChecked())
00528 src_image=pre.applyCanny(getGrayImage(src_image));
00529 }catch(...){
00530 ui.txInform->append(QString("Some preprocessing exception has been thrown"));
00531 }
00533 Segmentation seg(ui);
00534 try {
00535
00536 if (ui.checkContour->isChecked())
00537 src_image=seg.drawContour(getGrayImage(src_image));
00538
00539 if (ui.comboHough->currentIndex()==1)
00540 src_image=seg.drawHoughLines(getGrayImage(src_image),CV_HOUGH_STANDARD);
00541 else if (ui.comboHough->currentIndex()==2)
00542 src_image=seg.drawHoughLines(getGrayImage(src_image),CV_HOUGH_PROBABILISTIC);
00543
00544 if (ui.checkScale->isChecked()==1)
00545 src_image=seg.drawLocalScaleSpace(getGrayImage(src_image));
00546 }catch(...){
00547 ui.txInform->append(QString("Some Segmentation exception has been thrown"));
00548 }
00549
00550 Blobs blob(ui);
00551 try{
00552 if (ui.checkBlobslib->isChecked())
00553 src_image=blob.applyBlobslib(getGrayImage(src_image));
00554 }catch(...){
00555 ui.txInform->append(QString("Some Segmentation-Blob exception has been thrown"));
00556 }
00557
00559
00560 if (ui.checkBlobTrack->isChecked()){
00561 if (ui.comboLog->currentIndex()>0)
00562 ui.txInform->append(QString("Running Blob Kalman"));
00563 filterBlobs=blob.getBlobs();
00564 ui.comboBlobs->clear();
00565 for (int j=0;j<filterBlobs.GetNumBlobs();j++)
00566 ui.comboBlobs->addItem(QString("Blob %1").arg(j));
00567 }
00568
00569 if (ui.checkKalmanPaint->isChecked()){
00570 if (ui.comboLog->currentIndex()>0)
00571 ui.txInform->append(QString("Painting Kalman point selected"));
00572 src_image=track.paintCrossKalmanSelected(src_image);
00573 }
00574 if (ui.comboKalmanPaint->currentIndex()>0){
00575 if (ui.comboKalmanPaint->currentIndex()==1)
00576 src_image=track.paintCrossKalmanPredicted(src_image);
00577 else if (ui.comboKalmanPaint->currentIndex()==2)
00578 src_image=track.paintCrossKalmanPredictedAutoUpdate(src_image);
00579 else if (ui.comboKalmanPaint->currentIndex()==3)
00580 src_image=track.paintCrossKalmanPredictedLastUpdate(src_image);
00581
00582 std::vector<CvPoint> vSel=track.getKalmanPoints();
00583 std::vector<CvPoint> vPre=track.getKalmanPredicted();
00584 std::vector<CvPoint> vUpd=track.getLastPointUpdate();
00585 if (ui.comboLog->currentIndex()>0){
00586 ui.txInform->append(QString("Running Kalman algorithm index %1").arg(ui.comboKalmanPaint->currentIndex()));
00587 for (int i=0;i<vPre.size();i++)
00588 ui.txInform->append(QString("Point: %1. Before: (%2,%3), Last Update: (%4,%5), Point Predicted: (%6,%7)")
00589 .arg(i).arg(vSel[i].x).arg(vSel[i].y).arg(vUpd[i].x).arg(vUpd[i].y).arg(vPre[i].x).arg(vPre[i].y));
00590 }
00591 }
00592
00593 cvShowImage( "image", src_image );
00594 cvReleaseImage(&src_image);
00595 }
00596
00597 QStringList MainFrame::loadSeq(){
00598 QDir dirSeq(ui.lePathSeq->text());
00599 QStringList filters;
00600 filters << "*.jpg" << "*.jpeg" << "*.png" <<"*.pgm";
00601 dirSeq.setNameFilters(filters);
00602 return dirSeq.entryList();
00603 }
00604
00605 void MainFrame::loadImageSeq(){
00606 if (ui.lePathSeq->text()==""){
00607 QMessageBox::warning(this, tr("Research Artificial Vision Tool"),
00608 tr("Path has to be selected\nFile->Open Directory"));
00609 return;
00610 }
00611 ui.txInform->append("Loading images...");
00612 ui.txInform->repaint();
00613
00614 if (ui.lePathSeq->text()==qPathLoaded){
00615 ui.txInform->append("Path already loaded");
00616 return;
00617 }
00618
00619 QStringList fileListTemp=loadSeq();
00620 if (fileListTemp.count()==0){
00621 QMessageBox::warning(this, tr("Research Artificial Vision Tool"),tr("Images were not found"));
00622 ui.txInform->append(QString("ALERT!!!: Images were not found in path: %1").arg(ui.lePathSeq->text()));
00623
00624 ui.lePathSeq->setText(qPathLoaded);
00625 return;
00626 }
00627 ui.txInform->append(QString("Loaded %1 images from %2").arg(fileListTemp.count()).arg(ui.lePathSeq->text()));
00628
00629 fileList=fileListTemp;
00630
00631 qPathLoaded=ui.lePathSeq->text();
00632
00633 cvDestroyAllWindows();
00634 closeCvWindow=1;
00635
00636 ui.showSeq->setEnabled(true);
00637 ui.showStepByStep->setEnabled(true);
00638 }
00639
00640 void MainFrame::loadAutoSeq(){
00641
00642 ui.showSeq->setEnabled(false);
00643 ui.showStepByStep->setEnabled(false);
00644 disableStepOptions();
00645
00646 cvDestroyAllWindows();
00647 closeCvWindow=0;
00648
00649 int iStop=0;
00650 for (int i = 0; i < fileList.size(); i++){
00651 int iFps=(ui.leFPSSeq->text()).toInt();
00652 iFps=(iFps<1)?1:iFps;
00653 loadStepImage(i);
00654 iStop=cvWaitKey(iFps);
00655
00656 if (iStop!=-1 || closeCvWindow)
00657 break;
00658 }
00659
00660 ui.showSeq->setEnabled(true);
00661 ui.showStepByStep->setEnabled(true);
00662
00663 cvDestroyAllWindows();
00664 }
00665
00666 void MainFrame::loadStepSeq(){
00667
00668 closeCvWindow=1;
00669 cvDestroyAllWindows();
00670
00671
00672
00673 ableStepOptions();
00674
00675
00676 iStepFrame=0;
00677 cvNamedWindow("image", 0);
00678 loadStepImage(iStepFrame);
00679 cvWaitKey(0);
00680
00681
00682 cvDestroyAllWindows();
00683
00684 disableStepOptions();
00685 }
00686
00687 void MainFrame::loadNextSeq(){
00688 iStepFrame++;
00689 if (fileList.size()>iStepFrame){
00690 loadStepImage(iStepFrame);
00691 }else
00692 iStepFrame--;
00693 }
00694
00695 void MainFrame::loadBackSeq(){
00696 iStepFrame--;
00697 if (iStepFrame>=0){
00698 loadStepImage(iStepFrame);
00699 }else
00700 iStepFrame++;
00701 }
00702
00703 void MainFrame::ableStepOptions(){
00704 ui.showBackStep->setEnabled(true);
00705 ui.showNextStep->setEnabled(true);
00706 }
00707
00708 void MainFrame::disableStepOptions(){
00709 ui.showBackStep->setEnabled(false);
00710 ui.showNextStep->setEnabled(false);
00711 }
00712
00713 IplImage* MainFrame::getGrayImage(IplImage *src_image){
00714 if (cvGetElemType(src_image)>0){
00715 IplImage* src = cvCreateImage( cvGetSize(src_image),IPL_DEPTH_8U, 1);
00716 cvCvtColor(src_image, src, CV_BGR2GRAY);
00717 cvReleaseImage(&src_image);
00718 if (ui.comboLog->currentIndex()>1)
00719 ui.txInform->append(QString("\tChanging color image to gray scale"));
00720 return src;
00721 } else
00722 return src_image;
00723 }
00724
00725
00726
00727
00728
00729
00730
00731
00732