Merge pull request #2498 from dreamworld:fix_tutorial_mat_the_basic_image_container
This commit is contained in:
commit
5effebb5f5
@ -310,6 +310,8 @@ extlinks = {
|
|||||||
'calib3d' : ('http://docs.opencv.org/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html#%s', None ),
|
'calib3d' : ('http://docs.opencv.org/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html#%s', None ),
|
||||||
'feature2d' : ('http://docs.opencv.org/modules/imgproc/doc/feature_detection.html#%s', None ),
|
'feature2d' : ('http://docs.opencv.org/modules/imgproc/doc/feature_detection.html#%s', None ),
|
||||||
'imgproc_geometric' : ('http://docs.opencv.org/modules/imgproc/doc/geometric_transformations.html#%s', None ),
|
'imgproc_geometric' : ('http://docs.opencv.org/modules/imgproc/doc/geometric_transformations.html#%s', None ),
|
||||||
|
'miscellaneous_transformations' : ('http://docs.opencv.org/modules/imgproc/doc/miscellaneous_transformations.html#%s', None),
|
||||||
|
'user_interface' : ('http://docs.opencv.org/modules/highgui/doc/user_interface.html#%s', None),
|
||||||
|
|
||||||
# 'opencv_group' : ('http://answers.opencv.org/%s', None),
|
# 'opencv_group' : ('http://answers.opencv.org/%s', None),
|
||||||
'opencv_qa' : ('http://answers.opencv.org/%s', None),
|
'opencv_qa' : ('http://answers.opencv.org/%s', None),
|
||||||
|
@ -45,7 +45,7 @@ All the above objects, in the end, point to the same single data matrix. Their h
|
|||||||
:linenos:
|
:linenos:
|
||||||
|
|
||||||
Mat D (A, Rect(10, 10, 100, 100) ); // using a rectangle
|
Mat D (A, Rect(10, 10, 100, 100) ); // using a rectangle
|
||||||
Mat E = A(Range:all(), Range(1,3)); // using row and column boundaries
|
Mat E = A(Range::all(), Range(1,3)); // using row and column boundaries
|
||||||
|
|
||||||
Now you may ask if the matrix itself may belong to multiple *Mat* objects who takes responsibility for cleaning it up when it's no longer needed. The short answer is: the last object that used it. This is handled by using a reference counting mechanism. Whenever somebody copies a header of a *Mat* object, a counter is increased for the matrix. Whenever a header is cleaned this counter is decreased. When the counter reaches zero the matrix too is freed. Sometimes you will want to copy the matrix itself too, so OpenCV provides the :basicstructures:`clone() <mat-clone>` and :basicstructures:`copyTo() <mat-copyto>` functions.
|
Now you may ask if the matrix itself may belong to multiple *Mat* objects who takes responsibility for cleaning it up when it's no longer needed. The short answer is: the last object that used it. This is handled by using a reference counting mechanism. Whenever somebody copies a header of a *Mat* object, a counter is increased for the matrix. Whenever a header is cleaned this counter is decreased. When the counter reaches zero the matrix too is freed. Sometimes you will want to copy the matrix itself too, so OpenCV provides the :basicstructures:`clone() <mat-clone>` and :basicstructures:`copyTo() <mat-copyto>` functions.
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ Each of the building components has their own valid domains. This leads to the d
|
|||||||
Creating a *Mat* object explicitly
|
Creating a *Mat* object explicitly
|
||||||
==================================
|
==================================
|
||||||
|
|
||||||
In the :ref:`Load_Save_Image` tutorial you have already learned how to write a matrix to an image file by using the :readWriteImageVideo:` imwrite() <imwrite>` function. However, for debugging purposes it's much more convenient to see the actual values. You can do this using the << operator of *Mat*. Be aware that this only works for two dimensional matrices.
|
In the :ref:`Load_Save_Image` tutorial you have already learned how to write a matrix to an image file by using the :readwriteimagevideo:`imwrite() <imwrite>` function. However, for debugging purposes it's much more convenient to see the actual values. You can do this using the << operator of *Mat*. Be aware that this only works for two dimensional matrices.
|
||||||
|
|
||||||
Although *Mat* works really well as an image container, it is also a general matrix class. Therefore, it is possible to create and manipulate multidimensional matrices. You can create a Mat object in multiple ways:
|
Although *Mat* works really well as an image container, it is also a general matrix class. Therefore, it is possible to create and manipulate multidimensional matrices. You can create a Mat object in multiple ways:
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ Load, Modify, and Save an Image
|
|||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
We assume that by now you know how to load an image using :imread:`imread <>` and to display it in a window (using :imshow:`imshow <>`). Read the :ref:`Display_Image` tutorial otherwise.
|
We assume that by now you know how to load an image using :readwriteimagevideo:`imread <imread>` and to display it in a window (using :user_interface:`imshow <imshow>`). Read the :ref:`Display_Image` tutorial otherwise.
|
||||||
|
|
||||||
Goals
|
Goals
|
||||||
======
|
======
|
||||||
@ -14,9 +14,9 @@ In this tutorial you will learn how to:
|
|||||||
|
|
||||||
.. container:: enumeratevisibleitemswithsquare
|
.. container:: enumeratevisibleitemswithsquare
|
||||||
|
|
||||||
* Load an image using :imread:`imread <>`
|
* Load an image using :readwriteimagevideo:`imread <imread>`
|
||||||
* Transform an image from BGR to Grayscale format by using :cvt_color:`cvtColor <>`
|
* Transform an image from BGR to Grayscale format by using :miscellaneous_transformations:`cvtColor <cvtcolor>`
|
||||||
* Save your transformed image in a file on disk (using :imwrite:`imwrite <>`)
|
* Save your transformed image in a file on disk (using :readwriteimagevideo:`imwrite <imwrite>`)
|
||||||
|
|
||||||
Code
|
Code
|
||||||
======
|
======
|
||||||
@ -63,10 +63,7 @@ Here it is:
|
|||||||
Explanation
|
Explanation
|
||||||
============
|
============
|
||||||
|
|
||||||
#. We begin by:
|
#. We begin by loading an image using :readwriteimagevideo:`imread <imread>`, located in the path given by *imageName*. For this example, assume you are loading a RGB image.
|
||||||
|
|
||||||
* Creating a Mat object to store the image information
|
|
||||||
* Load an image using :imread:`imread <>`, located in the path given by *imageName*. Fort this example, assume you are loading a RGB image.
|
|
||||||
|
|
||||||
#. Now we are going to convert our image from BGR to Grayscale format. OpenCV has a really nice function to do this kind of transformations:
|
#. Now we are going to convert our image from BGR to Grayscale format. OpenCV has a really nice function to do this kind of transformations:
|
||||||
|
|
||||||
@ -74,15 +71,15 @@ Explanation
|
|||||||
|
|
||||||
cvtColor( image, gray_image, CV_BGR2GRAY );
|
cvtColor( image, gray_image, CV_BGR2GRAY );
|
||||||
|
|
||||||
As you can see, :cvt_color:`cvtColor <>` takes as arguments:
|
As you can see, :miscellaneous_transformations:`cvtColor <cvtcolor>` takes as arguments:
|
||||||
|
|
||||||
.. container:: enumeratevisibleitemswithsquare
|
.. container:: enumeratevisibleitemswithsquare
|
||||||
|
|
||||||
* a source image (*image*)
|
* a source image (*image*)
|
||||||
* a destination image (*gray_image*), in which we will save the converted image.
|
* a destination image (*gray_image*), in which we will save the converted image.
|
||||||
* an additional parameter that indicates what kind of transformation will be performed. In this case we use **CV_BGR2GRAY** (because of :imread:`imread <>` has BGR default channel order in case of color images).
|
* an additional parameter that indicates what kind of transformation will be performed. In this case we use **CV_BGR2GRAY** (because of :readwriteimagevideo:`imread <imread>` has BGR default channel order in case of color images).
|
||||||
|
|
||||||
#. So now we have our new *gray_image* and want to save it on disk (otherwise it will get lost after the program ends). To save it, we will use a function analagous to :imread:`imread <>`: :imwrite:`imwrite <>`
|
#. So now we have our new *gray_image* and want to save it on disk (otherwise it will get lost after the program ends). To save it, we will use a function analagous to :readwriteimagevideo:`imread <imread>`: :readwriteimagevideo:`imwrite <imwrite>`
|
||||||
|
|
||||||
.. code-block:: cpp
|
.. code-block:: cpp
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user