Skip to content

Commit f7b1a9d

Browse files
committed
14, 15
1 parent bd59605 commit f7b1a9d

File tree

7 files changed

+35
-20
lines changed

7 files changed

+35
-20
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
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~~
1111

1212
**To do:**
1313
* ~~Chapter 15~~
@@ -20,7 +20,7 @@ In progress June 30, 2017
2020
* ~~Chapter 22~~
2121

2222
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~~
23+
~~2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15~~ 16 17 18 19 20 ~~21 22 23~~
2424

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

example_14-01.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void on_trackbar( int, void* ) {
2929
int main( int argc, char** argv ) {
3030
if( argc != 2 || ( g_gray = cv::imread(argv[1], 0)).empty() ) {
3131
cout << "\nExample 14-1: Find threshold dependent contours\nUsage:\n" <<argv[0]
32-
<<"fruits.jpg\n" << endl;
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 14-3: Drawing labeled 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: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,18 @@ void help(char** argv) {
3737
cout << "\nExample 14-4. Using the shape context distance extractor"
3838
<< "\nNOTE: See images to try in ../shape_sample/\n"
3939
<< "\nCall:\n" << argv[0] << " <path/image_1> <path/image2>\n"
40-
<< "\nExample:\n" << argv[0] << " ../shape1.jpg ../shape2.jpg\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"
4142
<< endl;
4243
}
4344

4445

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

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

6369
return 0;
6470

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

0 commit comments

Comments
 (0)