Skip to content
Snippets Groups Projects
Commit 0ee54406 authored by Thomas Boy's avatar Thomas Boy
Browse files

bug fixed, sad work around, we have a lot of corrupted jpg files, will double check before load

parent 7201cda8
No related branches found
No related tags found
No related merge requests found
......@@ -15,7 +15,7 @@ based on original demo.cpp
#define PROCESS_CENTER_VERSION_MAJOR 0
#define PROCESS_CENTER_VERSION_MINOR 9
#define PROCESS_CENTER_VERSION_MINOR_FIXES 7
#define PROCESS_CENTER_VERSION_MINOR_FIXES 8
//opencv
#include <opencv2/opencv.hpp>
......@@ -47,8 +47,8 @@ bool cmdOptionExists(char** begin, char** end, const std::string& option)
int main(int argc, char * argv[])
{
std::cout << "using processcenter " <<PROCESS_CENTER_VERSION_MAJOR <<"."<< PROCESS_CENTER_VERSION_MINOR << endl;
std::cout << "Using OpenCV " << CV_MAJOR_VERSION << "." << CV_MINOR_VERSION << "." << CV_SUBMINOR_VERSION <<"."<<PROCESS_CENTER_VERSION_MINOR_FIXES<< std::endl;
std::cout << "using processcenter " <<PROCESS_CENTER_VERSION_MAJOR <<"."<< PROCESS_CENTER_VERSION_MINOR<<"."<<PROCESS_CENTER_VERSION_MINOR_FIXES<< endl;
std::cout << "Using OpenCV " << CV_MAJOR_VERSION << "." << CV_MINOR_VERSION << "." << CV_SUBMINOR_VERSION << std::endl;
//!** parse programm input****************/
if(cmdOptionExists(argv, argv+argc, "-h"))
{
......@@ -175,12 +175,6 @@ int main(int argc, char * argv[])
Tapter *bgs = new Tapter;
// bgs->setPathOut(outputDir);
// bgs->setInitialFrameCounter(0);
// bgs->setFlagWrite(0);
// bgs->setFlagWriteDBGpic(0);
//see paper https://dl.acm.org/citation.cfm?id=2321600
//https://ieeexplore.ieee.org/document/4527178/
//was in benchmark on top https://www.researchgate.net/publication/259340906_A_comprehensive_review_of_background_subtraction_algorithms_evaluated_with_synthetic_and_real_videos
......@@ -291,28 +285,16 @@ int main(int argc, char * argv[])
cout <<"\t"<<i <<"\t of \t"<<amountTrainingSteps<<" rnd file :"<< fileName<<endl;
img_input = imread(fileName.c_str(), CV_LOAD_IMAGE_COLOR);
cout << " a "<<endl;
if(img_input.data )
{
//we cut out a smaller ROI
img_input = TToolBox::cropImageCircle(img_input,circleCenterX,circleCenterY,circleRadius);
//cv::imshow("input", img_input);
cv::Mat img_mask;
cv::Mat img_bkgmodel;
// //adapter learning rate
// if(j>62)
// bgs->setLearningRate(j);
bgs->process(img_input, img_mask, img_bkgmodel); // by default, it shows automatically the foreground mask image
cout << " b "<<endl;
// //we save the bk gmodel
// std::string bkTestFileName = inputDir + "bk_"+TToolBox::mNzero(i)+".jpg";
// imwrite(bkTestFileName.c_str(),img_bkgmodel);
}
else
{
......@@ -322,9 +304,6 @@ int main(int argc, char * argv[])
}
}
cout << " c "<<endl;
cout <<"c) we produce train the background with random choosen files"<< fileName<<endl;
int everyPic=60*5;
......@@ -337,27 +316,15 @@ int main(int argc, char * argv[])
for(frameCounter=0;frameCounter<amountFiles;frameCounter++)
{
cout << " d "<<endl;
//measure time consumption
clock_t begin = clock();
//we define the type better to prevent error
fileName = std::string(inputDir + TToolBox::getFileName(frameCounter));
// //check the string
// cout <<"open fileName: "<< fileName<<endl;
// if(fileName.empty())
// cerr <<"error: empty string fileName"<<endl;
cv::String fileNameCV(fileName);
cout <<"\t"<<frameCounter<<"\tof \t"<<amountFiles<<" load file :"<< fileName<<endl;
//cv::imwrite(convert.str().c_str(), img_output);
//we open the file
cv::String fileNameCV(fileName);
cout << " d 3: "<< fileName.size()<< " size: "<< fileName<<endl;
cout << " d 3: "<< fileNameCV.size()<< " size:"<< fileNameCV.c_str();
//we check if the image in NOT corrupted
if(!TToolBox::checkFileCorrupted(fileName))
......@@ -365,8 +332,6 @@ int main(int argc, char * argv[])
//we load the file
img_input = imread(fileNameCV, CV_LOAD_IMAGE_COLOR);
cout << " e "<<endl;
if(img_input.data )
{
//! we cut out a smaller ROI,
......@@ -380,8 +345,6 @@ int main(int argc, char * argv[])
bgs->process(img_input, img_mask, img_bkgmodel); // by default, it shows automatically the foreground mask image
cout << " f "<<endl;
//! step 3) we make we apply a edge detection
//TODO make this in a function, how many times is this listed ??
//TODO read from tapter config
......@@ -450,9 +413,6 @@ int main(int argc, char * argv[])
float areaMinThreshold = 150;
float areaMaxThreshold = 300000; //old max threshold was to small //TODO apply moving filter ??, an more adaptive approach
cout << " g "<<endl;
//iterate all rectangles
for( size_t i = 0; i< minRect.size(); i++ )
{
......@@ -535,9 +495,6 @@ int main(int argc, char * argv[])
muConvexHullMassCenter= Point2f( muConvexHull.m10/muConvexHull.m00 , muConvexHull.m01/muConvexHull.m00 );
}
cout << " h "<<endl;
}//end after selection is empty
{
cerr<<"error, no contour found after selection in file: "<< fileName<<endl;
......@@ -574,20 +531,9 @@ int main(int argc, char * argv[])
#endif
cout << " i "<<endl;
//cout<<"we try to write file: "<< i <<endl;
//! step 8: we write down all our results in yml file
std::string nameOutPutFileData = outputDir + TToolBox::mNzero(frameCounter) + ".yml";
cout << " j "<<endl;
// //check the string
// cout <<"write output nameOutPutFileData: "<< nameOutPutFileData<<endl;
// if(nameOutPutFileData.empty())
// cerr <<"error: empty string nameOutPutFileData"<<endl;
FileStorage fs(nameOutPutFileData.c_str(), FileStorage::WRITE);
fs << "masscenters" << massCenters;
fs << "polygonselection"<< contourSelection;
......@@ -595,8 +541,6 @@ int main(int argc, char * argv[])
fs << "masscenterconvexhull"<<muConvexHullMassCenter;
fs.release();
cout << " k "<<endl;
//! we write from time to time a dbg picture
if(frameCounter%everyPic==0)
{
......@@ -632,14 +576,8 @@ int main(int argc, char * argv[])
//we write the file down
std::string nameOutPutFileDBGpic = outputDir + TToolBox::mNzero(frameCounter) + std::string(".jpg");
// //check the string
// cout <<"write dbg file: "<< nameOutPutFileDBGpic<<endl;
// if(nameOutPutFileDBGpic.empty())
// cerr <<"error: empty string nameOutPutFileDBGpic"<<endl;
imwrite(nameOutPutFileDBGpic.c_str(),imgOverlay2);
cout << " l "<<endl;
}//end if we write a dbg picture
......@@ -653,7 +591,7 @@ int main(int argc, char * argv[])
}//end if not corrupted picture
else
{
cout<<"error file: "<< fileName<<" is corrupted, will ignore it"<<endl;
cerr<<"error file: "<< fileName<<" is corrupted, will ignore it"<<endl;
myFileListCorrupted.push_back(fileName);
}
......@@ -669,9 +607,7 @@ int main(int argc, char * argv[])
double elapsedSecTotal = double(endAll - beginAll) / CLOCKS_PER_SEC;
cout <<"process single pic:\t"<<elapsedSecs<<" s - \t\t"<<(int)(elapsedSecTotal/60)<<" min -\t"<<(int)(elapsedSecTotal/60/60)<<" h"<<endl;
cout << " --- "<<endl;
}
cout << " X "<<endl;
//finishing time
clock_t endAll = clock();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment