diff --git a/Exercises_11-1-2-5-6-7.cpp b/Exercises_11-1-2-5-6-7.cpp index 6d8ce7f..93c96b3 100644 --- a/Exercises_11-1-2-5-6-7.cpp +++ b/Exercises_11-1-2-5-6-7.cpp @@ -134,7 +134,7 @@ int main( int argc, const char** argv ) circle(matInpaint,Point(255,255),100,Scalar(255),10); circle(matInpaintMask,Point(255,255),100,Scalar(255),10); imshow("befor inpaint",matInpaint); - inpaint(matInpaint,matInpaintMask,matInpaint,10,CV_INPAINT_TELEA); + inpaint(matInpaint,matInpaintMask,matInpaint,10, INPAINT_TELEA); imshow("after inpaint",matInpaint); //the result is :if "the writing obscured a real object edge in a picture",the result is bad /************************************************************************/ diff --git a/Exercises_7.cpp b/Exercises_7.cpp index c761207..672c2bf 100644 --- a/Exercises_7.cpp +++ b/Exercises_7.cpp @@ -83,11 +83,11 @@ int main( int argc, const char** argv ) // b rng.fill(planes[2],RNG::NORMAL,128,2); // c - PCA pca(planes[0],Mat(),CV_PCA_DATA_AS_ROW,2); + PCA pca(planes[0],Mat(), PCA::DATA_AS_ROW,2); planes[0] = pca.project(planes[0]); - pca(planes[1],Mat(),CV_PCA_DATA_AS_ROW,2); + pca(planes[1],Mat(), PCA::DATA_AS_ROW,2); planes[1] = pca.project(planes[1]); - pca(planes[2],Mat(),CV_PCA_DATA_AS_ROW,2); + pca(planes[2],Mat(), PCA::DATA_AS_ROW,2); planes[2] = pca.project(planes[2]); //d f1 = 0; diff --git a/Exercises_8_1.cpp b/Exercises_8_1.cpp index 9793325..4bb7e5c 100644 --- a/Exercises_8_1.cpp +++ b/Exercises_8_1.cpp @@ -44,7 +44,7 @@ int main( int argc, const char** argv ) cout << "Could not open " << argv[1] << endl; return 1; } - double rate=capture.get(CV_CAP_PROP_FPS); + double rate=capture.get(CAP_PROP_FPS); Mat MatFrame; Mat MatGray; Mat MatCanny; @@ -80,9 +80,9 @@ int main( int argc, const char** argv ) MatCanny.copyTo(MatSub); //question b Scalar color = CV_RGB(255,0,0); - putText(MatAll,"raw video",Point(50,30),CV_FONT_HERSHEY_DUPLEX,1.0f,color); - putText(MatAll,"gray video",Point(50+MatFrame.cols,30),CV_FONT_HERSHEY_DUPLEX,1.0f,color); - putText(MatAll,"canny video",Point(50+2*MatFrame.cols,30),CV_FONT_HERSHEY_DUPLEX,1.0f,color); + putText(MatAll,"raw video",Point(50,30),FONT_HERSHEY_DUPLEX,1.0f,color); + putText(MatAll,"gray video",Point(50+MatFrame.cols,30),FONT_HERSHEY_DUPLEX,1.0f,color); + putText(MatAll,"canny video",Point(50+2*MatFrame.cols,30),FONT_HERSHEY_DUPLEX,1.0f,color); imshow("all Video",MatAll); if ((cv::waitKey(delay) & 255) == 27) diff --git a/Exercises_9_1-2-10-11-12-15-16.cpp b/Exercises_9_1-2-10-11-12-15-16.cpp index 61c1718..1b460f9 100644 --- a/Exercises_9_1-2-10-11-12-15-16.cpp +++ b/Exercises_9_1-2-10-11-12-15-16.cpp @@ -113,7 +113,7 @@ int main( int argc, const char** argv ) /************************************************************************/ cvtColor(src,gray,COLOR_BGR2GRAY); //a - morphologyEx(gray,temp,CV_MOP_TOPHAT,Mat()); + morphologyEx(gray,temp,MORPH_TOPHAT,Mat()); imshow(" morphological Top Hat",temp); //b temp.convertTo(mask,CV_8UC1); @@ -171,7 +171,7 @@ int main( int argc, const char** argv ) matKernel.at(2,1) = 0; matKernel.at(2,2) = 0; filter2D(matWithLines,temp,CV_32FC1,matKernel); - threshold(temp,temp,0.99,1,CV_THRESH_BINARY); + threshold(temp,temp,0.99,1,THRESH_BINARY); /************************************************************************/ /* 16. Separable kernels: create a 3 × 3 Gaussian kernel using rows [(1/16, 2/16, 1/16), (2/16, 4/16, 2/16), (1/16, 2/16, 1/16)] and with anchor point in the middle. diff --git a/README.md b/README.md index 7485722..6acabfd 100644 --- a/README.md +++ b/README.md @@ -2,13 +2,13 @@ ## INTRO -This is the example code that accompanies Learning OpenCV 3 by Adrian Kaehler and Gary Bradski ([9781491937990](http:*shop.oreilly.com/product/0636920044765.do)). +This is the example code that accompanies Learning OpenCV 3 by Adrian Kaehler and Gary Bradski ([9781491937990](https://shop.oreilly.com/product/0636920044765.do)). Click the Download Zip button to the right to download example code. -Visit the catalog page [here](http:*shop.oreilly.com/product/0636920044765.do). +Visit the catalog page [here](https://shop.oreilly.com/product/0636920044765.do). -See an error? Report it [here](http:*oreilly.com/catalog/errata.csp?isbn=0636920044765), or simply fork and send us a pull request +See an error? Report it [here](https://oreilly.com/catalog/errata.csp?isbn=0636920044765), or simply fork and send us a pull request ## NOTES @@ -170,6 +170,6 @@ For your interest, included here is an Ubuntu _Docker_ file that ## LINKS: Click the Download Zip button to the right to download example code. -Visit the catalog page [here](http:*shop.oreilly.com/product/0636920044765.do). +Visit the catalog page [here](https://shop.oreilly.com/product/0636920044765.do). -See an error? Report it [here](http:*oreilly.com/catalog/errata.csp?isbn=0636920044765), or simply fork and send us a pull request +See an error? Report it [here](https://oreilly.com/catalog/errata.csp?isbn=0636920044765), or simply fork and send us a pull request diff --git a/example_02-04.cpp b/example_02-04.cpp index 12e1ee2..c78746a 100644 --- a/example_02-04.cpp +++ b/example_02-04.cpp @@ -14,7 +14,7 @@ cv::VideoCapture g_cap; void onTrackbarSlide( int pos, void *) { - g_cap.set( CV_CAP_PROP_POS_FRAMES, pos ); + g_cap.set( cv::CAP_PROP_POS_FRAMES, pos ); if( !g_dontset ) g_run = 1; @@ -44,9 +44,9 @@ int main( int argc, char** argv ) { g_cap.open( string(argv[1]) ); - int frames = (int) g_cap.get( CV_CAP_PROP_FRAME_COUNT ); - int tmpw = (int) g_cap.get( CV_CAP_PROP_FRAME_WIDTH ); - int tmph = (int) g_cap.get( CV_CAP_PROP_FRAME_HEIGHT ); + int frames = (int) g_cap.get( cv::CAP_PROP_FRAME_COUNT ); + int tmpw = (int) g_cap.get( cv::CAP_PROP_FRAME_WIDTH ); + int tmph = (int) g_cap.get( cv::CAP_PROP_FRAME_HEIGHT ); cout << "Video has " << frames << " frames of dimensions(" << tmpw << ", " << tmph << ")." << endl; @@ -65,7 +65,7 @@ int main( int argc, char** argv ) { if( g_run != 0 ) { g_cap >> frame; if(frame.empty()) break; - int current_pos = (int)g_cap.get( CV_CAP_PROP_POS_FRAMES ); + int current_pos = (int)g_cap.get(cv::CAP_PROP_POS_FRAMES ); g_dontset = 1; cv::setTrackbarPos("Position", "Example 2-4", current_pos); diff --git a/example_02-11.cpp b/example_02-11.cpp index 14416b7..9d4a05b 100644 --- a/example_02-11.cpp +++ b/example_02-11.cpp @@ -31,14 +31,14 @@ int main( int argc, char** argv ) { // cv::VideoCapture capture( argv[1] ); - double fps = capture.get( CV_CAP_PROP_FPS ); + double fps = capture.get( cv::CAP_PROP_FPS ); cv::Size size( - (int)capture.get( CV_CAP_PROP_FRAME_WIDTH ), - (int)capture.get( CV_CAP_PROP_FRAME_HEIGHT ) + (int)capture.get(cv::CAP_PROP_FRAME_WIDTH ), + (int)capture.get(cv::CAP_PROP_FRAME_HEIGHT ) ); cv::VideoWriter writer; - writer.open( argv[2], CV_FOURCC('M','J','P','G'), fps, size ); + writer.open( argv[2], cv::VideoWriter::fourcc('M','J','P','G'), fps, size ); cv::Mat logpolar_frame, bgr_frame; @@ -57,7 +57,7 @@ int main( int argc, char** argv ) { bgr_frame.rows/2 // y ), 40, // Magnitude (scale parameter) - CV_WARP_FILL_OUTLIERS // Fill outliers with 'zero' + cv::WARP_FILL_OUTLIERS // Fill outliers with 'zero' ); cv::imshow( "Log_Polar", logpolar_frame ); diff --git a/example_09-04.cpp b/example_09-04.cpp index 615b8e3..b89f40a 100644 --- a/example_09-04.cpp +++ b/example_09-04.cpp @@ -3,6 +3,7 @@ //connected to the sliders in Figure 9-6 // Note: This example needs OpenGL installed on your system. It doesn't build if // the OpenGL libraries cannot be found. +#include #include #include @@ -82,7 +83,7 @@ int main(int argc, char* argv[]) return -1; } - cv::namedWindow( "Example 9-4", CV_WINDOW_OPENGL ); + cv::namedWindow( "Example 9-4", cv::WINDOW_OPENGL ); cv::resizeWindow("Example 9-4", img.cols, img.rows); cv::createTrackbar( "X-rotation", "Example 9-4", &rotx, 360, on_trackbar); cv::createTrackbar( "Y-rotation", "Example 9-4", &roty, 360, on_trackbar); diff --git a/example_12-03.cpp b/example_12-03.cpp index 912d4b0..1f798c4 100644 --- a/example_12-03.cpp +++ b/example_12-03.cpp @@ -96,7 +96,7 @@ int main(int argc, char** argv) { return -1; } - img = cv::imread(std::string(argv[1]), CV_LOAD_IMAGE_COLOR); + img = cv::imread(std::string(argv[1]), cv::IMREAD_COLOR); if (img.channels() != 3) { cerr << "Input image should have 3 channels" << endl; exit(1); diff --git a/example_12-04.cpp b/example_12-04.cpp index 6f0acb0..5f499a3 100644 --- a/example_12-04.cpp +++ b/example_12-04.cpp @@ -106,7 +106,7 @@ int main(int argc, char** argv) { return -1; } - img = cv::imread(std::string(argv[1]), CV_LOAD_IMAGE_COLOR); + img = cv::imread(std::string(argv[1]), cv::IMREAD_COLOR); if (img.channels() != 3) { cerr << "Input image should have 3 channels" << endl; exit(1); diff --git a/example_14-04.cpp b/example_14-04.cpp index 5c37d5b..5a91913 100644 --- a/example_14-04.cpp +++ b/example_14-04.cpp @@ -5,6 +5,7 @@ #include #include "opencv2/opencv.hpp" +#include "opencv2/shape.hpp" using namespace std; using namespace cv; diff --git a/example_15-01.cpp b/example_15-01.cpp index a8ac75d..232d84c 100644 --- a/example_15-01.cpp +++ b/example_15-01.cpp @@ -20,7 +20,7 @@ int main( int argc, char** argv) { // Argument handling // if(argc != 2) { help(argv); return -1; } - cv::namedWindow( argv[0], CV_WINDOW_AUTOSIZE ); + cv::namedWindow( argv[0], cv::WINDOW_AUTOSIZE ); cv::VideoCapture cap; if((argc < 2)|| !cap.open(argv[1])) { diff --git a/example_16-01.cpp b/example_16-01.cpp index f5176e3..23409a3 100644 --- a/example_16-01.cpp +++ b/example_16-01.cpp @@ -26,11 +26,11 @@ int main(int argc, char** argv) { // allocate the images and other structures we will need for // results. // - cv::Mat imgA = cv::imread(argv[1], CV_LOAD_IMAGE_GRAYSCALE); - cv::Mat imgB = cv::imread(argv[2], CV_LOAD_IMAGE_GRAYSCALE); + cv::Mat imgA = cv::imread(argv[1], cv::IMREAD_GRAYSCALE); + cv::Mat imgB = cv::imread(argv[2], cv::IMREAD_GRAYSCALE); cv::Size img_sz = imgA.size(); int win_size = 10; - cv::Mat imgC = cv::imread(argv[2], CV_LOAD_IMAGE_UNCHANGED); + cv::Mat imgC = cv::imread(argv[2], cv::IMREAD_UNCHANGED); // The first thing we need to do is get the features // we want to track. // diff --git a/example_16-02.cpp b/example_16-02.cpp index 2331357..507ce86 100644 --- a/example_16-02.cpp +++ b/example_16-02.cpp @@ -47,7 +47,7 @@ using cv::KAZE; using cv::xfeatures2d::BriefDescriptorExtractor; using cv::xfeatures2d::SURF; -using cv::xfeatures2d::SIFT; +using cv::SIFT; using cv::xfeatures2d::DAISY; using cv::xfeatures2d::FREAK; @@ -182,8 +182,8 @@ int main(int argc, char** argv) { string img_file1(argv[3]); string img_file2(argv[4]); - Mat img1 = cv::imread(img_file1, CV_LOAD_IMAGE_COLOR); - Mat img2 = cv::imread(img_file2, CV_LOAD_IMAGE_COLOR); + Mat img1 = cv::imread(img_file1, cv::IMREAD_COLOR); + Mat img2 = cv::imread(img_file2, cv::IMREAD_COLOR); if (img1.channels() != 1) { cvtColor(img1, img1, cv::COLOR_RGB2GRAY); diff --git a/example_17-02.cpp b/example_17-02.cpp index 3258c2e..9fc22d4 100644 --- a/example_17-02.cpp +++ b/example_17-02.cpp @@ -76,7 +76,7 @@ int main(int argc, char** argv) { break; } if (colored_frame.type() == CV_8UC3) { - cvtColor(colored_frame, frame, CV_BGR2GRAY); + cvtColor(colored_frame, frame, cv::COLOR_BGR2GRAY); } if (prev_frame.rows) { calcOpticalFlowFarneback(prev_frame, frame, optflow, pyr_scale, levels, winsize, diff --git a/example_18-01_from_disk.cpp b/example_18-01_from_disk.cpp index 712d85e..4c3160e 100644 --- a/example_18-01_from_disk.cpp +++ b/example_18-01_from_disk.cpp @@ -2,9 +2,13 @@ // the requested number of views, and calibrating the camera // You need these includes for the function -// #include // for windows systems -#include // for linux systems -#include // for linux systems +#ifdef WIN32 // WIN + #include // for windows systems +#else + #include // for linux systems + #include // for linux systems +#endif + #include // cout #include // std::sort #include @@ -17,12 +21,12 @@ using std::endl; // Returns a list of files in a directory (except the ones that begin with a dot) int readFilenames(vector& filenames, const string& directory) { -#ifdef WINDOWS +#ifdef WIN32 HANDLE dir; WIN32_FIND_DATA file_data; if ((dir = FindFirstFile((directory + "/*").c_str(), &file_data)) == INVALID_HANDLE_VALUE) - return; // no files found + return -1; // no files found do { const string file_name = file_data.cFileName; const string full_file_name = directory + "/" + file_name; diff --git a/example_19-04.cpp b/example_19-04.cpp index 9d9f1ac..549832c 100644 --- a/example_19-04.cpp +++ b/example_19-04.cpp @@ -53,7 +53,7 @@ int main(int argc, char **argv) { cv::circle(img, points[i], 2, i < count - outliers ? cv::Scalar(0, 0, 255) : cv::Scalar(0, 255, 255), - cv::FILLED, CV_AA, 0); + cv::FILLED, cv::LINE_AA, 0); // ... and the long enough line to cross the whole image d = sqrt((double)line[0] * line[0] + (double)line[1] * line[1]); @@ -64,7 +64,7 @@ int main(int argc, char **argv) { pt1.y = cvRound(line[3] - line[1] * t); pt2.x = cvRound(line[2] + line[0] * t); pt2.y = cvRound(line[3] + line[1] * t); - cv::line(img, pt1, pt2, cv::Scalar(0, 255, 0), 3, CV_AA, 0); + cv::line(img, pt1, pt2, cv::Scalar(0, 255, 0), 3, cv::LINE_AA, 0); cv::imshow("Fit Line", img); key = (char)cv::waitKey(0); if (key == 27 || key == 'q' || key == 'Q') // 'ESC' diff --git a/example_20-02.cpp b/example_20-02.cpp index f51b732..c03c8ce 100644 --- a/example_20-02.cpp +++ b/example_20-02.cpp @@ -59,7 +59,7 @@ int main(int argc, char** argv) { vector means(CLUSTER_COUNT); for(int i = 0; i < CLUSTER_COUNT; i++) { cv::calcCovarMatrix(clusters[i], covarMats[i], means[i], - CV_COVAR_NORMAL | CV_COVAR_ROWS, 5); + cv::COVAR_NORMAL | cv::COVAR_ROWS, 5); } diff --git a/example_22-01.cpp b/example_22-01.cpp index 3c7ab7f..f85fbe9 100644 --- a/example_22-01.cpp +++ b/example_22-01.cpp @@ -32,7 +32,7 @@ void detectAndDraw( // Image preparation: // cv::Mat gray(img.size(), CV_8UC1); - cv::Mat small_img(cvSize(cvRound(img.cols / scale), + cv::Mat small_img(cv::Size(std::round(img.cols / scale), cvRound(img.rows / scale)), CV_8UC1); cv::cvtColor(img, gray, cv::COLOR_BGR2GRAY); cv::resize(gray, small_img, small_img.size(), 0.0, 0.0, cv::INTER_LINEAR); @@ -45,7 +45,7 @@ void detectAndDraw( objects, // place for the results 1.1, // scale factor 3, // minimum number of neighbors - CV_HAAR_DO_CANNY_PRUNING, // (old format cascades only) + cv::CASCADE_DO_CANNY_PRUNING, // (old format cascades only) cv::Size(30, 30)); // throw away detections smaller than this // Loop through to found objects and draw boxes around them @@ -78,7 +78,7 @@ int main(int argc, char** argv) { exit(1); } string image_file_name = string(argv[1]); - cv::Mat img = cv::imread(image_file_name, CV_LOAD_IMAGE_COLOR); + cv::Mat img = cv::imread(image_file_name, cv::IMREAD_COLOR); string cascade_file_name = string(argv[2]); cv::Ptr cascade(new cv::CascadeClassifier(cascade_file_name)); detectAndDraw(img, cascade);