-# Declare variables such as the matrices to store the base image and the two other images to
- Load the base image (src_base) and the other two test images:
compare ( BGR and HSV )
@code{.cpp}
@add_toggle_cpp
Mat src_base, hsv_base;
@snippet samples/cpp/tutorial_code/Histograms_Matching/compareHist_Demo.cpp Load three images with different environment settings
Mat src_test1, hsv_test1;
@end_toggle
Mat src_test2, hsv_test2;
Mat hsv_half_down;
@add_toggle_java
@endcode
@snippet samples/java/tutorial_code/Histograms_Matching/histogram_comparison/CompareHistDemo.java Load three images with different environment settings
-# Load the base image (src_base) and the other two test images:
@snippet samples/python/tutorial_code/Histograms_Matching/histogram_comparison/compareHist_Demo.py Load three images with different environment settings
return -1;
@end_toggle
}
- Convert them to HSV format:
src_base = imread( argv[1], 1 );
src_test1 = imread( argv[2], 1 );
@add_toggle_cpp
src_test2 = imread( argv[3], 1 );
@snippet samples/cpp/tutorial_code/Histograms_Matching/compareHist_Demo.cpp Convert to HSV
@endcode
@end_toggle
-# Convert them to HSV format:
@code{.cpp}
@add_toggle_java
cvtColor( src_base, hsv_base, COLOR_BGR2HSV );
@snippet samples/java/tutorial_code/Histograms_Matching/histogram_comparison/CompareHistDemo.java Convert to HSV
cvtColor( src_test1, hsv_test1, COLOR_BGR2HSV );
@end_toggle
cvtColor( src_test2, hsv_test2, COLOR_BGR2HSV );
@endcode
@add_toggle_python
-# Also, create an image of half the base image (in HSV format):
@snippet samples/python/tutorial_code/Histograms_Matching/histogram_comparison/compareHist_Demo.py Convert to HSV
@snippet samples/cpp/tutorial_code/ImgTrans/Geometric_Transforms_Demo.cpp Apply the Affine Transform just found to the src image
@end_toggle
@add_toggle_java
@snippet samples/java/tutorial_code/ImgTrans/warp_affine/GeometricTransformsDemo.java Apply the Affine Transform just found to the src image
@end_toggle
@add_toggle_python
@snippet samples/python/tutorial_code/ImgTrans/warp_affine/Geometric_Transforms_Demo.py Apply the Affine Transform just found to the src image
@end_toggle
with the following arguments:
with the following arguments:
- **src**: Input image
- **src**: Input image
...
@@ -149,47 +180,87 @@ Explanation
...
@@ -149,47 +180,87 @@ Explanation
We just got our first transformed image! We will display it in one bit. Before that, we also
We just got our first transformed image! We will display it in one bit. Before that, we also
want to rotate it...
want to rotate it...
-#**Rotate:** To rotate an image, we need to know two things:
-**Rotate:** To rotate an image, we need to know two things:
-# The center with respect to which the image will rotate
-# The center with respect to which the image will rotate
-# The angle to be rotated. In OpenCV a positive angle is counter-clockwise
-# The angle to be rotated. In OpenCV a positive angle is counter-clockwise
-# *Optional:* A scale factor
-# *Optional:* A scale factor
We define these parameters with the following snippet:
We define these parameters with the following snippet:
@code{.cpp}
Point center = Point( warp_dst.cols/2, warp_dst.rows/2 );
@add_toggle_cpp
double angle = -50.0;
@snippet samples/cpp/tutorial_code/ImgTrans/Geometric_Transforms_Demo.cpp Compute a rotation matrix with respect to the center of the image
double scale = 0.6;
@end_toggle
@endcode
-# We generate the rotation matrix with the OpenCV function @ref cv::getRotationMatrix2D , which
@add_toggle_java
@snippet samples/java/tutorial_code/ImgTrans/warp_affine/GeometricTransformsDemo.java Compute a rotation matrix with respect to the center of the image
@end_toggle
@add_toggle_python
@snippet samples/python/tutorial_code/ImgTrans/warp_affine/Geometric_Transforms_Demo.py Compute a rotation matrix with respect to the center of the image
@end_toggle
- We generate the rotation matrix with the OpenCV function @ref cv::getRotationMatrix2D , which
returns a \f$2 \times 3\f$ matrix (in this case *rot_mat*)
returns a \f$2 \times 3\f$ matrix (in this case *rot_mat*)
@code{.cpp}
rot_mat = getRotationMatrix2D( center, angle, scale );
@add_toggle_cpp
@endcode
@snippet samples/cpp/tutorial_code/ImgTrans/Geometric_Transforms_Demo.cpp Get the rotation matrix with the specifications above
-# We now apply the found rotation to the output of our previous Transformation.