From 71348651eb8845ef18fa3346866015250a46aa44 Mon Sep 17 00:00:00 2001 From: Dmitriy Anisimov Date: Mon, 22 Sep 2014 21:46:18 +0400 Subject: [PATCH] fixed display_image tutorial sample --- .../display_image/display_image.rst | 18 +++++++++--------- .../display_image/display_image.cpp | 10 ++++++---- samples/data/HappyFish.jpg | Bin 0 -> 8283 bytes 3 files changed, 15 insertions(+), 13 deletions(-) create mode 100755 samples/data/HappyFish.jpg diff --git a/doc/tutorials/introduction/display_image/display_image.rst b/doc/tutorials/introduction/display_image/display_image.rst index fc6e6ca5cc..c485fae438 100644 --- a/doc/tutorials/introduction/display_image/display_image.rst +++ b/doc/tutorials/introduction/display_image/display_image.rst @@ -39,28 +39,28 @@ You'll almost always end up using the: .. literalinclude:: ../../../../samples/cpp/tutorial_code/introduction/display_image/display_image.cpp :language: cpp :tab-width: 4 - :lines: 1-4 + :lines: 1-6 We also include the *iostream* to facilitate console line output and input. To avoid data structure and function name conflicts with other libraries, OpenCV has its own namespace: *cv*. To avoid the need appending prior each of these the *cv::* keyword you can import the namespace in the whole file by using the lines: .. literalinclude:: ../../../../samples/cpp/tutorial_code/introduction/display_image/display_image.cpp :language: cpp :tab-width: 4 - :lines: 6-7 + :lines: 8-9 -This is true for the STL library too (used for console I/O). Now, let's analyze the *main* function. We start up assuring that we acquire a valid image name argument from the command line. +This is true for the STL library too (used for console I/O). Now, let's analyze the *main* function. We start up assuring that we acquire a valid image name argument from the command line. Otherwise take a picture by default: "HappyFish.jpg". .. literalinclude:: ../../../../samples/cpp/tutorial_code/introduction/display_image/display_image.cpp :language: cpp :tab-width: 4 - :lines: 11-15 + :lines: 13-17 Then create a *Mat* object that will store the data of the loaded image. .. literalinclude:: ../../../../samples/cpp/tutorial_code/introduction/display_image/display_image.cpp :language: cpp :tab-width: 4 - :lines: 17 + :lines: 19 Now we call the :imread:`imread <>` function which loads the image name specified by the first argument (*argv[1]*). The second argument specifies the format in what we want the image. This may be: @@ -73,7 +73,7 @@ Now we call the :imread:`imread <>` function which loads the image name specifie .. literalinclude:: ../../../../samples/cpp/tutorial_code/introduction/display_image/display_image.cpp :language: cpp :tab-width: 4 - :lines: 18 + :lines: 20 .. note:: @@ -88,21 +88,21 @@ After checking that the image data was loaded correctly, we want to display our .. literalinclude:: ../../../../samples/cpp/tutorial_code/introduction/display_image/display_image.cpp :language: cpp - :lines: 26 + :lines: 28 :tab-width: 4 Finally, to update the content of the OpenCV window with a new image use the :imshow:`imshow <>` function. Specify the OpenCV window name to update and the image to use during this operation: .. literalinclude:: ../../../../samples/cpp/tutorial_code/introduction/display_image/display_image.cpp :language: cpp - :lines: 27 + :lines: 29 :tab-width: 4 Because we want our window to be displayed until the user presses a key (otherwise the program would end far too quickly), we use the :wait_key:`waitKey <>` function whose only parameter is just how long should it wait for a user input (measured in milliseconds). Zero means to wait forever. .. literalinclude:: ../../../../samples/cpp/tutorial_code/introduction/display_image/display_image.cpp :language: cpp - :lines: 29 + :lines: 31 :tab-width: 4 Result diff --git a/samples/cpp/tutorial_code/introduction/display_image/display_image.cpp b/samples/cpp/tutorial_code/introduction/display_image/display_image.cpp index c97ff9e864..133ada6edf 100644 --- a/samples/cpp/tutorial_code/introduction/display_image/display_image.cpp +++ b/samples/cpp/tutorial_code/introduction/display_image/display_image.cpp @@ -1,21 +1,23 @@ #include #include #include + #include +#include using namespace cv; using namespace std; int main( int argc, char** argv ) { - if( argc != 2) + string imageName("../data/HappyFish.jpg"); // by default + if( argc > 1) { - cout <<" Usage: display_image ImageToLoadAndDisplay" << endl; - return -1; + imageName = argv[1]; } Mat image; - image = imread(argv[1], IMREAD_COLOR); // Read the file + image = imread(imageName.c_str(), IMREAD_COLOR); // Read the file if( image.empty() ) // Check for invalid input { diff --git a/samples/data/HappyFish.jpg b/samples/data/HappyFish.jpg new file mode 100755 index 0000000000000000000000000000000000000000..c76288edbfb7105a6ad07b6f3f5b8f2095a1becd GIT binary patch literal 8283 zcmZvB1yoeu*Y*q{DcvBTlr#*|B}jwB07D5#mv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