Skip to content
Snippets Groups Projects
Commit ed6b10cc authored by am0ebe's avatar am0ebe
Browse files

.

parent 830f23e8
Branches
No related tags found
No related merge requests found
...@@ -102,11 +102,11 @@ file(GLOB main ../src/*.cpp) #Main.cpp FrameProcessor.cpp PreProcessor.cpp Video ...@@ -102,11 +102,11 @@ file(GLOB main ../src/*.cpp) #Main.cpp FrameProcessor.cpp PreProcessor.cpp Video
# set(src "../src") # set(src "../src")
# file(GLOB main "${src}/Main.cpp" "${src}/FrameProcessor.cpp" "${src}/PreProcessor.cpp" "${src}/VideoAnalysis.cpp" "${src}/VideoCapture.cpp") # file(GLOB main "${src}/Main.cpp" "${src}/FrameProcessor.cpp" "${src}/PreProcessor.cpp" "${src}/VideoAnalysis.cpp" "${src}/VideoCapture.cpp")
file(GLOB demo Demo.cpp) file(GLOB demo Demo.cpp)
file(GLOB demo2 Demo2.cpp) file(GLOB demo_orig Demo_orig.cpp)
file(GLOB_RECURSE tools_src ../src/tools/*.cpp) file(GLOB_RECURSE tools_src ../src/tools/*.cpp)
#file(GLOB sources FrameProcessor.cpp PreProcessor.cpp VideoAnalysis.cpp VideoCapture.cpp) #file(GLOB sources FrameProcessor.cpp PreProcessor.cpp VideoAnalysis.cpp VideoCapture.cpp)
# list(REMOVE_ITEM sources ${demo} ${demo2}) # list(REMOVE_ITEM sources ${demo} ${demo_orig})
if(BGS_PYTHON_SUPPORT) if(BGS_PYTHON_SUPPORT)
file(GLOB_RECURSE bgs_src ../algorithms/*.cpp ../algorithms/*.c wrapper_python/*.cpp) file(GLOB_RECURSE bgs_src ../algorithms/*.cpp ../algorithms/*.c wrapper_python/*.cpp)
...@@ -148,7 +148,7 @@ message(STATUS "bgs_src: '${bgs_src}'") ...@@ -148,7 +148,7 @@ message(STATUS "bgs_src: '${bgs_src}'")
message(STATUS "tools_src: '${tools_src}'") message(STATUS "tools_src: '${tools_src}'")
message(STATUS "main: '${main}'") message(STATUS "main: '${main}'")
message(STATUS "demo: '${demo}'") message(STATUS "demo: '${demo}'")
message(STATUS "demo2: '${demo2}'") message(STATUS "demo_orig: '${demo_orig}'")
message(STATUS "CMAKE_SOURCE_DIR: '${CMAKE_SOURCE_DIR}'") message(STATUS "CMAKE_SOURCE_DIR: '${CMAKE_SOURCE_DIR}'")
message(STATUS "CMAKE_BINARY_DIR: '${CMAKE_BINARY_DIR}'") message(STATUS "CMAKE_BINARY_DIR: '${CMAKE_BINARY_DIR}'")
message(STATUS "CMAKE_INCLUDE_PATH: '${CMAKE_INCLUDE_PATH}'") message(STATUS "CMAKE_INCLUDE_PATH: '${CMAKE_INCLUDE_PATH}'")
...@@ -162,11 +162,11 @@ add_executable(bgslibrary ${main}) ...@@ -162,11 +162,11 @@ add_executable(bgslibrary ${main})
target_link_libraries(bgslibrary ${OpenCV_LIBS} libbgs) target_link_libraries(bgslibrary ${OpenCV_LIBS} libbgs)
set_target_properties(bgslibrary PROPERTIES OUTPUT_NAME bgs) set_target_properties(bgslibrary PROPERTIES OUTPUT_NAME bgs)
# add_executable(bgs_demo ${demo}) # <<<<<< TODO add_executable(bgs_demo ${demo}) # <<<<<< TODO
# target_link_libraries(bgs_demo ${OpenCV_LIBS} ${LibArchive_LIBRARIES} libbgs) target_link_libraries(bgs_demo ${OpenCV_LIBS} ${LibArchive_LIBRARIES} libbgs)
add_executable(bgs_demo2 ${demo2}) add_executable(bgs_demo_orig ${demo_orig})
target_link_libraries(bgs_demo2 ${OpenCV_LIBS} ${LibArchive_LIBRARIES} libbgs) target_link_libraries(bgs_demo_orig ${OpenCV_LIBS} ${LibArchive_LIBRARIES} libbgs)
install(TARGETS libbgs bgslibrary install(TARGETS libbgs bgslibrary
RUNTIME DESTINATION bin COMPONENT app RUNTIME DESTINATION bin COMPONENT app
......
/* /*
./bgs_demo -i test45/ -a 100 -o test45/results bgs_demo -i ../../dataset/video.tar -a 100 -o ../../output -c ../../config/centerConfigFile.xml -p ../../config/camParam.xml
// -c center?
*/ */
//cpp c //cpp c
...@@ -52,15 +51,25 @@ int main(int argc, char * argv[]) ...@@ -52,15 +51,25 @@ int main(int argc, char * argv[])
std::cout << "using processcenter " << PROCESS_CENTER_VERSION_MAJOR <<"."<< PROCESS_CENTER_VERSION_MINOR<<"."<<PROCESS_CENTER_VERSION_MINOR_FIXES<< 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; std::cout << "Using OpenCV " << CV_MAJOR_VERSION << "." << CV_MINOR_VERSION << "." << CV_SUBMINOR_VERSION << std::endl;
//!** parse programm input****************/ //!** parse programm input****************/
if(cmdOptionExists(argv, argv+argc, "-h") if( cmdOptionExists(argv, argv+argc, "-h")
|| cmdOptionExists(argv, argv+argc, "-?")
|| !cmdOptionExists(argv, argv+argc, "-i") || !cmdOptionExists(argv, argv+argc, "-i")
|| !cmdOptionExists(argv, argv+argc, "-a") || !cmdOptionExists(argv, argv+argc, "-a")
|| !cmdOptionExists(argv, argv+argc, "-o") || !cmdOptionExists(argv, argv+argc, "-o")
|| !cmdOptionExists(argv, argv+argc, "-p")) || !cmdOptionExists(argv, argv+argc, "-p"))
{ {
cout <<" Usage:\n" << argv[0] << " -i inputTarFile -a amountOfJpgFiles -c exactCenterConfFile.xml -o outPutPath -p camparameterFile.xml"<< endl; cout <<" Usage:" << endl;
cout << " " << argv[0] << " -i in.tar -a amount -c center.xml -o outPath -p camparameterFile.xml"<< endl << endl;
cout << " Options:" << endl;
cout << " i - input tarfile/dir containing tars ?" << endl;
cout << " a - amount of files/frames ?" << endl;
cout << " c - exact center xml-conf file" << endl;
cout << " o - output path / dir" << endl;
cout << " p - camparameterFile ?" << endl;
return EXIT_FAILURE; return EXIT_FAILURE;
} }
...@@ -165,7 +174,7 @@ int main(int argc, char * argv[]) ...@@ -165,7 +174,7 @@ int main(int argc, char * argv[])
clock_t beginAll = clock(); clock_t beginAll = clock();
//! we read the center config file for cut out the ROI //! read the center config file to cut out the ROI
//TODO merge this config with the Tapter.xml ?? //TODO merge this config with the Tapter.xml ??
//circle param //circle param
int circleCenterX = 880; int circleCenterX = 880;
...@@ -202,17 +211,23 @@ int main(int argc, char * argv[]) ...@@ -202,17 +211,23 @@ int main(int argc, char * argv[])
fs.open(camParam, FileStorage::READ); fs.open(camParam, FileStorage::READ);
if (!fs.isOpened()) if (!fs.isOpened())
{ {
cerr << "error during open " << cameraParameterFile << " will abort\n "; cerr << "error during open " << cameraParameterFile << " will abort" << endl;
return -1; return -1;
} }
fs["camera_matrix"] >> intrinsicsCameraMatrix; // fs["camera_matrix"] >> intrinsicsCameraMatrix;
std::cout << "camera_matrix = "<< intrinsicsCameraMatrix << endl; // fs["distortion_coefficients"] >> distortionCoeff;
fs["distortion_coefficients"] >> distortionCoeff; intrinsicsCameraMatrix = (int) fs["camera_matrix"];
std::cout << "distortion_coefficients"<< distortionCoeff << endl; // intrinsicsCameraMatrix = fs["camera_matrix"].mat();
cout << "camera_matrix = "<< intrinsicsCameraMatrix << endl;
distortionCoeff = (int) fs["distortion_coefficients"];
// distortionCoeff = fs["distortion_coefficients"].mat();
cout << "distortion_coefficients = " << distortionCoeff << endl;
} }
cout.flush();
cout <<"a) we process all frames "<<endl; cout <<"a) we process all frames "<<endl;
...@@ -225,11 +240,7 @@ int main(int argc, char * argv[]) ...@@ -225,11 +240,7 @@ int main(int argc, char * argv[])
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;
//the corruption check is done beforehand //loop over all picture of the tar archive, independing how many this are
//vector<string> myFileListCorrupted; //list all corrupted jpg files
//here we loop over all picture of the tar archive, independing how many this are
for (;;) for (;;)
{ {
...@@ -238,20 +249,20 @@ int main(int argc, char * argv[]) ...@@ -238,20 +249,20 @@ int main(int argc, char * argv[])
std::vector<char> vec; std::vector<char> vec;
//we read the next header //we read the next header
r = corruption(archive, &entry); r = archive_read_next_header(archive, &entry);
if (r == ARCHIVE_EOF) if (r == ARCHIVE_EOF)
break; break;
if (r != ARCHIVE_OK) if (r != ARCHIVE_OK)
{ {
cerr<<"archive_read_next_header: error: "<< archive_error_string(archive) <<" will abort"<< endl; cerr << "archive_read_next_header: error: "<< archive_error_string(archive) <<" will abort"<< endl;
exit(1); exit(1);
} }
//we get the filename // get filename
const char *fileNamePtr = archive_entry_pathname(entry); const char *fileNamePtr = archive_entry_pathname(entry);
std::string filename(fileNamePtr,strlen(fileNamePtr) ); std::string filename(fileNamePtr,strlen(fileNamePtr) );
//cout << "fileName: "<< filename <<endl; //cout << "fileName: "<< filename <<endl;
//we convert it to a framenumber // convert it to a framenumber
frameCounter = toFrameNumber(filename); frameCounter = toFrameNumber(filename);
if(frameCounterOld>frameCounter) if(frameCounterOld>frameCounter)
...@@ -269,9 +280,7 @@ int main(int argc, char * argv[]) ...@@ -269,9 +280,7 @@ int main(int argc, char * argv[])
myFileTarWriterHeaderCounter++; myFileTarWriterHeaderCounter++;
continue; //we overjump all in our for loop continue; //we overjump all in our for loop
} }
//else
//{
//we copy all data to the buffer vector
vec = copyDataInBuffer(archive); vec = copyDataInBuffer(archive);
if(vec.empty()) if(vec.empty())
cerr << "error during load data into buffer"; cerr << "error during load data into buffer";
...@@ -282,8 +291,8 @@ int main(int argc, char * argv[]) ...@@ -282,8 +291,8 @@ int main(int argc, char * argv[])
cerr<<"archive_write_finish_entry: error: "<< archive_error_string(ext) <<" will abort"<< endl; cerr<<"archive_write_finish_entry: error: "<< archive_error_string(ext) <<" will abort"<< endl;
exit(1); exit(1);
} }
//}
//we read the image buffer as a jpg picture and decode it // read the image buffer as a jpg picture and decode it
Mat img_input = imdecode(Mat(vec), 1); Mat img_input = imdecode(Mat(vec), 1);
// //we define the type better to prevent error // //we define the type better to prevent error
...@@ -313,7 +322,7 @@ int main(int argc, char * argv[]) ...@@ -313,7 +322,7 @@ int main(int argc, char * argv[])
bgs->process(img_input, img_mask, img_bkgmodel); // by default, it shows automatically the foreground mask image bgs->process(img_input, img_mask, img_bkgmodel); // by default, it shows automatically the foreground mask image
//! step 3) we make we apply a edge detection //! step 3) apply edge detection
//TODO make this in a function, how many times is this listed ?? //TODO make this in a function, how many times is this listed ??
//TODO read from tapter config //TODO read from tapter config
//TODO all parameter from applyCannyEdgeAndCalcCountours also !! //TODO all parameter from applyCannyEdgeAndCalcCountours also !!
...@@ -523,21 +532,12 @@ int main(int argc, char * argv[]) ...@@ -523,21 +532,12 @@ int main(int argc, char * argv[])
myFileErrorList.push_back(filename); myFileErrorList.push_back(filename);
} }
// }//end if not corrupted picture //calc the time which we used for a picture
// else
// {
// cerr<<"error file: "<< fileName<<" is corrupted, will ignore it"<<endl;
// myFileListCorrupted.push_back(fileName);
// }
//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;
//we calc the time which was used for all picture //calc the time which was used for all pictures
clock_t endAll = clock(); clock_t endAll = clock();
double elapsedSecTotal = double(endAll - beginAll) / CLOCKS_PER_SEC; 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 <<"process single pic:\t"<<elapsedSecs<<" s - \t\t"<<(int)(elapsedSecTotal/60)<<" min -\t"<<(int)(elapsedSecTotal/60/60)<<" h"<<endl;
...@@ -578,11 +578,6 @@ int main(int argc, char * argv[]) ...@@ -578,11 +578,6 @@ int main(int argc, char * argv[])
cout <<"amount contour errors after selection: "<< myFileListAfterContourSelection.size()<<endl; cout <<"amount contour errors after selection: "<< myFileListAfterContourSelection.size()<<endl;
fs2 << "fileErrorNoContoursAfterSelections" << myFileListAfterContourSelection; fs2 << "fileErrorNoContoursAfterSelections" << myFileListAfterContourSelection;
// //we write error list no contours found in file
// cout <<"amount of corrupted jpg files: "<< myFileListCorrupted.size()<<endl;
// fs2 << "fileErrorIOcorruptFiles" << myFileListCorrupted;
//the bgs related things //the bgs related things
delete bgs; delete bgs;
...@@ -624,7 +619,7 @@ std::vector<char> copyDataInBuffer(struct archive *aw) ...@@ -624,7 +619,7 @@ std::vector<char> copyDataInBuffer(struct archive *aw)
if (r != ARCHIVE_OK) if (r != ARCHIVE_OK)
{ {
cerr << "error during read archive "<<endl; cerr << "error during read archive " << endl;
return vec; return vec;
} }
...@@ -640,6 +635,7 @@ std::vector<char> copyDataInBuffer(struct archive *aw) ...@@ -640,6 +635,7 @@ std::vector<char> copyDataInBuffer(struct archive *aw)
return vec; return vec;
} }
void my_handler(int signum) void my_handler(int signum)
{ {
if (signum == SIGUSR1) if (signum == SIGUSR1)
......
/*
./bgs_demo -i test45/ -a 100 -o test45/results/
based on original demo.cpp
*/
// c
#include <sys/types.h>
#include <sys/stat.h>
#include <archive.h>
#include <archive_entry.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
//cpp c
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <stdio.h> /* printf, scanf, puts, NULL */
#include <stdlib.h> /* srand, rand */
#include <time.h> /* time */
#include <ctime>
#define PROCESS_CENTER_VERSION_MAJOR 0
#define PROCESS_CENTER_VERSION_MINOR 2
#include <opencv2/opencv.hpp> //opencv
#include "../src/algorithms/algorithms.h" //bgs
using namespace bgslibrary::algorithms;
using namespace cv;
using namespace std;
char* getCmdOption(char ** begin, char ** end, const std::string & option)
{
char ** itr = std::find(begin, end, option);
if (itr != end && ++itr != end)
{
return *itr;
}
return 0;
}
bool cmdOptionExists(char** begin, char** end, const std::string& option)
{
return std::find(begin, end, option) != end;
}
static std::vector<char> copyDataInBuffer(struct archive *aw);
//static void errmsg(const char *);
//static void fail(const char *, const char *, int);
//static void msg(const char *);
//static void warn(const char *, const char *);
int main(int argc, char * argv[])
{
std::cout << "using produce bk " <<PROCESS_CENTER_VERSION_MAJOR <<"."<< PROCESS_CENTER_VERSION_MINOR << 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"))
{
cout <<" error: please use command as\n./bgs_demo -i pathToInputDir -a amountOfJpgFiles -c exactCenterConfFile.xml -o outPutPath"<<endl;
return EXIT_FAILURE;
}
if(!cmdOptionExists(argv, argv+argc, "-i")||!cmdOptionExists(argv, argv+argc, "-a")||!cmdOptionExists(argv, argv+argc, "-o") )
{
cout <<" error: please use command as\n./bgs_demo -i pathToInputDir -a amountOfJpgFiles -c exactCenterConfFile.xml -o outPutPath"<<endl;
return EXIT_FAILURE;
}
char *testInputDir = getCmdOption(argv, argv + argc, "-i");
string inputDir(".");
if (testInputDir)
{
//test dir exists
inputDir = string(testInputDir);
}
int amountFiles = -1;
char *testFileAmount = getCmdOption(argv, argv + argc, "-a");
if (testFileAmount)
{
string s(testFileAmount);
stringstream foo(s);
foo >> amountFiles;
}
char *centerFile = getCmdOption(argv, argv + argc, "-c");
string centerFileString(".");
if (centerFile)
{
//test dir exists
centerFileString = string(centerFile);
}
char *testOutputDir = getCmdOption(argv, argv + argc, "-o");
string outputDir(".");
if (testOutputDir)
{
//test dir exists
outputDir = string(testOutputDir);
}
struct archive *archive;
struct archive *ext;
struct archive_entry *entry;
int r;
int flags = ARCHIVE_EXTRACT_TIME; // see https://linux.die.net/man/3/archive_write_disk for more flags
const char *filename = "data_sized.tar";
archive = archive_read_new();
ext = archive_write_disk_new();
archive_write_disk_set_options(ext, flags);
archive_read_support_format_tar(archive);
//we get the filename
if (filename != NULL && strcmp(filename, "-") == 0)
filename = NULL;
//and open the handler
if ((r = archive_read_open_filename(archive, filename, 10240)))
{
cerr<<"archive_read_open_filename: error: "<< archive_error_string(archive) <<" will abort"<< endl;
exit(1);
// fail("archive_read_open_filename()",
// archive_error_string(a), r);
}
int counter = 0;
for (;;) {
r = archive_read_next_header(archive, &entry);
if (r == ARCHIVE_EOF)
break;
if (r != ARCHIVE_OK)
{
cerr<<"archive_read_next_header: error: "<< archive_error_string(archive) <<" will abort"<< endl;
exit(1);
// fail("archive_read_next_header()",
// archive_error_string(a), 1);
}
//msg("x ");
///char *buffer = malloc (sizeof(char) * 400000);
//Mat img =Mat::zeros(1936,1456,CV_8UC3);
//new way
//std::ifstream file("img.jpg");
std::vector<char> vec;
// file >> std::noskipws;
// std::copy(std::istream_iterator<char>(file), std::istream_iterator<char>(), std::back_inserter(data));
const char *fileNamePtr = archive_entry_pathname(entry);
std::string filename(fileNamePtr,strlen(fileNamePtr) );
cout << "fileName: "<< filename <<endl;
//TODO we should test what file we have, this filenumber n = n - 1 ??
//msg(archive_entry_pathname(entry));
r = archive_write_header(ext, entry);
if (r != ARCHIVE_OK)
{
cerr<<"archive_write_header() error: "<< archive_error_string(ext)<<endl;
}
else
{
vec = copyDataInBuffer(archive);//no // we cast the data pointer to void, because we know what we do ??
if(vec.empty())
cerr << "error during load data into buffer";
r = archive_write_finish_entry(ext);
if (r != ARCHIVE_OK)
{
cerr<<"archive_write_finish_entry: error: "<< archive_error_string(ext) <<" will abort"<< endl;
exit(1);
// fail("archive_write_finish_entry()",
// archive_error_string(ext), 1);
}
}
//we read the image buffer as a jpg picture and decode it
Mat img2 = imdecode(Mat(vec), 1);
// //here we could use our image
// //we show what we got
// namedWindow( "Display window", WINDOW_AUTOSIZE );// Create a window for display.
// imshow( "Display window", img2 ); // Show our image inside it.
// cv::imwrite("foo.jpg", img2);
// //msg("\n");
if(counter > 10) exit(1);
counter ++;
// waitKey(0);
}
archive_read_close(archive);
archive_read_free(archive);
archive_write_close(ext);
archive_write_free(ext);
return 0;
}
static std::vector<char> copyDataInBuffer(struct archive *aw)
{
int r;
const void *buff;
std::vector<char> vec;
size_t size;
#if ARCHIVE_VERSION_NUMBER >= 3000000
int64_t offset;
#else
off_t offset;
#endif
// unsigned int myOffsetCounter = 0;
// int counterIteration = 0;
// ofstream myfile;
// myfile.open ("tmpPicture.jpg", ios::out | ios::binary);
// if (!myfile.is_open())
// return vec;
for (;;) {
r = archive_read_data_block(aw, &buff, &size, &offset);
if (r == ARCHIVE_EOF)
{
return vec; // everything fine, were are just at the end
}
if (r != ARCHIVE_OK)
{
cerr << "error during read archive "<<endl;
return vec;
}
//r = archive_write_data_block(aw, buff, size, offset);
//we mem copy the buffer
//cout <<counterIteration++<< " offset: "<< offset<< " size: "<< size<<endl;
//memcpy( &buffer[myOffsetCounter], (char*) buff, size * sizeof( char ) );
//we simply copy it to the end
//std::copy ( buff, buff+size, vec.end() );
//myOffsetCounter += size;
//a good discussion : https://stackoverflow.com/questions/259297/how-do-you-copy-the-contents-of-an-array-to-a-stdvector-in-c-without-looping
// Method 4: vector::insert
{
//we rename our pointer to avoid a weird compiler warning
char *foo = (char*) buff;
vec.insert(vec.end(), &foo[0], &foo[size]);
}
//myfile.write ((char*)buff,size);
// if (r != ARCHIVE_OK) {
// warn("archive_write_data_block()",
// archive_error_string(aw));
// return (r);
// }
}
//myfile.close();
return vec;
}
//static void
//msg(const char *m)
//{
// write(1, m, strlen(m));
//}
//static void
//errmsg(const char *m)
//{
// write(2, m, strlen(m));
//}
//static void
//warn(const char *f, const char *m)
//{
// errmsg(f);
// errmsg(" failed: ");
// errmsg(m);
// errmsg("\n");
//}
//static void
//fail(const char *f, const char *m, int r)
//{
// warn(f, m);
// exit(r);
//}
File moved
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment