I'm pretty new to android app development, and I'm currently working on a school project that requires my application to capture a video using my android phone and then detect an object in this case the object is a AA battery, using openCV, in the captured video. I'd like to know how I can have OpenCV detect an object in a pre-captured video using the video's uri, I am only capable of detecting an object using openCV's javaCameraView, which is in real-time.
If its not possible for OpenCV to do detection using only the video's URI are there other possible methods? Please note i must use openCV as this is a school project
Here's my java code for the video capturing:
public class MainActivity extends AppCompatActivity {
private Button mRecordView, mPlayView;
private VideoView mVideoView;
private Intent callVideoAppIntent;
private int ACTIVITY_START_CAMERA_APP = 0;
public Uri videoUri;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mRecordView = (Button) findViewById(R.id.btnRecord);
mPlayView = (Button) findViewById(R.id.btnPlay);
mVideoView = (VideoView) findViewById(R.id.videoview);
//Record Button OnClickListener
mRecordView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
callVideoAppIntent = new Intent();
callVideoAppIntent.setAction(MediaStore.ACTION_VIDEO_CAPTURE);
//startActivityForResult(Intent, int RequestCode);
//application capture video using phone camera,
//then returns to application after stopping.
startActivityForResult(callVideoAppIntent, ACTIVITY_START_CAMERA_APP);
}
});
//Play Button OnClickListener
mPlayView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mVideoView.start();
mPlayView.setEnabled(false);
mRecordView.setEnabled(false);
}
});
mVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mPlayView.setEnabled(true);
mRecordView.setEnabled(true);
}
});
}
//Once video captured and returned to application,
//we need to capture response,
//on activty result function.
protected void onActivityResult(int requestCode, int resultCode, Intent data){
if(requestCode == ACTIVITY_START_CAMERA_APP && resultCode == RESULT_OK) {
videoUri = data.getData();
mVideoView.setVideoURI(videoUri);
}
}
}