2013-11-02 4 views
0

안녕하세요 여러분, 물 샘플을 통과하는 빛을 캡처하고 그 물 샘플에서 나오는 빛의 양을 측정하는 안드로이드 응용 프로그램 (탁도 미터 응용 프로그램)에서 일하고 있지만 발견 나는 누군가가 pliz를 도울 수있는 적절한 판독 값을 얻기 위해 캡처 한 이미지를자를 수 있어야합니다. 여기 내 코드 줄이 있습니다. 그래서 깨끗한 물에서 나오는 빛의 양을 측정 할 때 나는 값이 높습니다. 즉 46 (NTU)이고 깨끗한 물에 대해서는 값이 5 (NTU) 미만이어야합니다. SI 단위입니다. 그래서 알고리즘은 이미지의 밝은 영역 인 관심 영역을 계산하는 대신 전체 이미지를 계산한다고 들었습니다. 여기android에서 이미지 자르기 방법

PictureCallback callback = new PictureCallback() { 
     @Override 
     public void onPictureTaken(byte[] data, Camera camera) { 
      Log.i(TAG, "Saving a bitmap to file"); 


       if (OpenCVLoader.initDebug()) { 

       Log.d("work", "work"); 

        Bitmap picture = BitmapFactory.decodeByteArray(data, 0, data.length); 
       Log.i("camera open", "n"); 

       imgToProcess=new Mat(); 


        Utils.bitmapToMat(picture, imgToProcess); 

        Log.d("work", "work"); 

       Imgproc.cvtColor(imgToProcess, imgToProcess, Imgproc.COLOR_RGB2GRAY); 

       t = Core.mean(imgToProcess).toString(); 
+0

http://docs.opencv.org/java/org/opencv/core/Mat.html#submat(int,%20int,%20int,%20int) – berak

답변

0

내 응용 프로그램에서 작업을 수행하는 코드의 일부입니다

private void doCrop() { 

     final ArrayList<CropOption> cropOptions = new ArrayList<CropOption>(); 

     Intent intent = new Intent("com.android.camera.action.CROP"); 
     intent.setType("image/*"); 

     List<ResolveInfo> list = getPackageManager().queryIntentActivities(
       intent, 0); 

     int size = list.size(); 

     if (size == 0) { 
      Toast.makeText(this, res.getString(R.string.no_crop_app), 
        Toast.LENGTH_SHORT).show(); 

      return; 
     } else { 
      intent.setData(mImageCaptureUri); 

      intent.putExtra("outputX", 256); 
      intent.putExtra("outputY", 256); 
      intent.putExtra("aspectX", 1); 
      intent.putExtra("aspectY", 1); 
      intent.putExtra("scale", true); 
      intent.putExtra("return-data", true); 

      if (size == 1) { 
       Intent i = new Intent(intent); 
       ResolveInfo res = list.get(0); 

       i.setComponent(new ComponentName(res.activityInfo.packageName, 
         res.activityInfo.name)); 

       startActivityForResult(i, ACTIVITY_CROP_FROM_CAMERA); 
      } else { 
       for (ResolveInfo res : list) { 
        final CropOption co = new CropOption(); 

        co.title = getPackageManager().getApplicationLabel(
          res.activityInfo.applicationInfo); 
        co.icon = getPackageManager().getApplicationIcon(
          res.activityInfo.applicationInfo); 
        co.appIntent = new Intent(intent); 

        co.appIntent 
        .setComponent(new ComponentName(
          res.activityInfo.packageName, 
           res.activityInfo.name)); 

        cropOptions.add(co); 
       } 

       CropOptionAdapter adapter = new CropOptionAdapter(
         getApplicationContext(), cropOptions); 

       AlertDialog.Builder builder = new AlertDialog.Builder(this); 
       builder.setTitle(res.getString(R.string.get_crop_app)); 
       builder.setAdapter(adapter, 
         new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, int item) { 
          startActivityForResult(
            cropOptions.get(item).appIntent, 
            ACTIVITY_CROP_FROM_CAMERA); 
         } 
       }); 

       builder.setOnCancelListener(new DialogInterface.OnCancelListener() { 
        public void onCancel(DialogInterface dialog) { 
         if (mImageCaptureUri != null) { 
          getContentResolver().delete(mImageCaptureUri, null, 
            null); 
          mImageCaptureUri = null; 
         } 
        } 
       }); 

       AlertDialog alert = builder.create(); 

       alert.show(); 
      } 
     } 

} 

CropOption 클래스 :

public class CropOption { 
      public CharSequence title; 
      public Drawable icon; 
      public Intent appIntent; 

}

그리고 해당 어댑터 :

class CropOptionAdapter extends ArrayAdapter<CropOption> { 
    private ArrayList<CropOption> mOptions; 
    private LayoutInflater mInflater; 

    public CropOptionAdapter(Context context, ArrayList<CropOption> options) { 
      super(context, R.layout.crop_selector, options); 
      mOptions  = options; 
      mInflater  = LayoutInflater.from(context); 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup group) { 
      if (convertView == null) 
        convertView = mInflater.inflate(R.layout.crop_selector, null); 

      CropOption item = mOptions.get(position); 

      if (item != null) { 
        ((ImageView) convertView.findViewById(R.id.iv_crop_icon)).setImageDrawable(item.icon); 
        ((TextView) convertView.findViewById(R.id.tv_crop_name)).setText(item.title); 

        return convertView; 
      } 

      return null; 
    } 

}

관련 문제