Ask Your Question

AMEMB's profile - activity

2020-06-06 12:21:47 -0600 received badge  Popular Question (source)
2017-11-08 07:32:09 -0600 received badge  Famous Question (source)
2017-08-14 21:38:14 -0600 received badge  Notable Question (source)
2017-07-03 10:37:25 -0600 received badge  Popular Question (source)
2016-11-16 09:09:10 -0600 asked a question OpenCV loading failed on Huawei BTV-W09

Hallo,

I am working with OpenCV4android version 2.4.11, the way i load openCV library as shown below in the code works fine on Samsung device, but when I tried the same code on Huawei MediaPad with Android version 6 the App does not start and i receive the following error

W/System.err:     at org.opencv.android.OpenCVLoader.initDebug(OpenCVLoader.java:66)
W/System.err:     at org.opencv.android.OpenCVLoader.initDebug(OpenCVLoader.java:66)
W/ContextImpl: Implicit intents with startService are not safe: Intent { act=org.opencv.engine.BIND } android.content.ContextWrapper.bindService:604 org.opencv.android.AsyncServiceHelper.initOpenCV:24 org.opencv.android.OpenCVLoader.initAsync:89 
E/OpenCVLoader/BaseLoaderCallback: OpenCV loading failed!

please let me know what should i do to load opencv correctly on Huawei?

thank you

code:

public class FragOpenCVCam extends Fragment implements CameraBridgeViewBase.CvCameraViewListener2, View.OnTouchListener {

private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(getActivity()) {
    @Override
    public void onManagerConnected(int status) {
        switch (status) {
            case LoaderCallbackInterface.SUCCESS: {
                Log.i(TAG, "OpenCV loaded successfully");
                mOpenCvCameraView.enableView();
            }
            break;
            default: {
                super.onManagerConnected(status);
            }
            break;
        }
    }
};
}

...
...
...

@Override
public void onResume() {
    super.onResume();
    Log.w(TAG, "onResume");

    if (!OpenCVLoader.initDebug()) {
        Log.d(TAG, "Internal OpenCV library not found. Using OpenCV Manager for initialization");
        OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_11, getActivity(), mLoaderCallback);
    } else {
        Log.d(TAG, "OpenCV library found inside package. Using it!");
        mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
    }
}
2016-10-20 05:42:47 -0600 asked a question how to detect corners in frames retrieved from Camera

I am working with OpenCV4Android version 2.4.11, and I am trying to detect cornrs in frames retrieved from the camera. i used "cornerHarris" method to detect the corners as shown in the code below. the problem is, at run time the Mat object that is named "corner" is completely black.

please let me know why the Mat that contains the corners is balck and how to solve this problem

code:

Mat mMatGray = new Mat();
Imgproc.cvtColor(mMatInputFrame, mMatGray, Imgproc.COLOR_BGR2GRAY);

corners = new Mat(mMatInputFrame.size(), CvType.CV_32FC1, Scalar.all(0));
Imgproc.cornerHarris(mMatGray,corners,1,3,3,1);

corners.convertTo(corners, CV_8UC(4) );

