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

try next bug fix, huge work around for corrupted file test

parent cb182607
No related branches found
No related tags found
No related merge requests found
...@@ -15,7 +15,7 @@ based on original demo.cpp ...@@ -15,7 +15,7 @@ based on original demo.cpp
#define PROCESS_CENTER_VERSION_MAJOR 0 #define PROCESS_CENTER_VERSION_MAJOR 0
#define PROCESS_CENTER_VERSION_MINOR 9 #define PROCESS_CENTER_VERSION_MINOR 9
#define PROCESS_CENTER_VERSION_MINOR_FIXES 4 #define PROCESS_CENTER_VERSION_MINOR_FIXES 7
//opencv //opencv
#include <opencv2/opencv.hpp> #include <opencv2/opencv.hpp>
...@@ -46,6 +46,7 @@ bool cmdOptionExists(char** begin, char** end, const std::string& option) ...@@ -46,6 +46,7 @@ bool cmdOptionExists(char** begin, char** end, const std::string& option)
int main(int argc, char * argv[]) int main(int argc, char * argv[])
{ {
std::cout << "using processcenter " <<PROCESS_CENTER_VERSION_MAJOR <<"."<< PROCESS_CENTER_VERSION_MINOR << endl; 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 OpenCV " << CV_MAJOR_VERSION << "." << CV_MINOR_VERSION << "." << CV_SUBMINOR_VERSION <<"."<<PROCESS_CENTER_VERSION_MINOR_FIXES<< std::endl;
//!** parse programm input****************/ //!** parse programm input****************/
...@@ -224,6 +225,14 @@ int main(int argc, char * argv[]) ...@@ -224,6 +225,14 @@ int main(int argc, char * argv[])
//std::string fileName = getFileName(begin); //std::string fileName = getFileName(begin);
std::string staticFile = inputDir+"/bk.jpg"; std::string staticFile = inputDir+"/bk.jpg";
cout <<"a) load first static background pic :"<< staticFile<<endl; cout <<"a) load first static background pic :"<< staticFile<<endl;
//we check for corrupt image
if(TToolBox::checkFileCorrupted(staticFile))
{
cout<<"error file: "<< staticFile<<" is corrupted, will abort"<<endl;
return EXIT_FAILURE;
}
img_input = imread(staticFile.c_str(), CV_LOAD_IMAGE_COLOR); img_input = imread(staticFile.c_str(), CV_LOAD_IMAGE_COLOR);
if(img_input.data ) if(img_input.data )
{ {
...@@ -271,6 +280,14 @@ int main(int argc, char * argv[]) ...@@ -271,6 +280,14 @@ int main(int argc, char * argv[])
fileName = inputDir + TToolBox::getFileName(index); fileName = inputDir + TToolBox::getFileName(index);
myRandomTrainList.push_back(fileName); myRandomTrainList.push_back(fileName);
//we check for corrupt image
if(TToolBox::checkFileCorrupted(fileName))
{
cout<<"error file: "<< fileName<<" is corrupted, will ignore it and draw new"<<endl;
i--;
continue; //we jump over the rest //TODO bad style
}
cout <<"\t"<<i <<"\t of \t"<<amountTrainingSteps<<" rnd file :"<< fileName<<endl; cout <<"\t"<<i <<"\t of \t"<<amountTrainingSteps<<" rnd file :"<< fileName<<endl;
img_input = imread(fileName.c_str(), CV_LOAD_IMAGE_COLOR); img_input = imread(fileName.c_str(), CV_LOAD_IMAGE_COLOR);
...@@ -316,6 +333,7 @@ int main(int argc, char * argv[]) ...@@ -316,6 +333,7 @@ int main(int argc, char * argv[])
vector<string> myFileErrorList;//list for pure io error vector<string> myFileErrorList;//list for pure io error
vector<string> myFileListNoContour; //list for no contours found; vector<string> myFileListNoContour; //list for no contours found;
vector<string> myFileListAfterContourSelection; //list for no contours found after selection; vector<string> myFileListAfterContourSelection; //list for no contours found after selection;
vector<string> myFileListCorrupted; //list all corrupted jpg files
for(frameCounter=0;frameCounter<amountFiles;frameCounter++) for(frameCounter=0;frameCounter<amountFiles;frameCounter++)
{ {
...@@ -341,6 +359,10 @@ int main(int argc, char * argv[]) ...@@ -341,6 +359,10 @@ int main(int argc, char * argv[])
cout << " d 3: "<< fileName.size()<< " size: "<< fileName<<endl; cout << " d 3: "<< fileName.size()<< " size: "<< fileName<<endl;
cout << " d 3: "<< fileNameCV.size()<< " size:"<< fileNameCV.c_str(); cout << " d 3: "<< fileNameCV.size()<< " size:"<< fileNameCV.c_str();
//we check if the image in NOT corrupted
if(!TToolBox::checkFileCorrupted(fileName))
{
//we load the file
img_input = imread(fileNameCV, CV_LOAD_IMAGE_COLOR); img_input = imread(fileNameCV, CV_LOAD_IMAGE_COLOR);
cout << " e "<<endl; cout << " e "<<endl;
...@@ -618,7 +640,8 @@ int main(int argc, char * argv[]) ...@@ -618,7 +640,8 @@ int main(int argc, char * argv[])
imwrite(nameOutPutFileDBGpic.c_str(),imgOverlay2); imwrite(nameOutPutFileDBGpic.c_str(),imgOverlay2);
cout << " l "<<endl; cout << " l "<<endl;
} }//end if we write a dbg picture
}//end if the loaded picture has data }//end if the loaded picture has data
else else
...@@ -627,6 +650,15 @@ int main(int argc, char * argv[]) ...@@ -627,6 +650,15 @@ int main(int argc, char * argv[])
myFileErrorList.push_back(fileName); myFileErrorList.push_back(fileName);
} }
}//end if not corrupted picture
else
{
cout<<"error file: "<< fileName<<" is corrupted, will ignore it"<<endl;
myFileListCorrupted.push_back(fileName);
}
//we calc the time which we used for a picture //we calc the time which we used for a picture
clock_t end = clock(); clock_t end = clock();
double elapsedSecs = double(end - begin) / CLOCKS_PER_SEC; double elapsedSecs = double(end - begin) / CLOCKS_PER_SEC;
......
...@@ -96,3 +96,56 @@ cv::Mat TToolBox::cropImageCircle(cv::Mat image, int x, int y, int r) ...@@ -96,3 +96,56 @@ cv::Mat TToolBox::cropImageCircle(cv::Mat image, int x, int y, int r)
return res; return res;
} }
int TToolBox::checkFileCorrupted(std::string filename)
{
int retVal = 1;//is as long Corrupted as we dont find it in another way
char command[] = "identify ";
const char *fileNameArr = filename.c_str();
char command2[] = " > /dev/null 2>&1 ; echo $?";
char *cmd = new char[std::strlen(command)+std::strlen(fileNameArr) + std::strlen(command2) +1];
//we put all peaces together
std::strcpy(cmd,command);
std::strcat(cmd,fileNameArr);
std::strcat(cmd,command2);
//std:: cout <<"cmd is: "<< cmd<< std::endl;
//execute the command
std::string result = TToolBox::execCMD((const char* ) cmd);
//std:: cout <<"results is: "<< result<< std::endl;
if(!result.empty())
{
try {
retVal = std::stoi(result);
}
catch(std::invalid_argument& e)
{
std::cerr <<"wrong argument for stoi"<<std::endl;
// if no conversion could be performed
}
catch (const std::exception& e)
{
std::cerr <<"error during use stoi"<<std::endl;
}
}//end if
return retVal;
}
std::string TToolBox::execCMD(const char* cmd) {
std::array<char, 128> buffer;
std::string result;
std::shared_ptr<FILE> pipe(popen(cmd, "r"), pclose);
if (!pipe) throw std::runtime_error("popen() failed!");
while (!feof(pipe.get())) {
if (fgets(buffer.data(), 128, pipe.get()) != nullptr)
result += buffer.data();
//std::cout<<result<<std::endl;
}
//std::cout<<"call: " <<result<<std::endl;
return result;
}
...@@ -10,6 +10,11 @@ ...@@ -10,6 +10,11 @@
#include <time.h> /* time */ #include <time.h> /* time */
#include <ctime> #include <ctime>
#include <sstream> #include <sstream>
#include <cstdio>
#include <memory>
#include <stdexcept>
#include <string>
#include <array>
//open cv //open cv
#include "opencv2/core/core.hpp" #include "opencv2/core/core.hpp"
...@@ -36,6 +41,13 @@ public: ...@@ -36,6 +41,13 @@ public:
//! canny edge detect //! canny edge detect
static std::vector<std::vector<cv::Point>> applyCannyEdgeAndCalcCountours(cv::Mat imgSource, double threshholdMin, double threshholdMax, int apertureSize); static std::vector<std::vector<cv::Point>> applyCannyEdgeAndCalcCountours(cv::Mat imgSource, double threshholdMin, double threshholdMax, int apertureSize);
//! will test if file is not corrupted
//! @return 1 if corrupted
//! @return 0 if not
static int checkFileCorrupted(std::string filename);
//! will try to execute the cmd on the bash
static std::string execCMD(const char* cmd);
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment