Merge remote-tracking branch 'upstream/3.4' into merge-3.4

This commit is contained in:
Alexander Alekhin
2020-07-28 17:15:02 +00:00
13 changed files with 237 additions and 61 deletions
+1 -3
View File
@@ -74,9 +74,7 @@ void mouseHandler(int event, int x, int y, int, void*)
final = Mat::zeros(src.size(), CV_8UC3);
mask = Mat::zeros(src.size(), CV_8UC1);
vector<vector<Point> > vpts;
vpts.push_back(pts);
fillPoly(mask, vpts, Scalar(255, 255, 255), 8, 0);
fillPoly(mask, pts, Scalar(255, 255, 255), 8, 0);
bitwise_and(src, src, final, mask);
imshow("Mask", mask);
imshow("Result", final);
+1 -3
View File
@@ -50,9 +50,7 @@ static float drawIntersection(Mat &image, vector<Point> polygon1, vector<Point>
{
fillColor = Scalar(0, 0, 255);
}
vector<vector<Point> > pp;
pp.push_back(intersectionPolygon);
fillPoly(image, pp, fillColor);
fillPoly(image, intersectionPolygon, fillColor);
}
polylines(image, polygons, true, Scalar(0, 0, 0));
+4 -18
View File
@@ -121,21 +121,6 @@ static void findSquares( const Mat& image, vector<vector<Point> >& squares )
}
}
// the function draws all the squares in the image
static void drawSquares( Mat& image, const vector<vector<Point> >& squares )
{
for( size_t i = 0; i < squares.size(); i++ )
{
const Point* p = &squares[i][0];
int n = (int)squares[i].size();
polylines(image, &p, &n, 1, true, Scalar(0,255,0), 3, LINE_AA);
}
imshow(wndname, image);
}
int main(int argc, char** argv)
{
static const char* names[] = { "pic1.png", "pic2.png", "pic3.png",
@@ -148,8 +133,6 @@ int main(int argc, char** argv)
names[1] = "0";
}
vector<vector<Point> > squares;
for( int i = 0; names[i] != 0; i++ )
{
string filename = samples::findFile(names[i]);
@@ -160,8 +143,11 @@ int main(int argc, char** argv)
continue;
}
vector<vector<Point> > squares;
findSquares(image, squares);
drawSquares(image, squares);
polylines(image, squares, true, Scalar(0, 255, 0), 3, LINE_AA);
imshow(wndname, image);
int c = waitKey();
if( c == 27 )
+13 -13
View File
@@ -74,9 +74,9 @@ void load_images( const String & dirname, vector< Mat > & img_lst, bool showImag
for ( size_t i = 0; i < files.size(); ++i )
{
Mat img = imread( files[i] ); // load the image
if ( img.empty() ) // invalid image, skip it.
if ( img.empty() )
{
cout << files[i] << " is invalid!" << endl;
cout << files[i] << " is invalid!" << endl; // invalid image, skip it.
continue;
}
@@ -95,16 +95,13 @@ void sample_neg( const vector< Mat > & full_neg_lst, vector< Mat > & neg_lst, co
box.width = size.width;
box.height = size.height;
const int size_x = box.width;
const int size_y = box.height;
srand( (unsigned int)time( NULL ) );
for ( size_t i = 0; i < full_neg_lst.size(); i++ )
if ( full_neg_lst[i].cols > box.width && full_neg_lst[i].rows > box.height )
{
box.x = rand() % ( full_neg_lst[i].cols - size_x );
box.y = rand() % ( full_neg_lst[i].rows - size_y );
box.x = rand() % ( full_neg_lst[i].cols - box.width );
box.y = rand() % ( full_neg_lst[i].rows - box.height );
Mat roi = full_neg_lst[i]( box );
neg_lst.push_back( roi.clone() );
}
@@ -259,7 +256,7 @@ int main( int argc, char** argv )
load_images( pos_dir, pos_lst, visualization );
if ( pos_lst.size() > 0 )
{
clog << "...[done]" << endl;
clog << "...[done] " << pos_lst.size() << " files." << endl;
}
else
{
@@ -287,22 +284,25 @@ int main( int argc, char** argv )
}
clog << "Negative images are being loaded...";
load_images( neg_dir, full_neg_lst, false );
load_images( neg_dir, full_neg_lst, visualization );
clog << "...[done] " << full_neg_lst.size() << " files." << endl;
clog << "Negative images are being processed...";
sample_neg( full_neg_lst, neg_lst, pos_image_size );
clog << "...[done]" << endl;
clog << "...[done] " << neg_lst.size() << " files." << endl;
clog << "Histogram of Gradients are being calculated for positive images...";
computeHOGs( pos_image_size, pos_lst, gradient_lst, flip_samples );
size_t positive_count = gradient_lst.size();
labels.assign( positive_count, +1 );
clog << "...[done] ( positive count : " << positive_count << " )" << endl;
clog << "...[done] ( positive images count : " << positive_count << " )" << endl;
clog << "Histogram of Gradients are being calculated for negative images...";
computeHOGs( pos_image_size, neg_lst, gradient_lst, flip_samples );
size_t negative_count = gradient_lst.size() - positive_count;
labels.insert( labels.end(), negative_count, -1 );
CV_Assert( positive_count < labels.size() );
clog << "...[done] ( negative count : " << negative_count << " )" << endl;
clog << "...[done] ( negative images count : " << negative_count << " )" << endl;
Mat train_data;
convert_to_ml( gradient_lst, train_data );
@@ -324,7 +324,7 @@ int main( int argc, char** argv )
if ( train_twice )
{
clog << "Testing trained detector on negative images. This may take a few minutes...";
clog << "Testing trained detector on negative images. This might take a few minutes...";
HOGDescriptor my_hog;
my_hog.winSize = pos_image_size;