当我尝试初始化MAt对象时,错误是不满足的。我在opencv加载成功后初始化它。但是错误。请提示你的观点。公共类NextActivity扩展Activity实现OnItemSelectedListener { 位图位图; ImageView imageView; String TAG =“FinalCamera”; int selectedFilter,selectedKMap; SeekBar seekBar; Mat imgMat,tmp;
//native function
//public native int convertNativeGray(long matAddrRgba, long matAddrGray,int selectedFilter,int ksize);
//loading and connecting to opencv library
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS:
{
System.loadLibrary("mixed_sample");
Log.i(TAG, "OpenCV loaded successfully");
} break;
default:
{
super.onManagerConnected(status);
} break;
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_next);
imageView=(ImageView)findViewById(R.id.imageView1);
// bitmap = getIntent().getExtras().getParcelable("name");
imageView.setImageBitmap(bitmap);
//for spinner
Spinner spinner = (Spinner) findViewById(R.id.filter_spinner);
// Create an ArrayAdapter using the string array and a default spinner layout
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.Filters, android.R.layout.simple_spinner_item);
// Specify the layout to use when the list of choices appears
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// Apply the adapter to the spinner
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(this);
//for kmap
seekBar = (SeekBar) findViewById(R.id.seekBar1);
seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
public void onProgressChanged(SeekBar seekBar, int progresValue, boolean fromUser) {
selectedKMap = progresValue;
System.out.println("The selected KMap is"+selectedKMap);
}
public void onStartTrackingTouch(SeekBar seekBar) {}
public void onStopTrackingTouch(SeekBar seekBar) {}
});
}
@Override
public void onResume()
{
super.onResume();
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_9, this, mLoaderCallback);
realProcessing();
}
public void realProcessing()
{
System.out.println("This is real processing");
bitmap = getIntent().getExtras().getParcelable("name");
bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
//here in below line there is error
tmp = new Mat (bitmap.getWidth(), bitmap.getHeight(), CvType.CV_8UC1);
// imgMat = new Mat (bitmap.getWidth(), bitmap.getHeight(), CvType.CV_8UC1);
// Utils.bitmapToMat(bitmap, tmp);
//convertNativeGray(tmp.getNativeObjAddr(), imgMat.getNativeObjAddr(),2,3);
//Utils.matToBitmap(imgMat, bitmap);
imageView.setImageBitmap(bitmap);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.next, menu);
return true;
}
@Override
//when seekbar an item is selected then this method will be called
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {
// TODO Auto-generated method stub
selectedFilter=pos+1;
System.out.println("This is selected filter="+selectedFilter);
}
@Override
//when nothing changed this method will be called
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
}
答案 0 :(得分:0)
你不能使用opencv代码,直到mLoaderCallback完成。
&#34;我在opencv成功加载后初始化它&#34; - 好吧,没有。你没有。
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_9, this, mLoaderCallback);
realProcessing();
OpenCVLoader.initAsync&lt; - async
您必须将realProcessing代码移至稍后阶段。要么在这里:
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS:
{
System.loadLibrary("mixed_sample");
Log.i(TAG, "OpenCV loaded successfully");
// yes, now it's safe !
} break;
或onCameraViewStarted(),onCameraFrame()。