Skip to content

Commit 7d40ccf

Browse files
authored
Merge branch 'master' into xfeatures2d
2 parents de276e5 + 5522217 commit 7d40ccf

11 files changed

+58
-27
lines changed

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33

44
This is the example code that accompanies Learning OpenCV 3 by Adrian Kaehler and Gary Bradski (9781491937990).
55

6-
~~In progress May 24, 2017~~
7-
~~In progress June 13, 2017~~
8-
~~In progress June 20, 2017~~
9-
~~In progress June 22, 2017~~
10-
In progress June 30, 2017
6+
* ~~In progress May 24, 2017~~
7+
* ~~In progress June 13, 2017~~
8+
* ~~In progress June 20, 2017~~
9+
* ~~In progress June 22, 2017~~
10+
* ~~In progress July 02, 2017~~
11+
* In progress July 03, 2017
1112

1213
**To do:**
1314
* ~~Chapter 15~~
@@ -20,7 +21,7 @@ In progress June 30, 2017
2021
* ~~Chapter 22~~
2122

2223
Checking Chapters
23-
~~2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,~~ 14, 15 16 17 18 19 20 ~~21 22 23~~
24+
~~2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,~~ 19, 20, ~~21 22 23~~
2425

2526
* Submit associated errata for ~~15 16~~ 17 18 19 20 21 22
2627
* Throw in some bonus material

