【问题标题】:Why is custom camera image quality not as high as system camera?为什么自定义摄像头画质不如系统摄像头?
【发布时间】:2017-02-09 05:43:26
【问题描述】:

与使用 camera2 api 的系统相机相比,我的自定义相机结果图像质量较差。

我的应用基于 Camera2Basic 示例。 并且所有模式都设置为自动并使用最大的可用尺寸。

JPEG 结果:

自定义相机:3984x2988, 630KB

原生相机:3984x2988,2.73MB

所有开源示例都有几乎相同的输出。有什么办法可以得到更好的输出吗? 任何帮助将不胜感激!

【问题讨论】:

  • 您是否尝试将比特率设置为与从本机相机应用程序拍摄的视频中找到的值相同的值?
  • @LouisCAD 不,因为我只是拍照
  • 您的捕获请求使用了哪个模板?

标签: android android-camera2


【解决方案1】:

请查看CameraView。 这是一个自定义的相机实现,我认为它会给你一个合适的起点。

【讨论】:

  • 我已经测试了他们的演示,结果不是我预期的:(
  • 它正在工作,但我的问题是为什么图像质量不如 native camera 的质量
  • 好吧,从哪里开始,原生相机应用程序可以通过后期处理进行很多优化,这也取决于制造商,因为相机是一个受到很多关注的功能。然后有 HDR 模式或其他模式使用不同的技术来调整曝光。长话短说,我的建议是,如果你想知道为什么高质量你应该检查为你正在使用的设备完成的设备特定优化。
  • 是的没错,我相信它不能和原生相机一样。
  • 我应该处理原始传感器图像以获得更好的结果吗?
【解决方案2】:

有这个很棒的开放式相机应用程序。它是开源的,你可以检查他是如何保存图像的。我认为您的问题是图像保存。您的图像比原始图像小,这就是您的图像质量低下的原因。这是开放的相机网站http://opencamera.sourceforge.net/。开启摄像头支持摄像头api 1和api 2。

【讨论】:

  • 我之前测试过这个应用,和camera2basic一样
  • 如果您通过打开相机以全分辨率拍摄图像。这个大小小于 1mb 吗?
  • 是的,使用三星 s6 是 541KB
  • 好吧。我在我的 Honor 8 上测试了打开的相机应用程序,我的图像是 1,97Mb。也许三星 google camera api 2 有故障或未完成。
  • 如果你改变图像类型,结果还是一样吗?
【解决方案3】:

这是使用相机全分辨率的应用程序:

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.osahub.rachit.highrescamera"
      xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme">
    <activity
        android:name=".CameraActivity"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>

            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
</application>

CameraActivity.java

package com.osahub.rachit.highrescamera;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.ShareActionProvider;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import java.io.File;

public class CameraActivity extends AppCompatActivity {

    ImageView image;
    Button camera;
    Uri imageUri;
    private String folderPath = Environment.getExternalStorageDirectory()
        .getPath() + "/CameraActivity/images";
    private File file;

    private ShareActionProvider mShareActionProvider;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_camera);
        camera = (Button) findViewById(R.id.camera);
        image = (ImageView) findViewById(R.id.image);
        File folder = new File(folderPath);
        folder.mkdirs();

        file = new File(folder.getPath() + "/image.jpg");
        camera.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                imageUri = Uri.fromFile(file);
                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
                startActivityForResult(intent, 10);
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        try {
            Bitmap bp = MediaStore.Images.Media.getBitmap(this.getContentResolver(), imageUri);
            Matrix rotateMatrix = new Matrix();
            rotateMatrix.postRotate(90);
            Bitmap rotatedBitmap = Bitmap.createBitmap(bp, 0, 0, bp.getWidth(),
                bp.getHeight(), rotateMatrix, false);
            camera.setVisibility(View.GONE);
            image.setImageBitmap(rotatedBitmap);
            setShareIntent(createShareIntent());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_camera, menu);

        MenuItem item = menu.findItem(R.id.action_share);
        mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(item);

        setShareIntent(createShareIntent());
        return true;
    }

    private void setShareIntent(Intent shareIntent) {
        if (mShareActionProvider != null) {
            mShareActionProvider.setShareIntent(shareIntent);
        }
    }

    private Intent createShareIntent() {
        Intent shareIntent = new Intent();
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
        shareIntent.setType("image/*");
        return shareIntent;
    }
}

activity_camera.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:paddingBottom="@dimen/activity_vertical_margin"
                android:paddingLeft="@dimen/activity_horizontal_margin"
                android:paddingRight="@dimen/activity_horizontal_margin"
                android:paddingTop="@dimen/activity_vertical_margin"
                tools:context=".CameraActivity">

    <Button
        android:id="@+id/camera"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:text="@string/open_camera"/>

    <ImageView
        android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentStart="true"
        android:layout_alignTop="@+id/camera"
        android:contentDescription="@string/image_description"/>
</RelativeLayout>

【讨论】:

  • 感谢您的努力,但我正在使用自定义相机
【解决方案4】:

经过一番研究,我找到了解决方案。 这个github代码对我帮助很大:https://github.com/webjb/myrobot

我正在使用 YUV_420_888 格式从相机拍摄图像,并使用 NDK 将其字节缓冲区传递给 opencv,opencv 保存为 jpeg。

质量很高,文件大小超过 2MB!

【讨论】:

  • @muddin,嗨,伙计,我知道这个帖子是很久以前写的(2017 年 1 月开始),但我的情况与您在问题中描述的情况非常相似现在。我正在尝试制作相机应用程序,但由于某种原因,输出的文件大小比本机相机应用程序输出小得多,而且看起来有点模糊/质量低下。这就是为什么我来到这个帖子,我在这里看到了你的评论^^。但我不知道什么是 opencv/NDK 以及这个 YUV_420_888 图像格式是什么。是否有任何指南可以帮助我提高输出图像质量?
【解决方案5】:

我找到了其他解决方案。这是最好的。我只是使用samsung camera sdk。非常棒,效果比自定义相机好很多,几乎和原生相机应用一样。

【讨论】:

    【解决方案6】:

    一种快速的解决方案是您可以使用Camera Parameters 仅设置方向,但不能设置图像的高度和宽度。像这样。

    if (this.getResources().getConfiguration().orientation!= Configuration.ORIENTATION_LANDSCAPE) {
        params.set("orientation","portrait");
        camera.setDisplayOrientation(90);
        params.setRotation(90);
    } else {
        params.set("orientation","landscape");
        camera.setDisplayOrientation(0);
        params.setRotation(0);
    }
    // params.setPictureSize(msize.width,msize.height);
    camera.setParameters(params);`
    

    我得到了this post的关键帮助。

    【讨论】:

      猜你喜欢
      • 2020-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-18
      相关资源
      最近更新 更多