我在这个问题上呆了几天。我想制作一个可以拍摄图片并提取该图片的HOG功能以供将来处理的android应用。问题在于下面的代码总是返回带有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);
}

因此,在日志猫中,我永远不会收到NOT ZERO消息。问题在于,无论我对此代码进行什么更改,我的descriptors MatOfFloat始终为零...而奇怪的是,如果我取消注释HOGDescriptor hog = new HOGDescriptor();并使用该代码而不是我现在使用的代码,则我的应用程序将崩溃。 ..
其余代码运行良好,图片始终可以照我期望的那样拍摄并显示在我的图像 View 中。

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

最佳答案

问题出在图书馆内部。当我使用适用于Linux而不适用于Android的OpenCV 2.4.13执行相同的代码时,该代码可以按预期运行。因此,我希望他们能解决OpenCV4Android的HOGDescriptor的所有问题。

09-28 09:13