Class: OpenCV::CvHistogram
- Inherits:
-
Object
- Object
- OpenCV::CvHistogram
- Defined in:
- ext/opencv/cvhistogram.cpp,
ext/opencv/cvhistogram.cpp
Overview
Multi-dimensional histogram.
Class Method Summary collapse
-
.calc_prob_density(hist1, hist2, scale = 255) ⇒ CvHistogram
Divides one histogram by another.
-
.compare_hist(hist1, hist2, method) ⇒ Number
Compares two histograms.
Instance Method Summary collapse
-
#[](args) ⇒ Number
(also: #query_hist_value)
Queries the value of the histogram bin.
-
#calc_back_project(images) ⇒ CvMat, IplImage
Calculates the back projection of a histogram.
-
#calc_back_project_patch(images, patch_size, method, factor) ⇒ CvMat, IplImage
Locates a template within an image by using a histogram comparison.
-
#calc_hist(images, accumulate = nil, mask = nil) ⇒ CvHistogram
Calculates a histogram of a set of arrays.
-
#calc_hist!(images, accumulate = nil, mask = nil) ⇒ Object
Calculates a histogram of a set of arrays.
-
#clear_hist ⇒ CvHistogram
(also: #clear)
Sets all histogram bins to 0 in case of dense histogram and removes all histogram bins in case of sparse array.
-
#clear_hist! ⇒ CvHistogram
(also: #clear!)
Sets all histogram bins to 0 in case of dense histogram and removes all histogram bins in case of sparse array.
-
#copy_hist ⇒ CvHistogram
Clones histogram.
-
#[](idx0, idx1, ...) ⇒ Array<Integer, Array<Integer>>
Returns number of array dimensions.
-
#has_range? ⇒ Boolean
Returns
self
has range or not. -
#new(dims, sizes, type, ranges = nil, uniform = true) ⇒ CvHistogram
constructor
Creates a histogram.
-
#is_sparse? ⇒ Boolean
Returns
self
is sparse histogram or not. -
#is_uniform? ⇒ Boolean
Returns
self
is uniform histogram or not. -
#min_max_value ⇒ Array
Finds the minimum and maximum histogram bins.
-
#normalize(factor) ⇒ CvHistogram
(also: #normalize)
Returns normalized the histogram bins by scaling them, such that the sum of the bins becomes equal to
factor
. -
#normalize!(factor) ⇒ CvHistogram
(also: #normalize!)
Returns normalized the histogram bins by scaling them, such that the sum of the bins becomes equal to
factor
. -
#set_hist_bin_ranges(ranges, uniform = true) ⇒ CvHistogram
Sets the bounds of the histogram bins.
-
#set_hist_bin_ranges!(ranges, uniform = true) ⇒ CvHistogram
Sets the bounds of the histogram bins.
-
#thresh_hist(threshold) ⇒ CvHistogram
(also: #thresh)
Returns cleared histogram bins that are below the specified threshold.
-
#thresh_hist!(threshold) ⇒ CvHistogram
(also: #thresh!)
Cleares histogram bins that are below the specified threshold.
Constructor Details
#new(dims, sizes, type, ranges = nil, uniform = true) ⇒ CvHistogram
Creates a histogram
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'ext/opencv/cvhistogram.cpp', line 88
VALUE
rb_initialize(int argc, VALUE *argv, VALUE self)
{
VALUE _dims, _sizes, _type, _ranges, _uniform;
int uniform;
int* sizes;
float** ranges = NULL;
rb_scan_args(argc, argv, "32", &_dims, &_sizes, &_type, &_ranges, &_uniform);
int sizes_len = RARRAY_LEN(_sizes);
sizes = ALLOCA_N(int, sizes_len);
if (NIL_P(_ranges)) {
sizes = ary2intptr(_sizes, sizes);
ranges = NULL;
}
else {
ranges = ALLOCA_N(float*, sizes_len);
VALUE* range_ptr = RARRAY_PTR(_ranges);
int i;
for (i = 0; i < sizes_len; i++) {
sizes[i] = NUM2INT(RARRAY_PTR(_sizes)[i]);
ranges[i] = ary2fltptr(range_ptr[i], ALLOCA_N(float, 2));
}
}
uniform = TRUE_OR_FALSE(_uniform, 1);
try {
DATA_PTR(self) = cvCreateHist(NUM2INT(_dims), sizes, NUM2INT(_type), ranges, uniform);
}
catch (cv::Exception& e) {
raise_cverror(e);
}
return self;
}
|
Class Method Details
.calc_prob_density(hist1, hist2, scale = 255) ⇒ CvHistogram
Divides one histogram by another.
645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 |
# File 'ext/opencv/cvhistogram.cpp', line 645
VALUE
rb_calc_prob_density(int argc, VALUE* argv, VALUE self)
{
VALUE hist1, hist2, scale;
rb_scan_args(argc, argv, "21", &hist1, &hist2, &scale);
double s = NIL_P(scale) ? 255 : NUM2DBL(scale);
CvHistogram* hist1_ptr = CVHISTOGRAM_WITH_CHECK(hist1);
VALUE dst_hist = rb_allocate(rb_klass);
try {
cvCopyHist(hist1_ptr, (CvHistogram**)&(DATA_PTR(dst_hist)));
cvCalcProbDensity(hist1_ptr, CVHISTOGRAM_WITH_CHECK(hist2), CVHISTOGRAM(dst_hist), s);
}
catch (cv::Exception& e) {
raise_cverror(e);
}
return dst_hist;
}
|
.compare_hist(hist1, hist2, method) ⇒ Number
Compares two histograms.
621 622 623 624 625 626 627 628 629 630 631 632 633 634 |
# File 'ext/opencv/cvhistogram.cpp', line 621
VALUE
rb_compare_hist(VALUE self, VALUE hist1, VALUE hist2, VALUE method)
{
double result = 0;
try {
result = cvCompareHist(CVHISTOGRAM_WITH_CHECK(hist1), CVHISTOGRAM_WITH_CHECK(hist2),
NUM2INT(method));
}
catch (cv::Exception& e) {
raise_cverror(e);
}
return rb_float_new(result);
}
|
Instance Method Details
#[](idx0) ⇒ Number #[](idx0, idx1) ⇒ Number #[](idx0, idx1, idx2) ⇒ Number #[](idx0, idx1, idx2, idx3, ...) ⇒ Number Also known as: query_hist_value
Queries the value of the histogram bin.
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
# File 'ext/opencv/cvhistogram.cpp', line 227
VALUE
rb_aref(VALUE self, VALUE args)
{
int num_idx = RARRAY_LEN(args);
int* idx = ALLOCA_N(int, num_idx);
VALUE* args_ptr = RARRAY_PTR(args);
for (int i = 0; i < num_idx; i++) {
idx[i] = NUM2INT(args_ptr[i]);
}
float value = 0.0;
CvHistogram* self_ptr = CVHISTOGRAM(self);
try {
switch (num_idx) {
case 1:
value = cvQueryHistValue_1D(self_ptr, idx[0]);
break;
case 2:
value = cvQueryHistValue_2D(self_ptr, idx[0], idx[1]);
break;
case 3:
value = cvQueryHistValue_3D(self_ptr, idx[0], idx[1], idx[2]);
break;
default:
value = cvQueryHistValue_nD(self_ptr, idx);
break;
}
}
catch (cv::Exception& e) {
raise_cverror(e);
}
return rb_float_new((double)value);
}
|
#calc_back_project(images) ⇒ CvMat, IplImage
Calculates the back projection of a histogram.
526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 |
# File 'ext/opencv/cvhistogram.cpp', line 526
VALUE
rb_calc_back_project(VALUE self, VALUE image)
{
Check_Type(image, T_ARRAY);
int num_images = RARRAY_LEN(image);
if (num_images == 0) {
return Qnil;
}
IplImage** img = ALLOCA_N(IplImage*, num_images);
VALUE* image_ptr = RARRAY_PTR(image);
for (int i = 0; i < num_images; ++i) {
img[i] = IPLIMAGE_WITH_CHECK(image_ptr[i]);
}
CvSize size;
size.width = img[0]->width;
size.height = img[0]->height;
VALUE back_project = cCvMat::new_mat_kind_object(size, image_ptr[0]);
try {
cvCalcBackProject(img, CVARR(back_project), CVHISTOGRAM(self));
}
catch (cv::Exception& e) {
raise_cverror(e);
}
return back_project;
}
|
#calc_back_project_patch(images, patch_size, method, factor) ⇒ CvMat, IplImage
Locates a template within an image by using a histogram comparison.
573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 |
# File 'ext/opencv/cvhistogram.cpp', line 573
VALUE
rb_calc_back_project_patch(VALUE self, VALUE image, VALUE patch_size, VALUE method, VALUE factor)
{
Check_Type(image, T_ARRAY);
int num_images = RARRAY_LEN(image);
if (num_images == 0) {
return Qnil;
}
IplImage** img = ALLOCA_N(IplImage*, num_images);
VALUE* image_ptr = RARRAY_PTR(image);
for (int i = 0; i < num_images; ++i) {
img[i] = IPLIMAGE_WITH_CHECK(image_ptr[i]);
}
CvSize patchsize = VALUE_TO_CVSIZE(patch_size);
CvSize dst_size;
dst_size.width = img[0]->width - patchsize.width + 1;
dst_size.height = img[0]->height - patchsize.height + 1;
VALUE dst = cCvMat::new_mat_kind_object(dst_size, image_ptr[0], CV_32F, 1);
try {
cvCalcBackProjectPatch(img, CVARR(dst), patchsize, CVHISTOGRAM(self),
NUM2INT(method), NUM2DBL(factor));
}
catch (cv::Exception& e) {
raise_cverror(e);
}
return dst;
}
|
#calc_hist(images, accumulate = nil, mask = nil) ⇒ CvHistogram
Calculates a histogram of a set of arrays.
177 178 179 180 181 |
# File 'ext/opencv/cvhistogram.cpp', line 177
VALUE
rb_calc_hist(int argc, VALUE* argv, VALUE self)
{
return rb_calc_hist_bang(argc, argv, rb_copy_hist(self));
}
|
#calc_hist!(images, accumulate = nil, mask = nil) ⇒ Object
Calculates a histogram of a set of arrays.
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'ext/opencv/cvhistogram.cpp', line 189
VALUE
rb_calc_hist_bang(int argc, VALUE* argv, VALUE self)
{
VALUE images, accumulate, mask;
rb_scan_args(argc, argv, "12", &images, &accumulate, &mask);
Check_Type(images, T_ARRAY);
int num_images = RARRAY_LEN(images);
if (num_images == 0) {
rb_raise(rb_eArgError, "One or more arrays are required.");
}
IplImage** img = ALLOCA_N(IplImage*, num_images);
VALUE* images_ptr = RARRAY_PTR(images);
for (int i = 0; i < num_images; i++) {
img[i] = IPLIMAGE_WITH_CHECK(images_ptr[i]);
}
CvMat* m = NIL_P(mask) ? NULL : CVMAT_WITH_CHECK(mask);
try {
cvCalcHist(img, CVHISTOGRAM(self), TRUE_OR_FALSE(accumulate, 0), m);
}
catch (cv::Exception& e) {
raise_cverror(e);
}
return self;
}
|
#clear_hist ⇒ CvHistogram Also known as: clear
Sets all histogram bins to 0 in case of dense histogram and removes all histogram bins in case of sparse array.
360 361 362 363 364 |
# File 'ext/opencv/cvhistogram.cpp', line 360
VALUE
rb_clear_hist(VALUE self)
{
return rb_clear_hist_bang(rb_copy_hist(self));
}
|
#clear_hist! ⇒ CvHistogram Also known as: clear!
Sets all histogram bins to 0 in case of dense histogram and removes all histogram bins in case of sparse array. This method changes self
.
375 376 377 378 379 380 381 382 383 384 385 |
# File 'ext/opencv/cvhistogram.cpp', line 375
VALUE
rb_clear_hist_bang(VALUE self)
{
try {
cvClearHist(CVHISTOGRAM(self));
}
catch (cv::Exception& e) {
raise_cverror(e);
}
return self;
}
|
#copy_hist ⇒ CvHistogram
Clones histogram
340 341 342 343 344 345 346 347 348 349 350 351 |
# File 'ext/opencv/cvhistogram.cpp', line 340
VALUE
rb_copy_hist(VALUE self)
{
CvHistogram* hist = NULL;
try {
cvCopyHist(CVHISTOGRAM(self), &hist);
}
catch (cv::Exception& e) {
raise_cverror(e);
}
return Data_Wrap_Struct(rb_klass, 0, release_hist, hist);
}
|
#[](idx0, idx1, ...) ⇒ Array<Integer, Array<Integer>>
Returns number of array dimensions
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 |
# File 'ext/opencv/cvhistogram.cpp', line 315
VALUE
rb_dims(VALUE self)
{
VALUE _sizes = Qnil;
int size[CV_MAX_DIM];
int dims = 0;
try {
dims = cvGetDims(CVHISTOGRAM(self)->bins, size);
_sizes = rb_ary_new2(dims);
for (int i = 0; i < dims; ++i) {
rb_ary_store(_sizes, i, INT2NUM(size[i]));
}
}
catch (cv::Exception& e) {
raise_cverror(e);
}
return rb_assoc_new(INT2NUM(dims), _sizes);
}
|
#has_range? ⇒ Boolean
Returns self
has range or not
155 156 157 158 159 |
# File 'ext/opencv/cvhistogram.cpp', line 155
VALUE
rb_has_range(VALUE self)
{
return CV_HIST_HAS_RANGES(CVHISTOGRAM(self)) ? Qtrue : Qfalse;
}
|
#is_sparse? ⇒ Boolean
Returns self
is sparse histogram or not
143 144 145 146 147 |
# File 'ext/opencv/cvhistogram.cpp', line 143
VALUE
rb_is_sparse(VALUE self)
{
return CV_IS_SPARSE_HIST(CVHISTOGRAM(self)) ? Qtrue : Qfalse;
}
|
#is_uniform? ⇒ Boolean
Returns self
is uniform histogram or not
131 132 133 134 135 |
# File 'ext/opencv/cvhistogram.cpp', line 131
VALUE
rb_is_uniform(VALUE self)
{
return CV_IS_UNIFORM_HIST(CVHISTOGRAM(self)) ? Qtrue : Qfalse;
}
|
#min_max_value ⇒ Array
Finds the minimum and maximum histogram bins.
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
# File 'ext/opencv/cvhistogram.cpp', line 274
VALUE
rb_min_max_value(VALUE self)
{
CvHistogram* self_ptr = CVHISTOGRAM(self);
int dims = 0;
float min_value = 0.0, max_value = 0.0;
int *min_idx = NULL;
int *max_idx = NULL;
try {
dims = cvGetDims(self_ptr->bins, NULL);
min_idx = ALLOCA_N(int, dims);
max_idx = ALLOCA_N(int, dims);
cvGetMinMaxHistValue(CVHISTOGRAM(self), &min_value, &max_value, min_idx, max_idx);
}
catch (cv::Exception& e) {
raise_cverror(e);
}
VALUE _min_idx = rb_ary_new2(dims);
VALUE _max_idx = rb_ary_new2(dims);
for (int i = 0; i < dims; i++) {
rb_ary_store(_min_idx, i, INT2NUM(min_idx[i]));
rb_ary_store(_max_idx, i, INT2NUM(max_idx[i]));
}
return rb_ary_new3(4, rb_float_new((double)min_value), rb_float_new((double)max_value),
_min_idx, _max_idx);
}
|
#normalize(factor) ⇒ CvHistogram Also known as: normalize
Returns normalized the histogram bins by scaling them, such that the sum of the bins becomes equal to factor
.
395 396 397 398 399 |
# File 'ext/opencv/cvhistogram.cpp', line 395
VALUE
rb_normalize_hist(VALUE self, VALUE factor)
{
return rb_normalize_hist_bang(rb_copy_hist(self), factor);
}
|
#normalize!(factor) ⇒ CvHistogram Also known as: normalize!
Returns normalized the histogram bins by scaling them, such that the sum of the bins becomes equal to factor
. This method changes self
.
411 412 413 414 415 416 417 418 419 420 421 |
# File 'ext/opencv/cvhistogram.cpp', line 411
VALUE
rb_normalize_hist_bang(VALUE self, VALUE factor)
{
try {
cvNormalizeHist(CVHISTOGRAM(self), NUM2DBL(factor));
}
catch (cv::Exception& e) {
raise_cverror(e);
}
return self;
}
|
#set_hist_bin_ranges(ranges, uniform = true) ⇒ CvHistogram
Sets the bounds of the histogram bins.
470 471 472 473 474 |
# File 'ext/opencv/cvhistogram.cpp', line 470
VALUE
rb_set_hist_bin_ranges(int argc, VALUE* argv, VALUE self)
{
return rb_set_hist_bin_ranges_bang(argc, argv, rb_copy_hist(self));
}
|
#set_hist_bin_ranges!(ranges, uniform = true) ⇒ CvHistogram
Sets the bounds of the histogram bins. This method changes self
.
490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 |
# File 'ext/opencv/cvhistogram.cpp', line 490
VALUE
rb_set_hist_bin_ranges_bang(int argc, VALUE* argv, VALUE self)
{
VALUE _ranges, _uniform;
rb_scan_args(argc, argv, "11", &_ranges, &_uniform);
Check_Type(_ranges, T_ARRAY);
int ranges_size = RARRAY_LEN(_ranges);
float** ranges = ALLOCA_N(float*, ranges_size);
VALUE* range_ptr = RARRAY_PTR(_ranges);
for (int i = 0; i < ranges_size; ++i) {
ranges[i] = ary2fltptr(range_ptr[i], ALLOCA_N(float, 2));
}
int uniform = TRUE_OR_FALSE(_uniform, 1);
try {
cvSetHistBinRanges(CVHISTOGRAM(self), ranges, uniform);
}
catch (cv::Exception& e) {
raise_cverror(e);
}
return self;
}
|
#thresh_hist(threshold) ⇒ CvHistogram Also known as: thresh
Returns cleared histogram bins that are below the specified threshold.
430 431 432 433 434 |
# File 'ext/opencv/cvhistogram.cpp', line 430
VALUE
rb_thresh_hist(VALUE self, VALUE threshold)
{
return rb_thresh_hist_bang(rb_copy_hist(self), threshold);
}
|
#thresh_hist!(threshold) ⇒ CvHistogram Also known as: thresh!
Cleares histogram bins that are below the specified threshold. This method changes self
.
445 446 447 448 449 450 451 452 453 454 455 |
# File 'ext/opencv/cvhistogram.cpp', line 445
VALUE
rb_thresh_hist_bang(VALUE self, VALUE threshold)
{
try {
cvThreshHist(CVHISTOGRAM(self), NUM2DBL(threshold));
}
catch (cv::Exception& e) {
raise_cverror(e);
}
return self;
}
|