0
私はギャラリーから画像を選択して画像ビューで表示するための小さなアンドロイドアプリを持っています。 OpenCVを使って画像を表示する前に、画像上で何らかの処理をしたいのですが、OpenCVを使って何も表示できません。今、if文の末尾にコメント行は、作業を行うギャラリー、Android、OpenCVの画像を表示
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
try {
// When an Image is picked
if (requestCode == RESULT_LOAD_IMG && resultCode == RESULT_OK && null != data) {
// Get the Image from data
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
// Get the cursor
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
// Move to first row
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
imgDecodableString = cursor.getString(columnIndex);
cursor.close();
File file = new File(imgDecodableString);
Log.e(getString(R.string.app_name), "File exists: " + file.exists());
Log.e(getString(R.string.app_name), "Trying to read: " + file.getAbsolutePath());
image = Imgcodecs.imread(file.getAbsolutePath(),Imgcodecs.CV_LOAD_IMAGE_COLOR);
ImageView imgView = (ImageView) findViewById(R.id.imgView);
// Set the Image in ImageView after decoding the String
float[] matrixValuesF = new float[image.cols()*image.rows()];
double[] matrixValuesD = new double[matrixValuesF.length];
image.get(0, 0, matrixValuesD);
for (int i=0; i<matrixValuesD.length; i++) {
matrixValuesF[i] = (float) matrixValuesD[i];
}
Matrix android_matrix = new Matrix();
android_matrix.setValues(matrixValuesF);
imgView.setImageMatrix(android_matrix);
// imgView.setImageBitmap(BitmapFactory.decodeFile(imgDecodableString));
} else {
Toast.makeText(this, "You haven't picked Image",
Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
Toast.makeText(this, "Something went wrong", Toast.LENGTH_LONG)
.show();
}
}
が、私はそれを表示する前に画像を処理したい言ったように:以下にいくつかの関連するコードです。以下は
logcatファイルです:
E/MyApp: File exists: true
E/MyApp: Trying to read: /storage/emulated/0/images/img.jpg
D/OpenCV/StaticHelper: Trying to get library list
E/OpenCV/StaticHelper: OpenCV error: Cannot load info library for OpenCV
D/OpenCV/StaticHelper: Library list: ""
D/OpenCV/StaticHelper: First attempt to load libs
D/OpenCV/StaticHelper: Trying to init OpenCV libs
D/OpenCV/StaticHelper: Trying to load library opencv_java3
D/OpenCV/StaticHelper: Library opencv_java3 loaded
D/OpenCV/StaticHelper: First attempt to load libs is OK
私はアプリを実行すると、私はトーストのメッセージは「何かが間違っていた」と全くイメージがImageViewの中に表示されていないと言ってもらうのギャラリーから画像を選択した場合。
私はアンドロイドアプリの開発に慣れているので、何か簡単なものが見つからないことがあります。前もって感謝します。