|
|
@@ -1,4 +1,4 @@ |
|
|
package com.mindspore.classificationforcar.widget; |
|
|
|
|
|
|
|
|
package com.mindspore.classificationforpet.widget; |
|
|
|
|
|
|
|
|
import android.Manifest; |
|
|
import android.Manifest; |
|
|
import android.content.DialogInterface; |
|
|
import android.content.DialogInterface; |
|
|
@@ -31,11 +31,11 @@ import androidx.core.content.FileProvider; |
|
|
import androidx.recyclerview.widget.GridLayoutManager; |
|
|
import androidx.recyclerview.widget.GridLayoutManager; |
|
|
import androidx.recyclerview.widget.RecyclerView; |
|
|
import androidx.recyclerview.widget.RecyclerView; |
|
|
|
|
|
|
|
|
import com.mindspore.classificationforcar.R; |
|
|
|
|
|
import com.mindspore.classificationforcar.gallery.classify.BitmapUtils; |
|
|
|
|
|
import com.mindspore.classificationforcar.gallery.classify.ImageTrackingMobile; |
|
|
|
|
|
import com.mindspore.classificationforcar.gallery.classify.RecognitionImageBean; |
|
|
|
|
|
import com.mindspore.classificationforcar.gallery.classify.TrackingMobile; |
|
|
|
|
|
|
|
|
import com.mindspore.classificationforpet.R; |
|
|
|
|
|
import com.mindspore.classificationforpet.gallery.classify.BitmapUtils; |
|
|
|
|
|
import com.mindspore.classificationforpet.gallery.classify.ImageTrackingMobile; |
|
|
|
|
|
import com.mindspore.classificationforpet.gallery.classify.RecognitionImageBean; |
|
|
|
|
|
import com.mindspore.classificationforpet.gallery.classify.TrackingMobile; |
|
|
|
|
|
|
|
|
import java.io.File; |
|
|
import java.io.File; |
|
|
import java.io.FileNotFoundException; |
|
|
import java.io.FileNotFoundException; |
|
|
@@ -52,18 +52,16 @@ public class MainActivity extends AppCompatActivity implements OnBackgroundImage |
|
|
private static final int REQUEST_PERMISSION = 0; |
|
|
private static final int REQUEST_PERMISSION = 0; |
|
|
|
|
|
|
|
|
private static final int[] IMAGES = {R.drawable.style0, R.drawable.style1, R.drawable.style2, R.drawable.style3, R.drawable.style4, |
|
|
private static final int[] IMAGES = {R.drawable.style0, R.drawable.style1, R.drawable.style2, R.drawable.style3, R.drawable.style4, |
|
|
R.drawable.style5, R.drawable.style6, R.drawable.style7, R.drawable.style8, R.drawable.style9, |
|
|
|
|
|
R.drawable.style10, R.drawable.style11, R.drawable.style12, R.drawable.style13, R.drawable.style14, |
|
|
|
|
|
R.drawable.style15, R.drawable.style16, R.drawable.style17, R.drawable.style18, R.drawable.style19}; |
|
|
|
|
|
|
|
|
R.drawable.style5, R.drawable.style6, R.drawable.style7, R.drawable.style8, R.drawable.style9}; |
|
|
|
|
|
|
|
|
private static final int RC_CHOOSE_PHOTO = 1; |
|
|
private static final int RC_CHOOSE_PHOTO = 1; |
|
|
private static final int RC_CHOOSE_CAMERA = 2; |
|
|
private static final int RC_CHOOSE_CAMERA = 2; |
|
|
private static final String IMAGE_SCENE_MS = "model/mobilenetv2.ms"; |
|
|
private static final String IMAGE_SCENE_MS = "model/mobilenetv2.ms"; |
|
|
|
|
|
|
|
|
private boolean isAllGranted; |
|
|
private boolean isAllGranted; |
|
|
private static final String CAR_MS = "car.ms"; |
|
|
|
|
|
private File ROOT_FILE = new File(Environment.getExternalStorageDirectory().getAbsoluteFile(), "CarClassification"); |
|
|
|
|
|
private File DIR_FILE = new File(ROOT_FILE, CAR_MS); |
|
|
|
|
|
|
|
|
private static final String Pet_MS = "pet.ms"; |
|
|
|
|
|
private File ROOT_FILE = new File(Environment.getExternalStorageDirectory().getAbsoluteFile(), "PetClassification"); |
|
|
|
|
|
private File DIR_FILE = new File(ROOT_FILE, Pet_MS); |
|
|
|
|
|
|
|
|
private ImageView imgPreview; |
|
|
private ImageView imgPreview; |
|
|
private Uri imageUri; |
|
|
private Uri imageUri; |
|
|
@@ -153,7 +151,7 @@ public class MainActivity extends AppCompatActivity implements OnBackgroundImage |
|
|
builder.show(); |
|
|
builder.show(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public boolean isHasCarModelFile() { |
|
|
|
|
|
|
|
|
public boolean isHasPetModelFile() { |
|
|
if (DIR_FILE.exists()) { |
|
|
if (DIR_FILE.exists()) { |
|
|
return true; |
|
|
return true; |
|
|
} else { |
|
|
} else { |
|
|
@@ -183,7 +181,7 @@ public class MainActivity extends AppCompatActivity implements OnBackgroundImage |
|
|
public void onClickScene(View view) { |
|
|
public void onClickScene(View view) { |
|
|
Intent intent = new Intent(MainActivity.this, CameraActivity.class); |
|
|
Intent intent = new Intent(MainActivity.this, CameraActivity.class); |
|
|
intent.putExtra("FILEPATH", DIR_FILE.getPath()); |
|
|
intent.putExtra("FILEPATH", DIR_FILE.getPath()); |
|
|
intent.putExtra("ISHASCARMODELFILE", isHasCarModelFile()); |
|
|
|
|
|
|
|
|
intent.putExtra("ISHASPetMODELFILE", isHasPetModelFile()); |
|
|
startActivity(intent); |
|
|
startActivity(intent); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@@ -256,7 +254,7 @@ public class MainActivity extends AppCompatActivity implements OnBackgroundImage |
|
|
private void initMindspore(Bitmap bitmap) { |
|
|
private void initMindspore(Bitmap bitmap) { |
|
|
progressBar.setVisibility(View.VISIBLE); |
|
|
progressBar.setVisibility(View.VISIBLE); |
|
|
|
|
|
|
|
|
if (isHasCarModelFile()) { |
|
|
|
|
|
|
|
|
if (isHasPetModelFile()) { |
|
|
boolean ret = trackingMobile.loadModelFromBuf(DIR_FILE.getPath()); |
|
|
boolean ret = trackingMobile.loadModelFromBuf(DIR_FILE.getPath()); |
|
|
if (!ret) { |
|
|
if (!ret) { |
|
|
textResult.setText("Load model error."); |
|
|
textResult.setText("Load model error."); |