Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
camtron
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
kr69sugu
camtron
Commits
dda824f2
Commit
dda824f2
authored
6 years ago
by
Thomas Boy
Browse files
Options
Downloads
Patches
Plain Diff
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
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Demo.cpp
+258
-226
258 additions, 226 deletions
Demo.cpp
package_bgs/ttoolbox.cpp
+53
-0
53 additions, 0 deletions
package_bgs/ttoolbox.cpp
package_bgs/ttoolbox.h
+12
-0
12 additions, 0 deletions
package_bgs/ttoolbox.h
with
323 additions
and
226 deletions
Demo.cpp
+
258
−
226
View file @
dda824f2
...
@@ -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
++
)
{
{
...
@@ -328,10 +346,10 @@ int main(int argc, char * argv[])
...
@@ -328,10 +346,10 @@ int main(int argc, char * argv[])
//we define the type better to prevent error
//we define the type better to prevent error
fileName
=
std
::
string
(
inputDir
+
TToolBox
::
getFileName
(
frameCounter
));
fileName
=
std
::
string
(
inputDir
+
TToolBox
::
getFileName
(
frameCounter
));
// //check the string
// //check the string
// cout <<"open fileName: "<< fileName<<endl;
// cout <<"open fileName: "<< fileName<<endl;
// if(fileName.empty())
// if(fileName.empty())
// cerr <<"error: empty string fileName"<<endl;
// cerr <<"error: empty string fileName"<<endl;
cout
<<
"
\t
"
<<
frameCounter
<<
"
\t
of
\t
"
<<
amountFiles
<<
" load file :"
<<
fileName
<<
endl
;
cout
<<
"
\t
"
<<
frameCounter
<<
"
\t
of
\t
"
<<
amountFiles
<<
" load file :"
<<
fileName
<<
endl
;
...
@@ -341,292 +359,306 @@ int main(int argc, char * argv[])
...
@@ -341,292 +359,306 @@ 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
();
img_input
=
imread
(
fileNameCV
,
CV_LOAD_IMAGE_COLOR
);
//we check if the image in NOT corrupted
if
(
!
TToolBox
::
checkFileCorrupted
(
fileName
))
cout
<<
" e "
<<
endl
;
if
(
img_input
.
data
)
{
{
//! we cut out a smaller ROI,
//we load the file
//! step 1)
img_input
=
imread
(
fileNameCV
,
CV_LOAD_IMAGE_COLOR
);
img_input
=
TToolBox
::
cropImageCircle
(
img_input
,
circleCenterX
,
circleCenterY
,
circleRadius
);
//! normal bgs processing
cout
<<
" e "
<<
endl
;
//! step 2)
cv
::
Mat
img_mask
;
cv
::
Mat
img_bkgmodel
;
bgs
->
process
(
img_input
,
img_mask
,
img_bkgmodel
);
// by default, it shows automatically the foreground mask image
cout
<<
" f "
<<
endl
;
if
(
img_input
.
data
)
//! 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
//TODO all parameter from applyCannyEdgeAndCalcCountours also !!
double
threshholdMin
=
150
;
double
threshholdMax
=
200
;
int
apertureSize
=
3
;
std
::
vector
<
vector
<
Point
>
>
contours
=
TToolBox
::
applyCannyEdgeAndCalcCountours
(
img_mask
,
threshholdMin
,
threshholdMax
,
apertureSize
);
//define what we will write down
std
::
vector
<
vector
<
Point
>
>
contourSelection
;
vector
<
Point2f
>
massCenters
;
vector
<
Point
>
conHull
;
Point2f
muConvexHullMassCenter
(
0.0
,
0.0
);
if
(
!
contours
.
empty
())
{
{
// //TODO: we need to order the points to get a nice polygon, otherwise not usefull
//! we cut out a smaller ROI,
// //we also try to find the aproximate polygon*****************
//! step 1)
//// vector<Point> aproxiCurve;
img_input
=
TToolBox
::
cropImageCircle
(
img_input
,
circleCenterX
,
circleCenterY
,
circleRadius
);
//! normal bgs processing
//! step 2)
cv
::
Mat
img_mask
;
cv
::
Mat
img_bkgmodel
;
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
//TODO all parameter from applyCannyEdgeAndCalcCountours also !!
double
threshholdMin
=
150
;
double
threshholdMax
=
200
;
int
apertureSize
=
3
;
std
::
vector
<
vector
<
Point
>
>
contours
=
TToolBox
::
applyCannyEdgeAndCalcCountours
(
img_mask
,
threshholdMin
,
threshholdMax
,
apertureSize
);
//define what we will write down
std
::
vector
<
vector
<
Point
>
>
contourSelection
;
vector
<
Point2f
>
massCenters
;
vector
<
Point
>
conHull
;
Point2f
muConvexHullMassCenter
(
0.0
,
0.0
);
if
(
!
contours
.
empty
())
{
// //TODO: we need to order the points to get a nice polygon, otherwise not usefull
// //we also try to find the aproximate polygon*****************
//// vector<Point> aproxiCurve;
//// // //see https://docs.opencv.org/3.4/d3/d63/classcv_1_1Mat.html#a167a8e0a3a3d86e84b70e33483af4466
//// // //see https://docs.opencv.org/3.4/d3/d63/classcv_1_1Mat.html#a167a8e0a3a3d86e84b70e33483af4466
//// // if(aproxiCurve::checkVector(10,CV_32F)==-1)
//// // if(aproxiCurve::checkVector(10,CV_32F)==-1)
//// // cout<<"error wrong format of vector"<<endl;
//// // cout<<"error wrong format of vector"<<endl;
//// //calc 0.1 percent of arc length of convex hull
//// //calc 0.1 percent of arc length of convex hull
//// double epsilon = 0.1 * cv::arcLength(hullComplete,true);
//// double epsilon = 0.1 * cv::arcLength(hullComplete,true);
//// //see https://docs.opencv.org/2.4.13.2/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html#approxpolydp
//// //see https://docs.opencv.org/2.4.13.2/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html#approxpolydp
//// cv::approxPolyDP(allContourPoints,aproxiCurve,epsilon,false);
//// cv::approxPolyDP(allContourPoints,aproxiCurve,epsilon,false);
////#ifdef MC_SHOW_STEP_ANALYSE
////#ifdef MC_SHOW_STEP_ANALYSE
//// if(aproxiCurve.size()>=2)//we only draw if we have at least a line
//// if(aproxiCurve.size()>=2)//we only draw if we have at least a line
//// {
//// {
//// Mat imgPolyApr = Mat::zeros( img_input.size(), CV_8UC3 );
//// Mat imgPolyApr = Mat::zeros( img_input.size(), CV_8UC3 );
//// imgPolyApr = Scalar(255,255,255); //fille the picture
//// imgPolyApr = Scalar(255,255,255); //fille the picture
//// Scalar colorC( 0,0,255,255 );//red
//// Scalar colorC( 0,0,255,255 );//red
//// //for(imgPolyApr)
//// //for(imgPolyApr)
//// polylines(imgPolyApr, aproxiCurve, true, colorC, 1, 8);
//// polylines(imgPolyApr, aproxiCurve, true, colorC, 1, 8);
//// cv::String outpath3= "/homes/tb55xemi/work/bugTrainingSet/testRec/rec04379437pp/result/";
//// cv::String outpath3= "/homes/tb55xemi/work/bugTrainingSet/testRec/rec04379437pp/result/";
//// std::ostringstream convert3;
//// std::ostringstream convert3;
//// convert3 << outpath3 << frameCounter <<"_appr_poly.jpg";
//// convert3 << outpath3 << frameCounter <<"_appr_poly.jpg";
//// cv::imwrite(convert3.str().c_str(), imgPolyApr);
//// cv::imwrite(convert3.str().c_str(), imgPolyApr);
//// }
//// }
//// else
//// else
//// cout<<"approximate poly has not enough points will skip file: "<<frameCounter<<endl;
//// cout<<"approximate poly has not enough points will skip file: "<<frameCounter<<endl;
////#endif
////#endif
//! step 4) we make a selection out of all counters with area sizes******************************
//! step 4) we make a selection out of all counters with area sizes******************************
//we calc all min rotated rectangles for all contour from candy egde detect
//we calc all min rotated rectangles for all contour from candy egde detect
//we exlcude very small one and very big ones
//we exlcude very small one and very big ones
vector
<
RotatedRect
>
minRect
(
contours
.
size
()
);
vector
<
RotatedRect
>
minRect
(
contours
.
size
()
);
//calc boxes around the contours
//calc boxes around the contours
for
(
size_t
i
=
0
;
i
<
contours
.
size
();
i
++
)
for
(
size_t
i
=
0
;
i
<
contours
.
size
();
i
++
)
minRect
[
i
]
=
minAreaRect
(
Mat
(
contours
[
i
])
);
//may use boundingRect ?? to use fix non rotated rectangles ?
minRect
[
i
]
=
minAreaRect
(
Mat
(
contours
[
i
])
);
//may use boundingRect ?? to use fix non rotated rectangles ?
vector
<
Point2f
>
recCenterPoints
;
vector
<
Point2f
>
recCenterPoints
;
float
areaMinThreshold
=
150
;
float
areaMinThreshold
=
150
;
float
areaMaxThreshold
=
300000
;
//old max threshold was to small //TODO apply moving filter ??, an more adaptive approach
float
areaMaxThreshold
=
300000
;
//old max threshold was to small //TODO apply moving filter ??, an more adaptive approach
cout
<<
" g "
<<
endl
;
cout
<<
" g "
<<
endl
;
//iterate all rectangles
//iterate all rectangles
for
(
size_t
i
=
0
;
i
<
minRect
.
size
();
i
++
)
for
(
size_t
i
=
0
;
i
<
minRect
.
size
();
i
++
)
{
Point2f
rect_points
[
4
];
//get all points of the retange
minRect
[
i
].
points
(
rect_points
);
//construct contour based on rectangle points because contour != rectangle with points
vector
<
Point
>
contourRect
;
for
(
int
j
=
0
;
j
<
4
;
j
++
)
contourRect
.
push_back
(
rect_points
[
j
]);
//calc the area of the contour
double
area0
=
contourArea
(
contourRect
);
//over stepp all small areas
if
(
area0
<
areaMinThreshold
||
area0
>
areaMaxThreshold
)
{
{
//cout<<i<<":area0:"<<area0<<" dismissed "<<endl;
Point2f
rect_points
[
4
];
//skipe if the area is too small
//get all points of the retange
continue
;
minRect
[
i
].
points
(
rect_points
);
}
else
//construct contour based on rectangle points because contour != rectangle with points
{
vector
<
Point
>
contourRect
;
//cout<<i<<":area0:"<<area0<<" choose "<<endl;
for
(
int
j
=
0
;
j
<
4
;
j
++
)
contourRect
.
push_back
(
rect_points
[
j
]);
//get the center of this rectangle
Point2f
center
=
minRect
[
i
].
center
;
//calc the area of the contour
recCenterPoints
.
push_back
(
center
);
double
area0
=
contourArea
(
contourRect
);
//over stepp all small areas
if
(
area0
<
areaMinThreshold
||
area0
>
areaMaxThreshold
)
{
//cout<<i<<":area0:"<<area0<<" dismissed "<<endl;
//skipe if the area is too small
continue
;
}
else
{
//cout<<i<<":area0:"<<area0<<" choose "<<endl;
//we also add the this contour to a selection
//get the center of this rectangle
contourSelection
.
push_back
(
contours
[
i
]);
Point2f
center
=
minRect
[
i
].
center
;
recCenterPoints
.
push_back
(
center
);
}
//we also add the this contour to a selection
}
//end iterate all min rectangle
contourSelection
.
push_back
(
contours
[
i
]);
if
(
!
contourSelection
.
empty
())
}
{
}
//end iterate all min rectangle
//! step 5) we calc the moments from the contour selection
vector
<
Moments
>
mu
(
contourSelection
.
size
()
);
for
(
size_t
i
=
0
;
i
<
contourSelection
.
size
();
i
++
)
{
mu
[
i
]
=
moments
(
contourSelection
[
i
],
false
);
}
// Get the mass centers:
if
(
!
contourSelection
.
empty
())
massCenters
=
vector
<
Point2f
>
(
contourSelection
.
size
()
);
for
(
size_t
i
=
0
;
i
<
contourSelection
.
size
();
i
++
)
{
{
massCenters
[
i
]
=
Point2f
(
mu
[
i
].
m10
/
mu
[
i
].
m00
,
mu
[
i
].
m01
/
mu
[
i
].
m00
);
//! step 5) we calc the moments from the contour selection
}
vector
<
Moments
>
mu
(
contourSelection
.
size
()
);
for
(
size_t
i
=
0
;
i
<
contourSelection
.
size
();
i
++
)
{
mu
[
i
]
=
moments
(
contourSelection
[
i
],
false
);
}
//! step 6) calc convex hull of all points of the contour selection *********
// Get the mass centers:
//TODO produce center of convex hull of all polygones
massCenters
=
vector
<
Point2f
>
(
contourSelection
.
size
()
);
//TODO double check if ne contour sharing a center point ? nearby ??
for
(
size_t
i
=
0
;
i
<
contourSelection
.
size
();
i
++
)
{
massCenters
[
i
]
=
Point2f
(
mu
[
i
].
m10
/
mu
[
i
].
m00
,
mu
[
i
].
m01
/
mu
[
i
].
m00
);
}
//we merge all points
//! step 6) calc convex hull of all points of the contour selection *********
vector
<
Point
>
allContourPoints
;
//TODO produce center of convex hull of all polygones
for
(
size_t
cC
=
0
;
cC
<
contourSelection
.
size
();
++
cC
)
//TODO double check if ne contour sharing a center point ? nearby ??
for
(
size_t
cP
=
0
;
cP
<
contourSelection
[
cC
].
size
();
cP
++
)
//we merge all points
vector
<
Point
>
allContourPoints
;
for
(
size_t
cC
=
0
;
cC
<
contourSelection
.
size
();
++
cC
)
for
(
size_t
cP
=
0
;
cP
<
contourSelection
[
cC
].
size
();
cP
++
)
{
Point
currentContourPixel
=
contourSelection
[
cC
][
cP
];
allContourPoints
.
push_back
(
currentContourPixel
);
}
// calc the hull ******************
conHull
=
vector
<
Point
>
(
allContourPoints
.
size
());
convexHull
(
Mat
(
allContourPoints
),
conHull
,
false
);
// Point roiCenter;
// float roiRadius;
//calc the min circle around
//minEnclosingCircle(conHull,roiCenter,roiRadius);
//we calc the mass center of the convex hull
///we calc the mass center of the convex hull
Moments
muConvexHull
;
if
(
!
conHull
.
empty
())
{
{
Point
currentContourPixel
=
contourSelection
[
cC
][
cP
]
;
muConvexHull
=
moments
(
conHull
,
true
)
;
allContourPoints
.
push_back
(
currentContourPixel
);
muConvexHullMassCenter
=
Point2f
(
muConvexHull
.
m10
/
muConvexHull
.
m00
,
muConvexHull
.
m01
/
muConvexHull
.
m00
);
}
}
// calc the hull ******************
cout
<<
" h "
<<
endl
;
conHull
=
vector
<
Point
>
(
allContourPoints
.
size
());
convexHull
(
Mat
(
allContourPoints
),
conHull
,
false
);
// Point roiCenter;
// float roiRadius;
//calc the min circle around
//minEnclosingCircle(conHull,roiCenter,roiRadius);
//we calc the mass center of the convex hull
///we calc the mass center of the convex hull
}
//end after selection is empty
Moments
muConvexHull
;
if
(
!
conHull
.
empty
())
{
{
muConvexHull
=
moments
(
conHull
,
true
)
;
cerr
<<
"error, no contour found after selection in file: "
<<
fileName
<<
endl
;
m
uConvexHullMassCenter
=
Point2f
(
muConvexHull
.
m10
/
muConvexHull
.
m00
,
muConvexHull
.
m01
/
muConvexHull
.
m00
);
m
yFileListAfterContourSelection
.
push_back
(
fileName
);
}
}
}
//end if contours are empty, to canny edge found nothing
cout
<<
" h "
<<
endl
;
else
}
//end after selection is empty
{
{
cerr
<<
"error, no contour found after selection in file: "
<<
fileName
<<
endl
;
cerr
<<
"error, no contour found at all in file: "
<<
fileName
<<
endl
;
myFileListAfterContourSelection
.
push_back
(
fileName
);
myFileListNoContour
.
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
;
myFileListNoContour
.
push_back
(
fileName
);
}
}
#ifdef MC_SHOW_STEP_ANALYSE
#ifdef MC_SHOW_STEP_ANALYSE
if
(
!
conHull
.
empty
())
//if we any elements, we process further
if
(
!
conHull
.
empty
())
//if we any elements, we process further
{
{
Mat
imgConvexHull
=
Mat
::
zeros
(
img_input
.
size
(),
CV_8UC3
);
Mat
imgConvexHull
=
Mat
::
zeros
(
img_input
.
size
(),
CV_8UC3
);
imgConvexHull
=
Scalar
(
255
,
255
,
255
);
//fille the picture
imgConvexHull
=
Scalar
(
255
,
255
,
255
);
//fille the picture
Scalar
colorB
(
0
,
0
,
255
,
255
);
//red
Scalar
colorB
(
0
,
0
,
255
,
255
);
//red
polylines
(
imgConvexHull
,
hullComplete
,
true
,
colorB
,
1
,
8
);
polylines
(
imgConvexHull
,
hullComplete
,
true
,
colorB
,
1
,
8
);
//draw circle around
//draw circle around
//circle( imgConvexHull, roiCenter, (int) roiRadius, colorB, 2, 8, 0 );
//circle( imgConvexHull, roiCenter, (int) roiRadius, colorB, 2, 8, 0 );
//we draw it
//we draw it
cv
::
String
outpath2
=
outputDir
;
cv
::
String
outpath2
=
outputDir
;
std
::
ostringstream
convert2
;
std
::
ostringstream
convert2
;
convert2
<<
outpath2
<<
TToolBox
::
mNzero
(
frameCounter
)
<<
"_convex_hull.jpg"
;
convert2
<<
outpath2
<<
TToolBox
::
mNzero
(
frameCounter
)
<<
"_convex_hull.jpg"
;
cv
::
imwrite
(
convert2
.
str
().
c_str
(),
imgConvexHull
);
cv
::
imwrite
(
convert2
.
str
().
c_str
(),
imgConvexHull
);
}
}
else
else
cout
<<
"convex hull has no points will skip file: "
<<
i
<<
endl
;
cout
<<
"convex hull has no points will skip file: "
<<
i
<<
endl
;
#endif
#endif
cout
<<
" i "
<<
endl
;
cout
<<
" i "
<<
endl
;
//cout<<"we try to write file: "<< i <<endl;
//cout<<"we try to write file: "<< i <<endl;
//! step 8: we write down all our results in yml file
//! step 8: we write down all our results in yml file
std
::
string
nameOutPutFileData
=
outputDir
+
TToolBox
::
mNzero
(
frameCounter
)
+
".yml"
;
std
::
string
nameOutPutFileData
=
outputDir
+
TToolBox
::
mNzero
(
frameCounter
)
+
".yml"
;
cout
<<
" j "
<<
endl
;
cout
<<
" j "
<<
endl
;
// //check the string
// //check the string
// cout <<"write output nameOutPutFileData: "<< nameOutPutFileData<<endl;
// cout <<"write output nameOutPutFileData: "<< nameOutPutFileData<<endl;
// if(nameOutPutFileData.empty())
// if(nameOutPutFileData.empty())
// cerr <<"error: empty string nameOutPutFileData"<<endl;
// cerr <<"error: empty string nameOutPutFileData"<<endl;
FileStorage
fs
(
nameOutPutFileData
.
c_str
(),
FileStorage
::
WRITE
);
FileStorage
fs
(
nameOutPutFileData
.
c_str
(),
FileStorage
::
WRITE
);
fs
<<
"masscenters"
<<
massCenters
;
fs
<<
"masscenters"
<<
massCenters
;
fs
<<
"polygonselection"
<<
contourSelection
;
fs
<<
"polygonselection"
<<
contourSelection
;
fs
<<
"convexhull"
<<
conHull
;
fs
<<
"convexhull"
<<
conHull
;
fs
<<
"masscenterconvexhull"
<<
muConvexHullMassCenter
;
fs
<<
"masscenterconvexhull"
<<
muConvexHullMassCenter
;
fs
.
release
();
fs
.
release
();
cout
<<
" k "
<<
endl
;
cout
<<
" k "
<<
endl
;
//! we write from time to time a dbg picture
//! we write from time to time a dbg picture
if
(
frameCounter
%
everyPic
==
0
)
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
for
(
size_t
i
=
0
;
i
<
contourSelection
.
size
();
i
++
)
{
{
//random color
Scalar
colorRed
(
0
,
0
,
255
,
255
);
//red
Scalar
color
=
Scalar
(
rng
.
uniform
(
0
,
255
),
rng
.
uniform
(
0
,
255
),
rng
.
uniform
(
0
,
255
)
);
RNG
rng
(
4344234
);
//contour
Mat
imgDebugPaint2
=
Mat
::
zeros
(
img_input
.
size
(),
CV_8UC3
);
drawContours
(
imgDebugPaint2
,
contourSelection
,
i
,
color
,
1
,
LINE_AA
);
imgDebugPaint2
=
Scalar
(
255
,
255
,
255
);
//fill the picture white
//draw the center
circle
(
imgDebugPaint2
,
massCenters
[
i
],
4
,
color
,
-
1
,
8
,
0
);
}
//we write the convex hull
//we write all polyies of the selection and the mass centers with a random color
if
(
!
conHull
.
empty
())
for
(
size_t
i
=
0
;
i
<
contourSelection
.
size
();
i
++
)
{
{
//the poly
//random color
polylines
(
imgDebugPaint2
,
conHull
,
true
,
colorRed
,
1
,
8
);
Scalar
color
=
Scalar
(
rng
.
uniform
(
0
,
255
),
rng
.
uniform
(
0
,
255
),
rng
.
uniform
(
0
,
255
)
);
//the center
//contour
circle
(
imgDebugPaint2
,
muConvexHullMassCenter
,
4
,
colorRed
,
-
1
,
8
,
0
);
drawContours
(
imgDebugPaint2
,
contourSelection
,
i
,
color
,
1
,
LINE_AA
);
}
//draw the center
circle
(
imgDebugPaint2
,
massCenters
[
i
],
4
,
color
,
-
1
,
8
,
0
);
}
//we make a copy
//we write the convex hull
Mat
imgOverlay2
=
img_input
.
clone
();
if
(
!
conHull
.
empty
())
//we add a overlay of our paitings
{
addWeighted
(
imgDebugPaint2
,
0.7
,
imgOverlay2
,
0.3
,
0.0
,
imgOverlay2
);
//the poly
//we write the file down
polylines
(
imgDebugPaint2
,
conHull
,
true
,
colorRed
,
1
,
8
);
std
::
string
nameOutPutFileDBGpic
=
outputDir
+
TToolBox
::
mNzero
(
frameCounter
)
+
std
::
string
(
".jpg"
);
//the center
circle
(
imgDebugPaint2
,
muConvexHullMassCenter
,
4
,
colorRed
,
-
1
,
8
,
0
);
}
//we make a copy
Mat
imgOverlay2
=
img_input
.
clone
();
//we add a overlay of our paitings
addWeighted
(
imgDebugPaint2
,
0.7
,
imgOverlay2
,
0.3
,
0.0
,
imgOverlay2
);
//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
);
// //check the string
cout
<<
" l "
<<
endl
;
// cout <<"write dbg file: "<< nameOutPutFileDBGpic<<endl;
}
//end if we write a dbg picture
// if(nameOutPutFileDBGpic.empty())
// cerr <<"error: empty string nameOutPutFileDBGpic"<<endl;
imwrite
(
nameOutPutFileDBGpic
.
c_str
(),
imgOverlay2
);
cout
<<
" l "
<<
endl
;
}
//end if the loaded picture has data
else
{
cerr
<<
"error loading file: "
<<
fileName
<<
", will skip this file"
<<
endl
;
myFileErrorList
.
push_back
(
fileName
);
}
}
}
//end if
the load
ed picture
has data
}
//end if
not corrupt
ed picture
else
else
{
{
cerr
<<
"error loading file: "
<<
fileName
<<
", will skip this file"
<<
endl
;
cout
<<
"error file: "
<<
fileName
<<
" is corrupted, will ignore it"
<<
endl
;
myFileErrorList
.
push_back
(
fileName
);
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
;
...
...
This diff is collapsed.
Click to expand it.
package_bgs/ttoolbox.cpp
+
53
−
0
View file @
dda824f2
...
@@ -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
;
}
This diff is collapsed.
Click to expand it.
package_bgs/ttoolbox.h
+
12
−
0
View file @
dda824f2
...
@@ -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
);
};
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment