Skip to content

Commit

Permalink
14, 15
Browse files Browse the repository at this point in the history
  • Loading branch information
garybradski committed Jul 3, 2017
1 parent bd59605 commit f7b1a9d
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 20 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

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

~~In progress May 24, 2017~~
~~In progress June 13, 2017~~
~~In progress June 20, 2017~~
~~In progress June 22, 2017~~
In progress June 30, 2017
* ~~In progress May 24, 2017~~
* ~~In progress June 13, 2017~~
* ~~In progress June 20, 2017~~
* ~~In progress June 22, 2017~~
* ~~In progress July 02, 2017~~

**To do:**
* ~~Chapter 15~~
Expand All @@ -20,7 +20,7 @@ In progress June 30, 2017
* ~~Chapter 22~~

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

* Submit associated errata for ~~15 16~~ 17 18 19 20 21 22
* Throw in some bonus material
Expand Down
2 changes: 1 addition & 1 deletion example_14-01.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void on_trackbar( int, void* ) {
int main( int argc, char** argv ) {
if( argc != 2 || ( g_gray = cv::imread(argv[1], 0)).empty() ) {
cout << "\nExample 14-1: Find threshold dependent contours\nUsage:\n" <<argv[0]
<<"fruits.jpg\n" << endl;
<<" ../fruits.jpg\n" << endl;
return -1;
}
cv::namedWindow( "Contours", 1 );
Expand Down
4 changes: 3 additions & 1 deletion example_14-02.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ int main(int argc, char* argv[]) {
// load image or show help if no image was provided
//
if( argc != 2 || (img = cv::imread(argv[1],cv::IMREAD_GRAYSCALE)).empty() ) {
cout << "\nExample 14_2: Drawing Contours\nCall is:\n" << argv[0] << " image\n\n";
cout << "\nERROR: You need 2 parameters, you had " << argc << "\n" << endl;
cout << "\nExample 14_2: Drawing Contours\nCall is:\n" << argv[0] << " <image>\n\n"
<< "Example:\n" << argv[0] << " ../box.png\n" << endl;
return -1;
}

Expand Down
16 changes: 10 additions & 6 deletions example_14-03.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,27 @@ using namespace std;

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

cv::Mat img, img_edge, labels, img_color, stats;
cv::Mat img, img_edge, labels, centroids, img_color, stats;

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

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

int i, nccomps = cv::connectedComponentsWithStats (
img_edge, labels,
stats, cv::noArray()
img_edge,
labels,
stats,
centroids
);
cout << "Total Connected Components Detected: " << nccomps << endl;

Expand Down
12 changes: 9 additions & 3 deletions example_14-04.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,18 @@ void help(char** argv) {
cout << "\nExample 14-4. Using the shape context distance extractor"
<< "\nNOTE: See images to try in ../shape_sample/\n"
<< "\nCall:\n" << argv[0] << " <path/image_1> <path/image2>\n"
<< "\nExample:\n" << argv[0] << " ../shape1.jpg ../shape2.jpg\n"
<< "\nMISSMATCH Example:\n" << argv[0] << " ../shape_sample/1.png ../shape_sample/3.png\n"
<< "\MATCH Example:\n" << argv[0] << " ../shape_sample/3.png ../shape_sample/4.png\n"
<< endl;
}


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

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

return 0;

Expand Down
5 changes: 3 additions & 2 deletions example_15-01.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ using namespace std;

void help(char** argv ) {
cout << "\n"
<< "Read out RGB pixel values and store them to disk\nCall:\n"
<< argv[0] <<" avi_file\n"
<< "Example: 15-1: Read out RGB pixel values and store them to disk\nCall:\n"
<< argv[0] <<" <path/video_file>\n"
<< "\nExample:\n" << argv[0] << " ../tree.avi"
<< "\n This will store to files blines.csv, glines.csv and rlines.csv\n\n"
<< endl;
}
Expand Down
4 changes: 3 additions & 1 deletion example_15-BackgroundSubtractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void help()
<< endl
<< "Usage:" << endl
<< "./example_15-BackgroundSubtractor {<#framesTraining> -vid <video filename>|-img <image filename>}\n" << endl
<< "for example: ./example_15-BackgroundSubtractor 50 -vid ../video.avi" << endl
<< "for example: ./example_15-BackgroundSubtractor 50 -vid ../tree.avi" << endl
<< "or: ./example_15-BackgroundSubtractor 20 -img /data/images/1.png" << endl
<< "\n" << endl
<< "This file demonstrates the MOG2 class, you can go to opencv docs to see" << endl
Expand Down Expand Up @@ -131,6 +131,7 @@ void processVideo(char* videoFilename, int train) {
*/
//get the input from the keyboard
if(frame_count >= train) {
cout << "\nHit any key to continue\n" << endl;
keyboard = waitKey(); //single step with keyboard press in run mode
} else {
keyboard = waitKey( 10 ); //run automatically in train mode
Expand Down Expand Up @@ -195,6 +196,7 @@ void processImages(char* fistFrameFilename, int train) {

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

0 comments on commit f7b1a9d

Please sign in to comment.