Sample3View.java

Shishir Joshi, 2012-08-08 07:47 am

Download (1.2 kB)

 
1
package org.opencv.samples.tutorial3;
2
3
import android.content.Context;
4
import android.graphics.Bitmap;
5
6
class Sample3View extends SampleViewBase {
7
        
8
        private int mFrameSize;
9
        private Bitmap mBitmap;
10
        private int[] mRGBA;
11
12
    public Sample3View(Context context) {
13
        super(context);
14
    }
15
16
        @Override
17
        protected void onPreviewStared(int previewWidtd, int previewHeight) {
18
                mFrameSize = previewWidtd * previewHeight;
19
                mRGBA = new int[mFrameSize];
20
                mBitmap = Bitmap.createBitmap(previewWidtd, previewHeight, Bitmap.Config.ARGB_8888);
21
        }
22
23
        @Override
24
        protected void onPreviewStopped() {
25
                if(mBitmap != null) {
26
                        mBitmap.recycle();
27
                        mBitmap = null;
28
                }
29
                mRGBA = null;
30
                
31
                
32
        }
33
34
    @Override
35
    protected Bitmap processFrame(byte[] data) {
36
        int[] rgba = mRGBA;
37
38
        FindFeatures(getFrameWidth(), getFrameHeight(), data, rgba);
39
40
        Bitmap bmp = mBitmap; 
41
        bmp.setPixels(rgba, 0/* offset */, getFrameWidth() /* stride */, 0, 0, getFrameWidth(), getFrameHeight());
42
        return bmp;
43
    }
44
45
    public native void FindFeatures(int width, int height, byte yuv[], int[] rgba);
46
47
    static {
48
            System.loadLibrary("opencv_java");
49
        System.loadLibrary("native_sample");
50
    }
51
}