Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
a489d86e
Commit
a489d86e
authored
Mar 17, 2014
by
Roman Donchenko
Committed by
OpenCV Buildbot
Mar 17, 2014
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2460 from berak:b_3598_24
parents
ae036838
5f94a205
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
87 deletions
+9
-87
histogram_comparison.rst
.../histograms/histogram_comparison/histogram_comparison.rst
+6
-84
compareHist_Demo.cpp
...pp/tutorial_code/Histograms_Matching/compareHist_Demo.cpp
+3
-3
No files found.
doc/tutorials/imgproc/histograms/histogram_comparison/histogram_comparison.rst
View file @
a489d86e
...
...
@@ -84,88 +84,10 @@ Code
* **Code at glance:**
.. code-block:: cpp
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>
using namespace std;
using namespace cv;
/** @function main */
int main( int argc, char** argv )
{
Mat src_base, hsv_base;
Mat src_test1, hsv_test1;
Mat src_test2, hsv_test2;
Mat hsv_half_down;
/// Load three images with different environment settings
if( argc < 4 )
{ printf("** Error. Usage: ./compareHist_Demo <image_settings0> <image_setting1> <image_settings2>\n");
return -1;
}
src_base = imread( argv[1], 1 );
src_test1 = imread( argv[2], 1 );
src_test2 = imread( argv[3], 1 );
/// Convert to HSV
cvtColor( src_base, hsv_base, CV_BGR2HSV );
cvtColor( src_test1, hsv_test1, CV_BGR2HSV );
cvtColor( src_test2, hsv_test2, CV_BGR2HSV );
hsv_half_down = hsv_base( Range( hsv_base.rows/2, hsv_base.rows - 1 ), Range( 0, hsv_base.cols - 1 ) );
/// Using 30 bins for hue and 32 for saturation
int h_bins = 50; int s_bins = 60;
int histSize[] = { h_bins, s_bins };
// hue varies from 0 to 256, saturation from 0 to 180
float h_ranges[] = { 0, 256 };
float s_ranges[] = { 0, 180 };
const float* ranges[] = { h_ranges, s_ranges };
// Use the o-th and 1-st channels
int channels[] = { 0, 1 };
/// Histograms
MatND hist_base;
MatND hist_half_down;
MatND hist_test1;
MatND hist_test2;
/// Calculate the histograms for the HSV images
calcHist( &hsv_base, 1, channels, Mat(), hist_base, 2, histSize, ranges, true, false );
normalize( hist_base, hist_base, 0, 1, NORM_MINMAX, -1, Mat() );
.. literalinclude:: ../../../../../samples/cpp/tutorial_code/Histograms_Matching/compareHist_Demo.cpp
:language: cpp
:tab-width: 4
calcHist( &hsv_half_down, 1, channels, Mat(), hist_half_down, 2, histSize, ranges, true, false );
normalize( hist_half_down, hist_half_down, 0, 1, NORM_MINMAX, -1, Mat() );
calcHist( &hsv_test1, 1, channels, Mat(), hist_test1, 2, histSize, ranges, true, false );
normalize( hist_test1, hist_test1, 0, 1, NORM_MINMAX, -1, Mat() );
calcHist( &hsv_test2, 1, channels, Mat(), hist_test2, 2, histSize, ranges, true, false );
normalize( hist_test2, hist_test2, 0, 1, NORM_MINMAX, -1, Mat() );
/// Apply the histogram comparison methods
for( int i = 0; i < 4; i++ )
{ int compare_method = i;
double base_base = compareHist( hist_base, hist_base, compare_method );
double base_half = compareHist( hist_base, hist_half_down, compare_method );
double base_test1 = compareHist( hist_base, hist_test1, compare_method );
double base_test2 = compareHist( hist_base, hist_test2, compare_method );
printf( " Method [%d] Perfect, Base-Half, Base-Test(1), Base-Test(2) : %f, %f, %f, %f \n", i, base_base, base_half , base_test1, base_test2 );
}
printf( "Done \n" );
return 0;
}
Explanation
...
...
@@ -211,11 +133,11 @@ Explanation
.. code-block:: cpp
int h_bins = 50; int s_bins =
32
;
int h_bins = 50; int s_bins =
60
;
int histSize[] = { h_bins, s_bins };
float h_ranges[] = { 0,
256
};
float s_ranges[] = { 0,
180
};
float h_ranges[] = { 0,
180
};
float s_ranges[] = { 0,
256
};
const float* ranges[] = { h_ranges, s_ranges };
...
...
samples/cpp/tutorial_code/Histograms_Matching/compareHist_Demo.cpp
View file @
a489d86e
...
...
@@ -40,13 +40,13 @@ int main( int argc, char** argv )
hsv_half_down
=
hsv_base
(
Range
(
hsv_base
.
rows
/
2
,
hsv_base
.
rows
-
1
),
Range
(
0
,
hsv_base
.
cols
-
1
)
);
/// Using
30 bins for hue and 32
for saturation
/// Using
50 bins for hue and 60
for saturation
int
h_bins
=
50
;
int
s_bins
=
60
;
int
histSize
[]
=
{
h_bins
,
s_bins
};
// hue varies from 0 to 256, saturation from 0 to 180
float
s_ranges
[]
=
{
0
,
256
};
// hue varies from 0 to 179, saturation from 0 to 255
float
h_ranges
[]
=
{
0
,
180
};
float
s_ranges
[]
=
{
0
,
256
};
const
float
*
ranges
[]
=
{
h_ranges
,
s_ranges
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment