Skip to content

Commit 83b8ac4

Browse files
committed
somee refinements to chapter 9
1 parent f12ec12 commit 83b8ac4

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

example_09-01.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,22 @@
22
// Example 9-1. Creating a window and displaying an image in that window
33
//
44
#include <opencv2/opencv.hpp>
5+
#include <iostream>
56

67
using namespace std;
78

89

10+
void help(char** argv ) {
11+
cout << "\n"
12+
<< "Create a window and display an image\nCall:\n"
13+
<< argv[0] <<" image\n"
14+
<< endl;
15+
}
16+
917
int main(int argc, char** argv) {
18+
// Document the interface
19+
help(argv);
20+
if(argc != 2) { cout << "You need to supply an image path/name" << endl;; exit(0);}
1021

1122
// Create a named window with the name of the file
1223
//
@@ -22,9 +33,7 @@ int main(int argc, char** argv) {
2233

2334
// Idle until the user hits the Esc key
2435
//
25-
while( true ) {
26-
if( cv::waitKey( 100 /* milliseconds */ ) == 27 ) break;
27-
}
36+
cv::waitKey(); //Any key will end the program
2837

2938
// Clean up and don't be piggies
3039
//

example_09-02.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ void draw_box( cv::Mat& img, cv::Rect box ) {
2323
cv::Scalar(0x00,0x00,0xff) /* red */
2424
);
2525
}
26-
void help() {
27-
std::cout << "Call: ./ch4_ex4_1\n" <<
28-
" shows how to use a mouse to draw regions in an image." << std::endl;
26+
void help(char** argv) {
27+
std::cout << "Call: " << argv[0] <<
28+
" shows how to use a mouse to draw regions in an image. Esc to quit" << std::endl;
2929
}
3030
int main( int argc, char** argv ) {
31-
help();
31+
help(argv);
3232
box = cv::Rect(-1,-1,0,0);
3333
cv::Mat image(200, 200, CV_8UC3), temp;
3434
image.copyTo(temp);

example_09-03.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ void switch_callback( int position, void* ) {
2626

2727
void help(char ** argv) {
2828
cout << "Call: " << argv[0] << " <my.avi>" << endl;
29-
cout << "Shows putting a pause button in a video." << endl;
29+
cout << "Shows putting a pause button in a video; Esc to quit" << endl;
3030
}
31+
3132
int main( int argc, char** argv ) {
3233
cv::Mat frame; // To hold movie images
3334
cv::VideoCapture g_capture;

0 commit comments

Comments
 (0)