Skip to content

Commit

Permalink
Merge branch 'master' into xfeatures2d
Browse files Browse the repository at this point in the history
  • Loading branch information
garybradski authored Jul 4, 2017
2 parents de276e5 + 5522217 commit 7d40ccf
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 27 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@

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~~
* In progress July 03, 2017

**To do:**
* ~~Chapter 15~~
Expand All @@ -20,7 +21,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
4 changes: 2 additions & 2 deletions example_14-01.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ void on_trackbar( int, void* ) {

int main( int argc, char** argv ) {
if( argc != 2 || ( g_gray = cv::imread(argv[1], 0)).empty() ) {
cout << "Find threshold dependent contours\nUsage: " <<argv[0]
<<"fruits.jpg" << endl;
cout << "\nExample 14-1: Find threshold dependent contours\nUsage:\n" <<argv[0]
<<" ../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 8_3 Drawing 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
19 changes: 18 additions & 1 deletion example_14-04.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,22 @@ static vector<Point> sampleContour( const Mat& image, int n=300 ) {
}
}

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

Expand All @@ -48,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
10 changes: 6 additions & 4 deletions example_16-01.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
#include <opencv2/opencv.hpp>

static const int MAX_CORNERS = 1000;

using std::cout;
using std::endl;
using std::vector;

void help(char** argv) {
cout << "Call: " << argv[0] << " [image1] [image2]" << endl;
cout << "Demonstrates Pyramid Lucas-Kanade optical flow." << endl;

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

int main(int argc, char** argv) {
Expand Down
2 changes: 1 addition & 1 deletion example_17-01.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ using std::endl;

void help(char** argv ) {
cout << "\n"
<< "Example code for using cv::KalmanFilter\n"
<< "Example 17-1: code for using cv::KalmanFilter\n"
<< argv[0] << "\n\n"
<< "For example:\n"
<< argv[0] <<"\n\n"
Expand Down
6 changes: 4 additions & 2 deletions example_17-02.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ int main(int argc, char** argv) {
// Program expects at least one argument that is path to video file
//
if (argc < 2) {
cerr << "Use:\n" << argv[0] << " <video_file>\n"
<< "to run this demo\n";
cerr << "\nExample 17-2: Farnback optical flow example\n"
<< "Use:\n" << argv[0] << " <path/video_file>\n"
<< "Example:\n" << argv[0] << " ../test.avi\n"
<< std::endl;
exit(1);
}

Expand Down
2 changes: 1 addition & 1 deletion example_18-01.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void help(char **argv) { // todo rewrite this
<< " reading and collecting the requested number of views,\n"
<< " and calibrating the camera\n\n"
<< "Call:\n" << argv[0] << " <board_width> <board_height> <number_of_boards> <if_video,_delay_between_framee_capture> <image_scaling_factor>\n\n"
<< "Example:\n./example_18-01 9 6 15 500 0.5\n"
<< "Example:\n" << argv[0] << " 9 6 15 500 0.5\n"
<< "-- to use the checkerboard9x6.png provided\n\n"
<< " * First it reads in checker boards and calibrates itself\n"
<< " * Then it saves and reloads the calibration matricies\n"
Expand Down

0 comments on commit 7d40ccf

Please sign in to comment.