如何设置相机的预览尺寸

时间:2016-11-14 14:30:04

标签: android camera android-camera

我正在尝试将预览和图片尺寸设置为相机的参数,如下面的代码所示。我还添加了一些日志声明,以确定大小设置正确。问题是我在logcat中有不同的大小 显示在下面的logcat输出部分。

请让我知道如何正确设置预览和图片尺寸。

tensorflow.python.framework.errors.InvalidArgumentError: Expected begin[0] == 0 (got 0) and size[0] == 0 (got 1) when input.dim_size(0) == 0
     [[Node: softmax_cross_entropy_loss/Slice_3 = Slice[Index=DT_INT32, T=DT_INT32, _device="/job:localhost/replica:0/task:0/gpu:0"](softmax_cross_entropy_loss/Shape_3, softmax_cross_entropy_loss/Slice_3/begin, softmax_cross_entropy_loss/Slice_3/size)]]

Caused by op u'softmax_cross_entropy_loss/Slice_3', defined at:
  File "train.py", line 103, in <module>
    FLAGS.log_dir)
  File "train.py", line 88, in main
    slim.losses.softmax_cross_entropy(predictions, labels)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/losses/python/losses/loss_ops.py", line 385, in softmax_cross_entropy
    return compute_weighted_loss(losses, weight)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/losses/python/losses/loss_ops.py", line 144, in compute_weighted_loss
    num_present = _num_present(losses, weight)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/losses/python/losses/loss_ops.py", line 179, in _num_present
    [0], [1]), [])
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/array_ops.py", line 431, in slice
    return gen_array_ops._slice(input_, begin, size, name=name)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_array_ops.py", line 2234, in _slice
    name=name)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/op_def_library.py", line 749, in apply_op
    op_def=op_def)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 2380, in create_op
    original_op=self._default_original_op, op_def=op_def)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1298, in __init__
    self._traceback = _extract_stack()

InvalidArgumentError (see above for traceback): Expected begin[0] == 0 (got 0) and size[0] == 0 (got 1) when input.dim_size(0) == 0
     [[Node: softmax_cross_entropy_loss/Slice_3 = Slice[Index=DT_INT32, T=DT_INT32, _device="/job:localhost/replica:0/task:0/gpu:0"](softmax_cross_entropy_loss/Shape_3, softmax_cross_entropy_loss/Slice_3/begin, softmax_cross_entropy_loss/Slice_3/size)]]

logcat输出

        mCamera = Camera.open(cameraId);

        Camera.Parameters parameters = mCamera.getParameters();
        parameters.setPreviewSize(400,400);
        parameters.setPictureSize(400, 400);
        mCamera.setParameters(parameters);

        mCamera.setDisplayOrientation(90);

        mPreviewWidth = mCamera.getParameters().getPreviewSize().width;
        mPreviewHeight = mCamera.getParameters().getPreviewSize().height;
        Log.d(TAG, "parameters mPreviewWidth: " + mPreviewWidth);
        Log.d(TAG, "parameters mPreviewHeight: " + mPreviewHeight);

1 个答案:

答案 0 :(得分:1)

您可以遍历所有sizeq并尝试最小化这些尺寸与预览尺寸之间的区域差异。

您可以查看this