写真で実行したヒストグラムから最大値を取得しようとしています。私のヒストグラムコードは次のようになります: (これについてはスタックオーバーフローユーザーに感謝します)
public static CvHistogram getHueHistogram(IplImage image){
if(image==null || image.nChannels()<3) new Exception("Error!");
// Split the 3 channels into 3 images
IplImageArray hsvChannels = splitChannels(image);
//bins and value-range
int numberOfBins=255;
float minRange= 0f;
float maxRange= 180f;
// Allocate histogram object
int dims = 1;
int[]sizes = new int[]{numberOfBins};
int histType = CV_HIST_ARRAY;
float[] minMax = new float[]{minRange, maxRange};
float[][] ranges = new float[][]{minMax};
int uniform = 1;
CvHistogram hist = cvCreateHist(dims, sizes, histType, ranges, uniform);
// Compute histogram
int accumulate = 1;
@SuppressWarnings("unused")
IplImage mask = null;
cvCalcHist(hsvChannels.position(0),hist, accumulate, null);
return hist;
}
private static IplImageArray splitChannels(IplImage hsvImage) {
CvSize size = hsvImage.cvSize();
int depth=hsvImage.depth();
IplImage channel0 = cvCreateImage(size, depth, 1);
IplImage channel1 = cvCreateImage(size, depth, 1);
IplImage channel2 = cvCreateImage(size, depth, 1);
cvSplit(hsvImage, channel0, channel1, channel2, null);
return new IplImageArray(channel0, channel1, channel2);
}
ここに私のget maxメソッドがあります:
public static float getHistMaxValue (CvHistogram hist){
float[] minValue = {0};// these exist from when I was testing the function, ignore them
float[] maxValue = {0};
int[] minId = {0}; // these exist from when I was testing the function, ignore them
int[] maxId = {0};
cvGetMinMaxHistValue( hist, null, maxValue, null, maxId);
System.out.printf("%2f", maxValue[0]);
return maxValue[0];
}
ほとんどの場合、これは正常に機能します。私の問題は、ヒストグラムの画像が同じままであっても、プログラムを実行するたびに最大値が 1532、298027、および 298038 から変化することです。ヒストグラムを取得する前に、画像に対してかなりの量の処理を実行しますが、これらの機能は適切に機能しているようです。これらの結果が変化する傾向がある理由について何か考えはありますか?