example_14-01.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ void on_trackbar( int, void* ) {
2828

2929
int main( int argc, char** argv ) {
3030
if( argc != 2 || ( g_gray = cv::imread(argv[1], 0)).empty() ) {
31-
cout << "Find threshold dependent contours\nUsage: " <<argv[0]
32-
<<"fruits.jpg" << endl;
31+
cout << "\nExample 14-1: Find threshold dependent contours\nUsage:\n" <<argv[0]
32+
<<" ../fruits.jpg\n" << endl;
3333
return -1;
3434
}
3535
cv::namedWindow( "Contours", 1 );

example_14-02.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ int main(int argc, char* argv[]) {
1919
// load image or show help if no image was provided
2020
//
2121
if( argc != 2 || (img = cv::imread(argv[1],cv::IMREAD_GRAYSCALE)).empty() ) {
22-
cout << "\nExample 14_2 Drawing Contours\nCall is:\n" << argv[0] << " image\n\n";
22+
cout << "\nERROR: You need 2 parameters, you had " << argc << "\n" << endl;
23+
cout << "\nExample 14_2: Drawing Contours\nCall is:\n" << argv[0] << " <image>\n\n"
24+
<< "Example:\n" << argv[0] << " ../box.png\n" << endl;
2325
return -1;
2426
}
2527

example_14-03.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,27 @@ using namespace std;
88

99
int main(int argc, char* argv[]) {
1010

11-
cv::Mat img, img_edge, labels, img_color, stats;
11+
cv::Mat img, img_edge, labels, centroids, img_color, stats;
1212

1313
// load image or show help if no image was provided
14-
if( argc != 2
14+
if( (argc != 2)
1515
|| (img = cv::imread( argv[1], cv::IMREAD_GRAYSCALE )).empty()
1616
) {
17-
cout << "\nExample 8_3 Drawing Connected componnents\n" \
18-
<< "Call is:\n" <<argv[0] <<" image\n\n";
17+
cout << "\nERROR: You need 2 parameters, you had " << argc << "\n" << endl;
18+
cout << "\nExample 14-3: Drawing labeled connected componnents\n"
19+
<< "Call is:\n" <<argv[0] <<" <path/image>\n"
20+
<< "\nExample:\n" << argv[0] << " ../HandIndoorColor.jpg\n" << endl;
1921
return -1;
2022
}
2123

2224
cv::threshold(img, img_edge, 128, 255, cv::THRESH_BINARY);
2325
cv::imshow("Image after threshold", img_edge);
2426

2527
int i, nccomps = cv::connectedComponentsWithStats (
26-
img_edge, labels,
27-
stats, cv::noArray()
28+
img_edge,
29+
labels,
30+
stats,
31+
centroids
2832
);
2933
cout << "Total Connected Components Detected: " << nccomps << endl;
3034

example_14-04.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,22 @@ static vector<Point> sampleContour( const Mat& image, int n=300 ) {
3333
}
3434
}
3535

36-
int main(int argc, char** argv) {
36+
void help(char** argv) {
37+
cout << "\nExample 14-4. Using the shape context distance extractor"
38+
<< "\nNOTE: See images to try in ../shape_sample/\n"
39+
<< "\nCall:\n" << argv[0] << " <path/image_1> <path/image2>\n"
40+
<< "\nMISSMATCH Example:\n" << argv[0] << " ../shape_sample/1.png ../shape_sample/3.png\n"
41+
<< "\MATCH Example:\n" << argv[0] << " ../shape_sample/3.png ../shape_sample/4.png\n"
42+
<< endl;
43+
}
44+
3745

46+
int main(int argc, char** argv) {
47+
help(argv);
48+
if(argc != 3) {
49+
cout << "\nERROR: you need 2 parameters, you had " << argc << " parameters.\n" << endl;
50+
return -1;
51+
}
3852
string path = "../data/shape_sample/";
3953
int indexQuery = 1;
4054

@@ -48,6 +62,9 @@ int main(int argc, char** argv) {
4862
float dis = mysc->computeDistance( c1, c2 );
4963
cout << "shape context distance between " <<
5064
argv[1] << " and " << argv[2] << " is: " << dis << endl;
65+
cv::imshow("SHAPE #1", img1);
66+
cv::imshow("SHAPE #2",img2);
67+
cv::waitKey();
5168

5269
return 0;
5370

example_15-01.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ using namespace std;
99

1010
void help(char** argv ) {
1111
cout << "\n"
12-
<< "Read out RGB pixel values and store them to disk\nCall:\n"
13-
<< argv[0] <<" avi_file\n"
12+
<< "Example: 15-1: Read out RGB pixel values and store them to disk\nCall:\n"
13+
<< argv[0] <<" <path/video_file>\n"
14+
<< "\nExample:\n" << argv[0] << " ../tree.avi"
1415
<< "\n This will store to files blines.csv, glines.csv and rlines.csv\n\n"
1516
<< endl;
1617
}

example_15-BackgroundSubtractor.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void help()
3333
<< endl
3434
<< "Usage:" << endl
3535
<< "./example_15-BackgroundSubtractor {<#framesTraining> -vid <video filename>|-img <image filename>}\n" << endl
36-
<< "for example: ./example_15-BackgroundSubtractor 50 -vid ../video.avi" << endl
36+
<< "for example: ./example_15-BackgroundSubtractor 50 -vid ../tree.avi" << endl
3737
<< "or: ./example_15-BackgroundSubtractor 20 -img /data/images/1.png" << endl
3838
<< "\n" << endl
3939
<< "This file demonstrates the MOG2 class, you can go to opencv docs to see" << endl
@@ -131,6 +131,7 @@ void processVideo(char* videoFilename, int train) {
131131
*/
132132
//get the input from the keyboard
133133
if(frame_count >= train) {
134+
cout << "\nHit any key to continue\n" << endl;
134135
keyboard = waitKey(); //single step with keyboard press in run mode
135136
} else {
136137
keyboard = waitKey( 10 ); //run automatically in train mode
@@ -195,6 +196,7 @@ void processImages(char* fistFrameFilename, int train) {
195196

196197
//get the input from the keyboard
197198
if(frame_count >= train) {
199+
cout << "\nHit any key to continue\n" << endl;
198200
keyboard = waitKey(); //Single step with keyboard press in test mode
199201
} else {
200202
keyboard = waitKey( 10 ); //Run automatically in train mode

example_16-01.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@
55
#include <opencv2/opencv.hpp>
66

77
static const int MAX_CORNERS = 1000;
8-
98
using std::cout;
109
using std::endl;
1110
using std::vector;
1211

13-
void help(char** argv) {
14-
cout << "Call: " << argv[0] << " [image1] [image2]" << endl;
15-
cout << "Demonstrates Pyramid Lucas-Kanade optical flow." << endl;
12+
13+
void help( char** argv ) {
14+
cout << "\nExample 16-1: Pyramid L-K optical flow example.\n" << endl;
15+
cout << "Call: " <<argv[0] <<" [image1] [image2]\n" << endl;
16+
cout << "\nExample:\n" << argv[0] << " ../example_16-01-imgA.png ../example_16-01-imgB.png\n" << endl;
17+
cout << "Demonstrates Pyramid Lucas-Kanade optical flow.\n" << endl;
1618
}
1719

1820
int main(int argc, char** argv) {

example_17-01.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ using std::endl;
1616

1717
void help(char** argv ) {
1818
cout << "\n"
19-
<< "Example code for using cv::KalmanFilter\n"
19+
<< "Example 17-1: code for using cv::KalmanFilter\n"
2020
<< argv[0] << "\n\n"
2121
<< "For example:\n"
2222
<< argv[0] <<"\n\n"

example_17-02.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ int main(int argc, char** argv) {
4545
// Program expects at least one argument that is path to video file
4646
//
4747
if (argc < 2) {
48-
cerr << "Use:\n" << argv[0] << " <video_file>\n"
49-
<< "to run this demo\n";
48+
cerr << "\nExample 17-2: Farnback optical flow example\n"
49+
<< "Use:\n" << argv[0] << " <path/video_file>\n"
50+
<< "Example:\n" << argv[0] << " ../test.avi\n"
51+
<< std::endl;
5052
exit(1);
5153
}
5254

0 commit comments

Comments
 (0)