-1

i'm trying to open a jpeg file which is a drawable of my app. Following this method I have no idea about how to set the variable "context" (that is the first parameter of the function loadResource).

My aim is just to load this image, extract some feature and compare it with the frames grabbed from camera. And to this end I would like some good suggested tutorial (i will use some feature matching method).

thanks a lot!

Community
  • 1
  • 1
user2614596
  • 630
  • 2
  • 11
  • 30

4 Answers4

0

If you are in Activity scope just write this:

Mat img = Utils.loadResource(this, refrenceimgID, Highgui.CV_LOAD_IMAGE_COLOR);
Imgproc.cvtColor(img, gryimg, Imgproc.COLOR_RGB2BGRA);

If you are in Fragment scope use getActivity() instead of this

Karzmu
  • 142
  • 1
  • 9
0

Just use your Activity instance as MainActivity.this where you need Context.

Or you can use your ApplicationClass instance as well.

Read about Context here

Praveen Sharma
  • 4,326
  • 5
  • 25
  • 45
0

You need to learn more about Context.

Use getApplicationContext():

Mat img = Utils.loadResource(getApplicationContext(), refrenceimgID, Highgui.CV_LOAD_IMAGE_COLOR);

Or if your code is on an activity, use this:

Mat img = Utils.loadResource(this, refrenceimgID, Highgui.CV_LOAD_IMAGE_COLOR);

or YourActivityName.this:

Mat img = Utils.loadResource(YourActivityName.this, refrenceimgID, Highgui.CV_LOAD_IMAGE_COLOR);
RyanB
  • 1,287
  • 1
  • 9
  • 28
  • thanks with getApplicationContext() it works!... i know that because i write a text with the sizes of the loaded image on the image frame grabbed from camera (i'm working in the onCameraFrame function)... but now if i want to show this image instead of the one grabbed from camera (simply by make the function return this new Mat) it doesn't work (i see black screen) – user2614596 Sep 24 '15 at 11:38
0

You can try the following code:

Context c= this;
Resources res2 = c.getResources();
Drawable drawable = res2.getDrawable(R.drawable.YOUR_DRAWABLE_NAME);
Elham Kohestani
  • 3,013
  • 3
  • 20
  • 29