Skip to content

Commit

Permalink
21 and 22
Browse files Browse the repository at this point in the history
  • Loading branch information
garybradski committed Jul 2, 2017
1 parent 0b6d8d3 commit 39c3aaa
Show file tree
Hide file tree
Showing 5 changed files with 27,788 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions example_21-01.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//Example 21-1. Creating and training a decision tree

#include <opencv2/opencv.hpp>
#include <stdio.h>
#include <iostream>
Expand All @@ -12,6 +14,7 @@ void help(char **argv) {
<< " This program demonstrates how to create and a train a \n"
<< " decision tree using ml library in OpenCV.\n"
<< "Call:\n" << argv[0] << " <csv-file-path>\n\n"
<< "\nIf you don't enter a file, it defaults to ../mushroom/agaricus-lepiota.data\n"
<< endl;
}

Expand Down
20 changes: 8 additions & 12 deletions example_22-01.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ using std::string;
//
void detectAndDraw(
cv::Mat& img, // input image
cv::Ptr<cv::CascadeClassifier> classifier, // preloaded classifier
cv::Ptr<cv::CascadeClassifier> classifier, // preloaded classifier
double scale = 1.3) { // resize image by ...
// Just some pretty colors to draw with
//
Expand Down Expand Up @@ -50,7 +50,6 @@ void detectAndDraw(

// Loop through to found objects and draw boxes around them
//

int i = 0;
for (vector<cv::Rect>::iterator r = objects.begin();
r != objects.end(); r++, ++i) {
Expand All @@ -69,23 +68,20 @@ int main(int argc, char** argv) {
// - path to .xml classifier file
//
if (argc < 3) {
cerr << "Error: wrong number of arguments.\n";
cerr << "Use:\n" << argv[0] << " <image_file> <xml_classifier_file>\n"
<< "to run this demo\n\n"
<< "Example:\n"
<< argv[0] << " faces.png haarcascade_frontalface_alt.xml\n"
<< std::endl;
cerr << "\nError: wrong number of arguments.\n";
cerr << "\nExample 22-1. Detecting and drawing faces\n\n"
<< "Use:\n" << argv[0] << " <path/image_file> <path/xml_classifier_file>\n"
<< "to run this demo\n\n"
<< "Example:\n"
<< argv[0] << " ../faces.png ../haarcascade_frontalface_alt.xml\n"
<< std::endl;
exit(1);
}

string image_file_name = string(argv[1]);
cv::Mat img = cv::imread(image_file_name, CV_LOAD_IMAGE_COLOR);

string cascade_file_name = string(argv[2]);
cv::Ptr<cv::CascadeClassifier> cascade(new cv::CascadeClassifier(cascade_file_name));

detectAndDraw(img, cascade);

cv::imshow("Result", img);
cv::waitKey(0);

Expand Down
Loading

0 comments on commit 39c3aaa

Please sign in to comment.