0

嗨,伙计们正在开发一个 android 应用程序(浊度计应用程序),它捕获穿过水样的光并测量从水样中发出的光量,但我发现我必须能够裁剪它捕获的图像以便获得正确的读数,有人可以帮助 pliz。这是我的代码行。所以当我测量从干净水中出来的光量时,我得到的值很高,即 46(NTU),但对于干净的水,该值必须低于 5(NTU)是 SI 单位.so我被告知该算法正在计算整个图像,而不是仅计算感兴趣区域,即图像的亮区。

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();
4

1 回答 1

0

Here is part of the code that does the job in my app:

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();
            }
        }

}

The CropOption class:

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

}

And the corresponding Adapter:

 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;
    }

}

于 2013-11-02T19:00:37.487 回答