-1
現在,我已將OpenCV導入並在Android Studio應用程序中工作。所有的應用程序,當打開時,主要活動在Galaxy Tab上打開相機,就是這樣。我希望能夠捕捉和保存圖像。有誰知道如何去做這個或知道一個鏈接,我可以按照進一步瞭解它?每當我Google如何捕捉圖像,我都沒有得到任何有用的信息。任何幫助是極大的讚賞。謝謝。如何使用OpenCV在Android Studio中捕捉圖像
現在,我已將OpenCV導入並在Android Studio應用程序中工作。所有的應用程序,當打開時,主要活動在Galaxy Tab上打開相機,就是這樣。我希望能夠捕捉和保存圖像。有誰知道如何去做這個或知道一個鏈接,我可以按照進一步瞭解它?每當我Google如何捕捉圖像,我都沒有得到任何有用的信息。任何幫助是極大的讚賞。謝謝。如何使用OpenCV在Android Studio中捕捉圖像
你可以使用一個按鈕,指導用戶到相機,當圖片被拍攝時,它顯示在一個imageView中。
下面是代碼: -
ImageView im =(ImageView)findViewById(R.id.imageid); //Your image View
Button b=(Button)findViewById(R.id.Buttonid); // your Button
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent img = new Intent(); //Your Intent
img.setAction(MediaStore.ACTION_IMAGE_CAPTURE); //the intents action to capture the image
startActivityForResult(img,1);//start the activity adding any code .1 in this example
}
});
protected void onActivityResult(int requestCode,int resultCode,Intent data){
super.onActivityResult(requestCode,resultCode,data);//method retrieves the requestCode , its result and the data containing the pic from system
if(requestCode==1&&resultCode==RESULT_OK){
Bitmap photo = (Bitmap)data.getExtras().get("data"); //get data and casts it into Bitmap photo
im.setImageBitmap(photo);// set photo to imageView
}