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

.

parent b35d87f9
Branches
No related tags found
No related merge requests found
......@@ -7,7 +7,7 @@
],
"settings":
{
"tab_size": 8,
"tab_size": 3,
// "cmake":
// {
// "build_folder": "$folder/build",
......
......@@ -32,6 +32,8 @@ using namespace bgslibrary::algorithms;
using namespace cv;
using namespace std;
Scalar color_red( 0,0,255,255 );
int g_badSignalFlagAbort = 0;
void my_handler(int signum);
......@@ -50,7 +52,7 @@ int main(int argc, char * argv[])
signal(SIGUSR1, my_handler);
cout << "Using OpenCV " << CV_MAJOR_VERSION << "." << CV_MINOR_VERSION << "." << CV_SUBMINOR_VERSION << endl;
cout << "Using processcenter " << PROCESS_CENTER_VERSION_MAJOR << "." << PROCESS_CENTER_VERSION_MINOR<< "." <<PROCESS_CENTER_VERSION_MINOR_FIXES<< endl << endl;
cout << "Using processcenter " << PROCESS_CENTER_VERSION_MAJOR << "." << PROCESS_CENTER_VERSION_MINOR << "." << PROCESS_CENTER_VERSION_MINOR_FIXES << endl << endl;
//!** parse programm input****************/
......@@ -116,7 +118,7 @@ int main(int argc, char * argv[])
}
cout << "args: -i " <<inputFile<< " -a " <<amountFiles << " -c" << centerFileString<< " -o " << outputDir << " -p " << cameraParameterFile << endl;
cout << "args: -i " << inputFile << " -a " << amountFiles << " -c" << centerFileString << " -o " << outputDir << " -p " << cameraParameterFile << endl;
//!**** end parse input***********/
//libarchive things
......@@ -141,7 +143,7 @@ int main(int argc, char * argv[])
//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;
cerr << "archive_read_open_filename: error: " << archive_error_string(archive) << " will abort" << endl;
exit(1);
}
......@@ -185,6 +187,7 @@ int main(int argc, char * argv[])
cv::String configFileNameCenter(centerFileString);
//read the config
cout << "parameter of centerConfigFile.xml" << endl;
FileStorage fsCen;
fsCen.open(configFileNameCenter, FileStorage::READ);
if (!fsCen.isOpened())
......@@ -204,6 +207,10 @@ int main(int argc, char * argv[])
fsCen.release();
cout << "here" << endl;
system("pause");
//open camera config file
cv::String camParam (cameraParameterFile);
Mat intrinsicsCameraMatrix, distortionCoeff;
......@@ -229,8 +236,6 @@ int main(int argc, char * argv[])
cout << "distortion_coefficients = " << distortionCoeff << endl;
}
cout.flush();
cout << "a) we process all frames " << endl;
int everyPic= 60*5;
......@@ -242,13 +247,13 @@ int main(int argc, char * argv[])
vector<string> myFileListNoContour; //list for no contours found;
vector<string> myFileListAfterContourSelection; //list for no contours found after selection;
cout << "here" << endl;
system("pause");
//loop over all picture of the tar archive, independing how many this are
//loop over _all_ picture of the tar archive
for (;;)
{
//measure time consumption
//sa opencv tick timer:
// https://docs.opencv.org/4.x/d9/d6f/classcv_1_1TickMeter.html#details
clock_t begin = clock(); //for every single file
vector<char> vec;
......@@ -266,7 +271,7 @@ int main(int argc, char * argv[])
// get filename
const char *fileNamePtr = archive_entry_pathname(entry);
string filename(fileNamePtr,strlen(fileNamePtr) );
//cout << "fileName: " << filename <<endl;
//cout << "fileName: " << filename << endl;
// convert it to a framenumber
frameCounter = toFrameNumber(filename);
......@@ -281,7 +286,7 @@ int main(int argc, char * argv[])
r = archive_write_header(ext, entry);
if (r != ARCHIVE_OK)
{
cerr<< "archive_write_header() error: " << archive_error_string(ext)<<endl;
cerr << "archive_write_header() error: " << archive_error_string(ext)<< endl;
myFileTarWriterHeaderCounter++;
continue; //we overjump all in our for loop
}
......@@ -293,7 +298,7 @@ int main(int argc, char * argv[])
r = archive_write_finish_entry(ext);
if (r != ARCHIVE_OK)
{
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);
}
......@@ -376,13 +381,13 @@ int main(int argc, char * argv[])
//over stepp all small areas
if(area0<areaMinThreshold||area0>areaMaxThreshold)
{
//cout<<i<< ":area0:" <<area0<< " dismissed " <<endl;
//cout << i << ":area0:" << area0 << " dismissed " << endl;
//skipe if the area is too small
continue;
}
else
{
//cout<<i<< ":area0:" <<area0<< " choose " <<endl;
//cout << i << ":area0:" << area0 << " choose " << endl;
//get the center of this rectangle
Point2f center = minRect[i].center;
......@@ -438,18 +443,18 @@ int main(int argc, char * argv[])
if(!conHull.empty())
{
muConvexHull = moments(conHull, true );
muConvexHullMassCenter= Point2f( muConvexHull.m10/muConvexHull.m00 , muConvexHull.m01/muConvexHull.m00 );
muConvexHullMassCenter = Point2f( muConvexHull.m10/muConvexHull.m00 , muConvexHull.m01/muConvexHull.m00 );
}
}
else //end after selection is empty
{
cerr<< "error, no contour found after selection in file: " << filename<<endl;
cerr << "error, no contour found after selection in file: " << filename << endl;
myFileListAfterContourSelection.push_back(filename);
}
}//end if contours are empty, to canny edge found nothing
else
{
cerr<< "error, no contour found at all in file: " << filename<<endl;
cerr << "error, no contour found at all in file: " << filename << endl;
myFileListNoContour.push_back(filename);
}
......@@ -458,26 +463,25 @@ int main(int argc, char * argv[])
if(!conHull.empty())//if we any elements, we process further
{
Mat imgConvexHull = Mat::zeros( img_input.size(), CV_8UC3 );
imgConvexHull = Scalar(255,255,255); //fille the picture
imgConvexHull = Scalar(255,255,255); //fill the picture
Scalar colorB( 0,0,255,255 );//red
polylines(imgConvexHull, hullComplete, true, colorB, 1, 8);
polylines(imgConvexHull, hullComplete, true, color_red, 1, 8);
//draw circle around
//circle( imgConvexHull, roiCenter, (int) roiRadius, colorB, 2, 8, 0 );
//circle( imgConvexHull, roiCenter, (int) roiRadius, color_red, 2, 8, 0 );
//we draw it
cv::String outpath2= outputDir;
cv::String outpath2 = outputDir;
ostringstream convert2;
convert2 << outpath2 << TToolBox::mNzero(frameCounter) << "_convex_hull.jpg";
cv::imwrite(convert2.str().c_str(), imgConvexHull);
}
else
cout<< "convex hull has no points will skip file: " << i<< endl;
cout << "convex hull has no points will skip file: " << i << endl;
#endif
//cout << " found center at : " << massCenters.at(0).x<< ";" << massCenters.at(0).y<< endl;
//cout << " found center at : " << massCenters.at(0).x << ";" << massCenters.at(0).y << endl;
//! step 8: we write down all our results in yml file
string nameOutPutFileData = outputDir + TToolBox::mNzero(frameCounter) + ".yml";
......@@ -493,12 +497,11 @@ int main(int argc, char * argv[])
//! occasionaly write a dbg picture
if(frameCounter%everyPic==0)
{
Scalar colorRed( 0,0,255,255 );//red
RNG rng(4344234);
Mat imgDebugPaint2 = Mat::zeros( img_input.size(), CV_8UC3 );
imgDebugPaint2 = Scalar(255,255,255); //fill the picture white
//we write all polyies of the selection and the mass centers with a random color
// write all polyies of the selection and the mass centers with a random color
for( size_t i = 0; i< contourSelection.size(); i++ )
{
//random color
......@@ -513,9 +516,9 @@ int main(int argc, char * argv[])
if(!conHull.empty())
{
//the poly
polylines(imgDebugPaint2, conHull, true, colorRed, 1, 8);
polylines(imgDebugPaint2, conHull, true, color_red, 1, 8);
//the center
circle( imgDebugPaint2,muConvexHullMassCenter, 4, colorRed, -1, 8, 0 );
circle( imgDebugPaint2,muConvexHullMassCenter, 4, color_red, -1, 8, 0 );
}
// copy
......@@ -533,7 +536,7 @@ int main(int argc, char * argv[])
}//end if the loaded picture has data
else
{
cerr<< "error loading file: " << filename<< ", will skip this file" << endl;
cerr << "error loading file: " << filename << ", will skip this file" << endl;
myFileErrorList.push_back(filename);
}
......@@ -545,10 +548,10 @@ int main(int argc, char * argv[])
//calc the time which was used for all pictures
clock_t endAll = clock();
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;
if(g_badSignalFlagAbort)
frameCounter = amountFiles; //we abort
frameCounter = amountFiles; // abort
//if(frameCounter>10)exit(0); //the test abort function
......@@ -557,7 +560,7 @@ int main(int argc, char * argv[])
//finishing time
clock_t endAll = clock();
double elapsed = double(endAll - beginAll) / CLOCKS_PER_SEC;
cout << "process : " << amountFiles<< " files took:\t" << (int)(elapsed/60)<< " min -\t" << (int)(elapsed/60/60)<< " h \n in total" << endl;
cout << "process : " << amountFiles << " files took:\t" << (int)(elapsed/60)<< " min -\t" << (int)(elapsed/60/60)<< " h \n in total" << endl;
// //we write the random file list to a file
// string nameOutRandomFile = outputDir + "randlist.yml";
......@@ -567,7 +570,7 @@ int main(int argc, char * argv[])
//TODO we should merge the file
cout<< "amount of libarchive read header errors :" << myFileTarWriterHeaderCounter;
cout << "amount of libarchive read header errors :" << myFileTarWriterHeaderCounter;
// write the random file list to a file
string nameOutErrorList = outputDir + "fileErrorList.yml";
......
This diff is collapsed.
point2f(y,x) # inverted!
BGR #not rgb ...
Scalar = 4 element vector
CV_RGB(r, g, b) #from bgs
Types:
#depth
......@@ -10,27 +14,67 @@ Types:
CV_32F float
CV_64F double
# + channels C1..4 eg RGBA:
# eg Mat M(2,2, CV_8UC3, Scalar(0,0,255));
0 to 255 for CV_8U images
0 to 65535 for CV_16U images
0 to 1 for CV_32F images
Camera Calibration:
distortion_coefficients - 5 values
camera_matrix - 3x3 matrix - eg focal length etc.
might need to calibrate using chess board, to get values
sa
https://github.com/abidrahmank/OpenCV2-Python-Tutorials/blob/master/source/py_tutorials/py_calib3d/py_calibration/py_calibration.rst
different methods:
https://docs.opencv.org/4.x/d7/d21/tutorial_interactive_calibration.html
https://docs.opencv.org/4.x/d6/d55/tutorial_table_of_content_calib3d.html
# using chess board, to get values
https://github.com/abidrahmank/OpenCV2-Python-Tutorials/blob/master/source/py_tutorials/py_calib3d/py_calibration/py_calibration.rs
roi - region of interest
x, y, w, h
// roi as subset of full data image
Mat D (A, Rect(10, 10, 100, 100) ); // using a rectangle
Mat E = A(Range::all(), Range(1,3)); // using row and column boundaries
Matrix
Fill matrix with random values
Mat R = Mat(3, 2, CV_8UC3);
randu(R, Scalar::all(0), Scalar::all(255));
Formatted output
cout << "R (csv) = " << endl << format(R, Formatter::FMT_CSV ) << endl << endl;
#sa FMT_C/PYTHON/NUMPY/CSV
MISC
glob( dir, file )
CommandLineParser
randu() # https://docs.opencv.org/4.x/d2/de8/group__core__array.html#ga1ba1026dca0807b27057ba6a49d258c0
cvtColor(img, img, COLOR_BGR2Luv); #convert color
roi - region of interest - x, y, w, h
BS:
https://docs.opencv.org/4.x/da/d5c/tutorial_canny_detector.html
https://docs.opencv.org/4.x/d1/dc5/tutorial_background_subtraction.html
https://web.archive.org/web/20140418093037/http://bmc.univ-bpclermont.fr/
https://web.archive.org/web/20140221195750/http://docs.opencv.org/trunk/doc/tutorials/video/background_subtraction/background_subtraction.html
https://www.pyimagesearch.com/2020/07/27/opencv-grabcut-foreground-segmentation-and-extraction/
https://learnopencv.com/applications-of-foreground-background-separation-with-semantic-segmentation/
https://docs.opencv.org/4.x/d2/d55/group__bgsegm.html
https://docs.opencv.org/4.x/d5/de8/samples_2cpp_2segment_objects_8cpp-example.html#_a15
tuts:))
https://docs.opencv.org/4.x/d6/d00/tutorial_py_root.html
https://datahacker.rs/opencv-thresholding/
# median frame as bg + frame difference
https://learnopencv.com/simple-background-estimation-in-videos-using-opencv-c-python/
https://learnopencv.com/contour-detection-using-opencv-python-c/
https://learnopencv.com/deep-learning-with-opencvs-dnn-module-a-definitive-guide/
moments
https://docs.opencv.org/4.x/d0/d49/tutorial_moments.html
#include "ttoolbox.h"
/*
http://docs.opencv.org/2.4/doc/tutorials/imgproc/gausian_median_blur_bilateral_filter/gausian_median_blur_bilateral_filter.html
https://learnopencv.com/edge-detection-using-opencv/
https://learnopencv.com/contour-detection-using-opencv-python-c/
*/
std::string TToolBox::mNzero(int i)
{
std::ostringstream convert;
......@@ -10,37 +14,36 @@ std::string TToolBox::mNzero(int i)
}
std::string TToolBox::getFileName(int i)
{
std::string fileName =std::string ( std::string ("/data/")+ mNzero(i) + std::string (".jpg"));
std::string fileName = std::string ( std::string ("/data/") + mNzero(i) + std::string (".jpg"));
return fileName;
}
std::vector<std::vector<cv::Point>> TToolBox::applyCannyEdgeAndCalcCountours(cv::Mat imgSource, double threshholdMin, double threshholdMax, int apertureSize)
{
cv::Mat imgCannyEdge;
std::vector<std::vector<cv::Point> > contours;
std::vector<cv::Vec4i> hierarchy;
//TODO: check if clone is necessary or if it wastes ressources by doing unneccessary copies of frames
//! 2 make a copy
//! make a copy
cv::Mat imgBinary = imgSource.clone();
//imgMarkBinary = Scalar(255,255,255); //fill white
//! 3 apply binary filter not reduce noise
//method to threshold important changes
//! apply binary filter not reduce noise
// > method to threshold important changes
int binaryThreshold = 80; //TODO as parameter
imgBinary = imgSource > binaryThreshold;
//! 4 smooth with gaussian filter to suppress no connected lines
//add a gaussian filter //see http://docs.opencv.org/2.4/doc/tutorials/imgproc/gausian_median_blur_bilateral_filter/gausian_median_blur_bilateral_filter.html
//! smooth with gaussian filter to suppress no connected lines
//add a gaussian filter
cv::Mat imgSmoothed = imgBinary.clone();
int exclusPara3 = 3; //TODO as parameter
cv::GaussianBlur(imgBinary,imgSmoothed,cv::Size(exclusPara3,exclusPara3),0); //0 = BORDER_CONSTANT
//! 5 we make the canny edge detect
// Detect edges using canny
//! detect edges using canny
cv::Mat imgCannyEdge;
cv::Canny( imgSmoothed, imgCannyEdge, threshholdMin, threshholdMax, apertureSize );
// Find contours, use RETR_EXTERNAL ignore inner child structures, TREE more usefull ?
//! find contours
// use RETR_EXTERNAL ignore inner child structures, TREE more useful ?
std::vector<std::vector<cv::Point> > contours;
std::vector<cv::Vec4i> hierarchy;
cv::findContours( imgCannyEdge, contours, hierarchy, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_SIMPLE, cv::Point(0, 0) );
#define MC_SHOW_STEP_ANALYSE
......@@ -65,7 +68,6 @@ std::vector<std::vector<cv::Point>> TToolBox::applyCannyEdgeAndCalcCountours(cv:
#endif
// return minRect;
return contours;
}
......@@ -73,7 +75,7 @@ std::vector<std::vector<cv::Point>> TToolBox::applyCannyEdgeAndCalcCountours(cv:
cv::Mat TToolBox::cropImageCircle(cv::Mat image, int x, int y, int r)
{
// Your Hough circle
// Hough circle
cv::Vec3f circ(x,y,r);
// Draw the mask: white circle on black background
......@@ -87,7 +89,7 @@ cv::Mat TToolBox::cropImageCircle(cv::Mat image, int x, int y, int r)
// Create a black image
cv::Mat res = cv::Mat::zeros( image.size(), CV_8UC3 );
res = cv::Scalar(0,0,0); //fill with black color
res = cv::Scalar(0,0,0); //fill with black color //needed? isnt it initd with zeros above?
// Copy only the image under the white circle to black image
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment