2017-03-15 101 views
-1

现在,我已将OpenCV导入并在Android Studio应用程序中工作。所有的应用程序,当打开时,主要活动在Galaxy Tab上打开相机,就是这样。我希望能够捕捉和保存图像。有谁知道如何去做这个或知道一个链接,我可以按照进一步了解它?每当我Google如何捕捉图像,我都没有得到任何有用的信息。任何帮助是极大的赞赏。谢谢。如何使用OpenCV在Android Studio中捕捉图像

回答

1

你可以使用一个按钮,指导用户到相机,当图片被拍摄时,它显示在一个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 
    }