Skip to content

Feature/opencv451 tested updates #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Exercises_11-1-2-5-6-7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
/************************************************************************/
Expand Down
6 changes: 3 additions & 3 deletions Exercises_7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions Exercises_8_1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions Exercises_9_1-2-10-11-12-15-16.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -171,7 +171,7 @@ int main( int argc, const char** argv )
matKernel.at<float>(2,1) = 0;
matKernel.at<float>(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.
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
10 changes: 5 additions & 5 deletions example_02-04.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions example_02-11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 );
Expand Down
3 changes: 2 additions & 1 deletion example_09-04.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion example_12-03.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion example_12-04.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions example_14-04.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <string>

#include "opencv2/opencv.hpp"
#include "opencv2/shape.hpp"

using namespace std;
using namespace cv;
Expand Down
2 changes: 1 addition & 1 deletion example_15-01.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
{
Expand Down
6 changes: 3 additions & 3 deletions example_16-01.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down
6 changes: 3 additions & 3 deletions example_16-02.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion example_17-02.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 9 additions & 5 deletions example_18-01_from_disk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
// the requested number of views, and calibrating the camera

// You need these includes for the function
// #include <windows.h> // for windows systems
#include <dirent.h> // for linux systems
#include <sys/stat.h> // for linux systems
#ifdef WIN32 // WIN
#include <windows.h> // for windows systems
#else
#include <dirent.h> // for linux systems
#include <sys/stat.h> // for linux systems
#endif

#include <iostream> // cout
#include <algorithm> // std::sort
#include <opencv2/opencv.hpp>
Expand All @@ -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<string>& 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;
Expand Down
4 changes: 2 additions & 2 deletions example_19-04.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand All @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion example_20-02.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ int main(int argc, char** argv) {
vector<cv::Mat> 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);

}

Expand Down
6 changes: 3 additions & 3 deletions example_22-01.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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<cv::CascadeClassifier> cascade(new cv::CascadeClassifier(cascade_file_name));
detectAndDraw(img, cascade);
Expand Down