Android Opencv 为什么 HOG 描述符总是零?

Android Opencv Why HOG descriptors are always zero?

我已经被这个问题困扰了几天。我想制作一个 android 应用程序来拍摄照片并提取该图像的 HOG 特征以供将来处理。问题是下面的代码总是 returns HOG descriptors with rezo values.

@Override
public void onPictureTaken(byte[] data, Camera camera) {
    Log.i(TAG, "Saving a bitmap to file");
    // The camera preview was automatically stopped. Start it again.
    mCamera.startPreview();
    mCamera.setPreviewCallback(this);
    this.disableView();
    Bitmap bitmapPicture = BitmapFactory.decodeByteArray(data, 0, data.length);
    myImage = new Mat(bitmapPicture.getWidth(), bitmapPicture.getHeight(), CvType.CV_8UC1);
    Utils.bitmapToMat(bitmapPicture, myImage);
    Bitmap bm = Bitmap.createBitmap(myImage.cols(), myImage.rows(),Bitmap.Config.ARGB_8888);
    Utils.matToBitmap(myImage.clone(), bm);
    // find the imageview and draw it!
    ImageView iv = (ImageView) getRootView().findViewById(R.id.imageView);
    this.setVisibility(SurfaceView.GONE);
    iv.setVisibility(ImageView.VISIBLE);

    Mat forHOGim = new Mat();
    org.opencv.core.Size sz = new org.opencv.core.Size(64,128);
    Imgproc.resize( myImage, myImage, sz );
    Imgproc.cvtColor(myImage,forHOGim,Imgproc.COLOR_RGB2GRAY);
    //forHOGim = myImage.clone();
    MatOfFloat descriptors = new MatOfFloat(); //an empty vector of descriptors
    org.opencv.core.Size winStride = new org.opencv.core.Size(64/2,128/2); //50% overlap in the sliding window
    org.opencv.core.Size padding = new org.opencv.core.Size(0,0); //no padding around the image
    MatOfPoint locations = new MatOfPoint(); ////an empty vector of locations, so perform full search
    //HOGDescriptor hog = new HOGDescriptor();
    HOGDescriptor hog = new HOGDescriptor(sz,new org.opencv.core.Size(16,16),new org.opencv.core.Size(8,8),new org.opencv.core.Size(8,8),9);
    Log.i(TAG,"Constructed");
    hog.compute(forHOGim , descriptors, new org.opencv.core.Size(16,16), padding, locations);
    Log.i(TAG,"Computed");
    Log.i(TAG,String.valueOf(hog.getDescriptorSize())+" "+descriptors.size());
    Log.i(TAG,String.valueOf(descriptors.get(12,0)[0]));
    double dd=0.0;
    for (int i=0;i<3780;i++){
        if (descriptors.get(i,0)[0]!=dd) Log.i(TAG,"NOT ZERO");
    }

    Bitmap bm2 = Bitmap.createBitmap(forHOGim.cols(), forHOGim.rows(),Bitmap.Config.ARGB_8888);
    Utils.matToBitmap(forHOGim,bm2);
    iv.setImageBitmap(bm2);
}

所以在 logcat 中我从未收到 NOT ZERO 消息。问题是,无论我对这段代码做了什么改变,我总是在 descriptors MatOfFloat 中有零...而且奇怪的是,如果我取消注释 HOGDescriptor hog = new HOGDescriptor(); 并使用那个而不是我现在正在使用,我的应用程序崩溃了... 其余代码运行良好,图片始终如我所愿地拍摄并显示在我的图像视图中。

如有任何帮助,我们将不胜感激。 提前致谢。

问题出在图书馆内部。当我使用 OpenCV 2.4.13 为 Linux 而不是 Android 执行相同的代码时,代码按预期工作得很好。所以我希望他们能解决 OpenCV4Android.

HOGDescriptor 的任何问题