1

カメラのプレビューで画像処理を実行しようとしていますが、遅すぎるため、サンプル時間の画像の下で、より小さなスケールで処理を行います。次に、処理された (しきい値が設定された) 画像をプレビューに重ねます。私の問題は、カメラのプレビューに合わせて小さい画像をスケーリングすると、ピクセルが同じサイズのままになることです...スケーリングのために大きなピクセルを見たいのですが、できません。

XML は次のとおりです。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:keepScreenOn="true"
    android:orientation="vertical" >

    <SurfaceView
        android:id="@+id/svPreview"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <SurfaceView
        android:id="@+id/svOverlay"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:adjustViewBounds="true" />
</RelativeLayout>

そして、カメラ プレビュー イメージのバイトを取得し、しきい値処理を行うスレッド:

class PathThread extends Thread implements PreviewCallback
{
    private final int width, height;
    private final SurfaceHolder holder;
    private Canvas overlayCanvas;
    private int samples = 8;

    final private float scale;
    final private Paint red, blue, yellow;

    public PathThread(int canvasWidth, int canvasHeight, SurfaceView canvasView)
    {
        // This is how much smaller image I want
        width = canvasWidth / samples;
        height = canvasHeight / samples;
        holder = canvasView.getHolder();

        // Scale to fit the camera preview SurfaceView
        scale = (float) canvasView.getWidth() / height;

        // No smoothing when scaling please
        yellow = new Paint();
        yellow.setColor(Color.parseColor("#ffbb33"));
        yellow.setAntiAlias(false);  
        yellow.setDither(false);  
        yellow.setFilterBitmap(false);
    }

    public void onPreviewFrame(byte[] data, Camera camera)
    {
        overlayCanvas = holder.lockCanvas();
        overlayCanvas.drawColor(0, Mode.CLEAR);
        overlayCanvas.scale(scale, scale);

        // Do the image processing and make a [samples] times smaller image
        // Boring, pseudo-optimized, per-pixel thresholding process

        holder.unlockCanvasAndPost(overlayCanvas);
    }
}

結果は次のとおりです。

スケーリングされたオーバーレイ ピクセルは元のサイズです

少しずれていることは承知していますが、それは私の問題の中で最も少ないものです.

4

1 に答える 1

1

解決:

さらに2日間検索した後、それは非常に単純でしたが、見つけたり理解したりするのはそれほど簡単ではありませんでした。

私が描くSurfaceViewのホルダーで、私はこれを呼び出さなければなりませんでした:

canvasHolder.setFixedSize(width, height);

さまざまな値を試して、必要なものを見つけました。これにより、大きなピクセルが作成されます。

于 2012-09-10T21:40:22.753 に答える