Last active
October 16, 2019 23:13
-
-
Save johnolafenwa/4f5d7f2e803ee434720a214ed8d18f62 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.johnolafenwa.pytorchandroid; | |
import android.content.Intent; | |
import android.graphics.Bitmap; | |
import android.os.Bundle; | |
import android.provider.MediaStore; | |
import android.support.v7.app.AppCompatActivity; | |
import android.support.v7.widget.Toolbar; | |
import android.util.Log; | |
import android.view.View; | |
import android.widget.Button; | |
import java.io.File; | |
public class MainActivity extends AppCompatActivity { | |
int cameraRequestCode = 001; | |
Classifier classifier; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
Toolbar toolbar = findViewById(R.id.toolbar); | |
setSupportActionBar(toolbar); | |
classifier = new Classifier(Utils.assetFilePath(this,"mobilenet-v2.pt")); | |
Button capture = findViewById(R.id.capture); | |
capture.setOnClickListener(new View.OnClickListener(){ | |
@Override | |
public void onClick(View view){ | |
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); | |
startActivityForResult(cameraIntent,cameraRequestCode); | |
} | |
}); | |
} | |
@Override | |
protected void onActivityResult(int requestCode, int resultCode, Intent data){ | |
if(requestCode == cameraRequestCode && resultCode == RESULT_OK){ | |
Intent resultView = new Intent(this,Result.class); | |
resultView.putExtra("imagedata",data.getExtras()); | |
Bitmap imageBitmap = (Bitmap) data.getExtras().get("data"); | |
String pred = classifier.predict(imageBitmap); | |
resultView.putExtra("pred",pred); | |
startActivity(resultView); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment