Happy Shrimp
http://blog.csdn.net/lights_joy/
Welcome reprint, but please keep the author information
the histogram is calculated using OpenCV of the calchist completed.
OpenCV of the C + + in the interface calchist There are three kinds of forms:
//! Computes the joint dense histogram for a set of images. cv_exports void Calchist (const mat* images, int nimages, const int* channels, Inputarray mask, Outputarray hist, int dims, const int* histsize, const float** ranges, Bo OL uniform=true, BOOL accumulate=false);//! Computes the joint sparse histogram for a set of images. cv_exports void Calchist (const mat* images, int nimages, const int* channels, Inputarray mask, sparsemat& hist, int dims, const int* histsize, const float** ranges, BOOL Uniform=true, bool accumulate=false); Cv_exports_w void Calchist (inputarrayofarrays images, const vector<int>& channels, Inputarray Mask, Outputarray hist, const vector<int>& hists ize, Const Vector<float>& ranges, bool accumulate=false);
but the exported Python The interface has only one:
Static pyobject* pyopencv_calchist (pyobject*, pyobject* args, pyobject* kw) {pyobject* pyobj_images = NULL; Vector_mat images; pyobject* pyobj_channels = NULL; Vector_int channels; pyobject* pyobj_mask = NULL; Mat Mask; pyobject* pyobj_hist = NULL; Mat hist; pyobject* pyobj_histsize = NULL; Vector_int histsize; pyobject* pyobj_ranges = NULL; Vector_float ranges; BOOL Accumulate=false; Const char* keywords[] = {"Images", "channels", "Mask", "histsize", "Ranges", "hist", "Accumulate", NULL}; if (pyarg_parsetupleandkeywords (args, kw, "ooooo| Ob:calchist ", (char**) keywords, &pyobj_images, &pyobj_channels, &pyobj_mask, &pyobj_histsize, & Pyobj_ranges, &pyobj_hist, &accumulate) && pyopencv_to (pyobj_images, Images, Arginfo ("Images", 0)) && pyopencv_to (pyobj_channels, channels, Arginfo ("channels", 0)) && pyopencv_to (Pyobj_mask, Mask, Arginfo ("mask", 0)) && pyopeNcv_to (Pyobj_hist, Hist, Arginfo ("hist", 1)) && pyopencv_to (pyobj_histsize, Histsize, Arginfo ("Histsize", 0 )) && pyopencv_to (pyobj_ranges, Ranges, Arginfo ("ranges", 0)) {ERRWRAP2 (cv::calchist, Channels, Mask, Hist, histsize, ranges, accumulate); Return Pyopencv_from (hist); } return NULL;
so Python the interface looks a bit strange:
hist = Cv2.calchist ([src], [0], None, [256], [0, 255])
Even if you operate on only one picture, you must use the form of an array for parameter passing.
Write a simple Python program to get a histogram of a single channel:
#-*-coding:utf-8-*-import cv2import numpy as Npimport Matplotlib.pyplot as plt# single-channel histogram test src = cv2.imread (' F:\\tmp\\co Tton.jpg ') cv2.imshow (' src ', src) hist = cv2.calchist ([src], [0], None, [], [0, 255]) Plt.plot (hist) plt.show () Cv2.waitkey ()
The results are as follows:
Meet our expectations of the histogram.
??
Python image Processing (5): Histogram