DevisYang / javacv

Automatically exported from code.google.com/p/javacv
GNU General Public License v2.0
0 stars 0 forks source link

OpenCV Error: Bad argument at cvGetReal1D, cvQueryHistValue_1D #247

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi everyone. in "OpenCV2_Cookbook_Examples_Chapter_4": 
http://code.google.com/p/javacv/wiki/OpenCV2_Cookbook_Examples_Chapter_4
I translated into java. But it doesn't work for me.

This's my code:

Histogram1D.java
...
19 class Histogram1D {
20     int numberOfBins=256;
21     float minRange=0.0f;
22     float maxRange=255.0f;
23    
24     public Histogram1D(){}
25    
26     public Histogram1D(float minRange,float maxRange){
27         this.minRange=minRange;
28         this.maxRange=maxRange;
28     }
30    
31     public CvHistogram getHistogram(IplImage img,IplImage mask){
32         int[] sizes=new int[numberOfBins];
33         float[][] ranges={{minRange,maxRange}};
34         CvHistogram hist=cvCreateHist(1, sizes, CV_HIST_ARRAY, ranges, 1);
35         IplImage[] arrayimg={img};
36         cvCalcHist(arrayimg, hist, 0, mask);
37         return hist;
38     }
39    
40     public float[] getHistogramAsArray(IplImage img){
41         CvHistogram histogram=getHistogram(img, null);
42         float[] dest=new float[numberOfBins];
43         for(int i=0;i<numberOfBins;i++){
44             dest[i]=cvQueryHistValue_1D(histogram, i);
45         }
46         cvReleaseHist(histogram);
47         return dest;
48     }
49 }
...

Ex1ComputeHistogram.java
...
15 public class Ex1ComputeHistogram {
16     public static void main(String args[]){
17         int sumOfHistogramBins=0;
18         IplImage img=cvLoadImage("data/group.jpg",CV_LOAD_IMAGE_GRAYSCALE);
19         Histogram1D h=new Histogram1D();
20         float[] histogram=h.getHistogramAsArray(img);
21         for(int i=0;i<histogram.length;i++){
22             System.out.println(i+":"+histogram[i]);
23             sumOfHistogramBins+=histogram[i];
24         }
25         int numberOfPixels=img.width()*img.height();
26         System.out.println("Number of pixels:"+numberOfPixels);
27         System.out.println("Sum of Histogram Bins:"+sumOfHistogramBins);
28     }
29 }
...

And error:

OpenCV Error: Bad argument (unrecognized or unsupported array type) in unknown 
function, file ..\..\..\src\opencv\modules\core\src\array.cpp, line 1735
Exception in thread "main" java.lang.RuntimeException: 
..\..\..\src\opencv\modules\core\src\array.cpp:1735: error: (-5) unrecognized 
or unsupported array type

    at com.googlecode.javacv.cpp.opencv_core.cvGetReal1D(Native Method)
    at com.googlecode.javacv.cpp.opencv_legacy.cvQueryHistValue_1D(opencv_legacy.java:106)
    at javacv.cookbook.examples.chap4.Histogram1D.getHistogramAsArray(Histogram1D.java:44)
    at javacv.cookbook.examples.chap4.Ex1ComputeHistogram.main(Ex1ComputeHistogram.java:20)

Anyone help me. Thank.

Original issue reported on code.google.com by tuananhv...@gmail.com on 9 Oct 2012 at 9:15

GoogleCodeExporter commented 9 years ago
That question has been answered on the mailing list as it should be. This isn't 
an issue with JavaCV.

Original comment by samuel.a...@gmail.com on 12 Oct 2012 at 9:20