final Bitmap bitmap = Bitmap.createBitmap(mMatInputFrame.cols(), mMatInputFrame.rows(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(corners, bitmap);
getActivity().runOnUiThread(new Runnable() {
    @Override
    public void run() {
        mIVEdges.setImageBitmap(bitmap);
    }
});
2016-10-12 02:17:44 -0600 commented question Where can I find DEPTH_MASK_8U constant?

I just was following an example and doing it, and that example was using that constant and i could not find it...Anyway, would you please have a look at ths question, maybe you can suggest something based on your experience: http://answers.opencv.org/question/10...

2016-10-12 02:14:36 -0600 asked a question how to detect the outer frame of an object

I am using OpenCV4Android version 3.1.0 and I want the Android camera to be able to detect a card e.g: credit-card, customer's card or etc. To implement such functionalitey using OpenCV i tried to do it using Edge-Detection function, but as you see in the picture below, Edge-Detection detects all the edges in the frame, while what I am looking for is to detect the only the outer frame of the card.

I tried also Object-Detection "contour-detection" function, and as you see in the picture below, it did not detect the outer frame of the card.

please let me know what is the optimal solution or function i should use to be able to detect only the outer frame of any given card

Edge-Detection: enter image description here

Shape"contour" Detection: enter image description here

2016-10-12 01:21:12 -0600 asked a question Where can I find DEPTH_MASK_8U constant?

I am using OpenCV4Android version 3.1.0 and I can not use Core.DEPTH_MASK_8U. is there any alternative to this constant? how can I use it in OpenCV4Android version 3.1.0?

2016-10-11 03:10:28 -0600 asked a question Regarding understanding Canny's parameters?

I am trying to learn how to make edge detection, so i referred to some tutorials such as the one in this link I followed the steps as stated but what i could not understand is the last four parameters set to the function of .Canny()!! I manipulated the parameters but i always get the same results and i could not notice any difference in the output. would you please explain what are these parameters really doing? and how to realize their effect

code:

//step 1
this.mMatGray = new Mat();
Imgproc.cvtColor(this.mMatInputFrame, this.mMatGray, Imgproc.COLOR_BGR2GRAY);

//step 2
this.mMatEdges = new Mat();
Imgproc.blur(this.mMatGray, this.mMatEdges, new Size(5, 5));

//step 3
Imgproc.Canny(this.mMatEdges, this.mMatEdges, 100, 1, 5, true);
2016-10-11 03:06:37 -0600 received badge  Scholar (source)
2016-10-11 02:04:26 -0600 asked a question How to initialize a Mat object with zeros

I want to create a Mat object initially initialized with zeros, and i want to avoid doing that using two nested for-loops. is there any alternative solution to the one posted below?

code:

this.mDest = new Mat(this.mMatEdges.rows(), this.mMatEdges.cols(), CvType.CV_8U);
    for (int i =  0; i < this.mMatEdges.size().height; i++) {
        for (int j = 0; j < this.mMatEdges.size().width; j++) {
            this.mDest.put(i, j, 0);
        }
    }
2016-10-10 01:10:51 -0600 received badge  Enthusiast
2016-10-07 04:50:20 -0600 received badge  Organizer (source)
2016-10-07 03:55:08 -0600 asked a question How to display Android camera preview[SOLVED]

I am trying to open the Android camera using Opencv. I referred to some posts such as: http://stackoverflow.com/questions/17... and http://docs.opencv.org/2.4/doc/tutori... and as some of these posts suggested, I created the below posted layout with "org.opencv.android.CameraBridgeViewBase" item as shown below in the layout section.

At run time, if the following line was active the App crashs and logCat says: "java.lang.InstantiationException: Can't instantiate abstract class org.opencv.android.CameraBridgeViewBase" setContentView(R.layout.activity_main);

When I comment that line out as shown in the code in onCreate() method and run the code, logCat displays the following message:

Log.d(TAG, "onCameraFrame");

which means the Camera is previewing, but actually there is nothing displayed on the screen, the screen is black.

please let me know why "setContentView(R.layout.activity_main);" causes the App to crash and how to preview the camera display correctly

layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:opencv="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.bakri.opencvcamera_00.MainActivity">

<org.opencv.android.CameraBridgeViewBase
    android:id="@+id/cameraBridgeViewBase_surfaceView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:visibility="gone"
    opencv:show_fps="true"  opencv:camera_id="any" />
</RelativeLayout>

code:

@Override public class MainActivity extends AppCompatActivity implements CameraBridgeViewBase.CvCameraViewListener2,View.OnTouchListener {
    private final String TAG = MainActivity.class.getSimpleName();
    private CameraBridgeViewBase mOpenCvCameraView;

    private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
        @Override
        public void onManagerConnected(int status) {
            switch (status) {
                case LoaderCallbackInterface.SUCCESS:
                    Log.i(TAG, "OpenCV loaded successfully");

                    mOpenCvCameraView.setOnTouchListener(MainActivity.this);
                    mOpenCvCameraView.enableView();

                    break;
                default:
                    super.onManagerConnected(status);
                    break;
            }
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_main);

        mOpenCvCameraView = (CameraBridgeViewBase) new JavaCameraView(this, 1);
        //mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.cameraBridgeViewBase_surfaceView);
        mOpenCvCameraView.setCameraIndex(CameraBridgeViewBase.CAMERA_ID_FRONT);
        setContentView(mOpenCvCameraView);
        mOpenCvCameraView.setVisibility(CameraBridgeViewBase.VISIBLE);
        mOpenCvCameraView.setCvCameraViewListener(this);
    }

    @Override
    protected void onResume() {
        super.onResume();

        if (!OpenCVLoader.initDebug()) {
            Log.d(TAG, "Internal OpenCV library not found. Using OpenCV Manager for initialization");
            OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_0_0, this, mLoaderCallback);
        } else {
            Log.d(TAG, "OpenCV library found inside package. Using it!");
            mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
        }
    }


    @Override
    public void onCameraViewStarted(int width, int height) {
        Log.d(TAG, "onCameraViewStarted");

    }

    @Override
    public void onCameraViewStopped() {
        Log.d(TAG, "onCameraViewStopped");
    }

    @Override
    public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
        Log.d(TAG, "onCameraFrame");
        return null;
    }

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        Log.d(TAG, "onTouch");
        return false;
    }

}
2016-10-07 01:03:40 -0600 received badge  Editor (source)
2016-10-07 01:02:14 -0600 asked a question size of the same image is different when it is read differently

