【问题标题】:Android Opencv Why HOG descriptors are always zero?Android Opencv 为什么 HOG 描述符总是为零?
【发布时间】:2016-11-09 01:55:48
【问题描述】:

我被这个问题困扰了几天。我想制作一个 android 应用程序,它可以拍照并提取该图像的 HOG 特征以供将来处理。问题是下面的代码总是返回带有 rezo 值的HOG descriptors

@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(); 并使用那个而不是我现在使用的那个,我的应用程序崩溃... 其余代码运行良好,照片总是按我的预期拍摄并显示在我的图像视图上。

任何帮助将不胜感激。 提前致谢。

【问题讨论】:

    标签: java android opencv feature-detection


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-17
      • 2017-03-21
      • 2013-03-10
      • 2011-08-25
      • 2017-01-14
      • 1970-01-01
      • 2014-10-11
      • 1970-01-01
      相关资源
      最近更新 更多