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).
我正在尝试打开一个jpeg文件,这是我的应用程序的drawable。按照这个方法,我不知道如何设置变量“context”(这是函数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!
非常感谢!
4 个解决方案
#1
0
You need to learn more about Context.
您需要了解有关Context的更多信息。
Use getApplicationContext()
:
使用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
:
或YourActivityName.this:
Mat img = Utils.loadResource(YourActivityName.this, refrenceimgID, Highgui.CV_LOAD_IMAGE_COLOR);
#2
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
如果您在Fragment范围内,请使用getActivity()而不是此
#3
0
Just use your Activity instance
as MainActivity.this
where you need Context
.
只需将您的Activity实例用作MainActivity.this,您需要Context。
Or you can use your ApplicationClass instance as well.
或者您也可以使用ApplicationClass实例。
Read about Context here
在这里阅读有关上下文
#4
0
You can try the following code:
您可以尝试以下代码:
Context c= this;
Resources res2 = c.getResources();
Drawable drawable = res2.getDrawable(R.drawable.YOUR_DRAWABLE_NAME);
#1
0
You need to learn more about Context.
您需要了解有关Context的更多信息。
Use getApplicationContext()
:
使用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
:
或YourActivityName.this:
Mat img = Utils.loadResource(YourActivityName.this, refrenceimgID, Highgui.CV_LOAD_IMAGE_COLOR);
#2
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
如果您在Fragment范围内,请使用getActivity()而不是此
#3
0
Just use your Activity instance
as MainActivity.this
where you need Context
.
只需将您的Activity实例用作MainActivity.this,您需要Context。
Or you can use your ApplicationClass instance as well.
或者您也可以使用ApplicationClass实例。
Read about Context here
在这里阅读有关上下文
#4
0
You can try the following code:
您可以尝试以下代码:
Context c= this;
Resources res2 = c.getResources();
Drawable drawable = res2.getDrawable(R.drawable.YOUR_DRAWABLE_NAME);