I am learning how to load/read images using opeCV with Android API. I have an image titled "arrow.png" in the drawable folder, and I tried to read the same image using two different ways as shown in the code below. the problem is, the size of the bitmap image produced by the following line

Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.arrow);

is 512x512. and when i converted that bitmap to Mat object, I got a Mat object with same size 512x512. But, when i read the same image as a Mat object using the follwoing line:

Mat mat = Utils.loadResource(MainActivity.this, R.drawable.arrow, Imgcodecs.CV_LOAD_IMAGE_UNCHANGED);

I get a Mat of size 256x256

why the previously mentioned two lines of code generate different sizes for the same image

update:

the original size of the image is 256x256

code

//1
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.arrow);
int bimapW = bitmap.getWidth();
int bitmapH = bitmap.getHeight();
Log.i(TAG, "bitmapW: " + bimapW);
Log.i(TAG, "bitmapH: " + bitmapH);

Mat bitmapToMat = new Mat();
Utils.bitmapToMat(bitmap, bitmapToMat);
Log.i(TAG, "size: " + bitmapToMat.size());

//2
try {
    Mat mat = Utils.loadResource(MainActivity.this, R.drawable.arrow, Imgcodecs.CV_LOAD_IMAGE_UNCHANGED);
    Log.i(TAG, "sizeMat: " + mat.size());
    } catch (IOException e) {
      e.printStackTrace();
    }
2016-10-07 00:57:23 -0600 asked a question how to get the size of an image in android

I am new to OpenCV in Android. I just wanted to make a samll test to the openCV lib in android. I downloaded an image .JPG and placed it inside the drawable folder, and I used the below code to read the image and display its size. when i run the below code i get the size of the image is 0x0 despite it is more than 400 kb.

why the size is 0x0 and how to get the right size?

code

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mLoaderCallback = new BaseLoaderCallback(this) {
        @Override
        public void onManagerConnected(int status) {
            switch (status) {
                case LoaderCallbackInterface.SUCCESS:
                    Log.i("OpenCV", "OpenCV loaded successfully");

                    Mat image = readImageFromResources();
                    Log.i(TAG, "size: " + image.size());
                    Log.i(TAG, "rows: " + image.rows());
                    Log.i(TAG, "cols: " + image.cols());

                    break;
                default:
                    super.onManagerConnected(status);
                    break;
            }
        }

        private Mat readImageFromResources() {
            return Imgcodecs.imread(getResources().getDrawable(R.drawable.see).toString());
        }
    };
}
2016-10-06 14:48:18 -0600 asked a question how to get the size of an image in android?

I am new to OpenCV in Android. I just wanted to make a samll test to the openCV library in android. I downloaded an image .JPG and placed it inside the drawable folder, and I used the below code to read the image and display its size. when I run the below code I get the size of the image is 0x0 despite it is more than 400 kb.

why the size is 0x0 and how to get the right size?

code

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mLoaderCallback = new BaseLoaderCallback(this) {
        @Override
        public void onManagerConnected(int status) {
            switch (status) {
                case LoaderCallbackInterface.SUCCESS:
                    Log.i("OpenCV", "OpenCV loaded successfully");

                    Mat image = readImageFromResources();
                    Log.i(TAG, "size: " + image.size());
                    Log.i(TAG, "rows: " + image.rows());
                    Log.i(TAG, "cols: " + image.cols());

                    break;
                default:
                    super.onManagerConnected(status);
                    break;
            }
        }

        private Mat readImageFromResources() {
            return Imgcodecs.imread(getResources().getDrawable(R.drawable.see).toString());
        }
    };
}
2016-10-06 09:25:32 -0600 received badge  Supporter (source)