Extract black and white image from android camera's NV21 format

前端 未结 6 1774
你的背包
你的背包 2020-11-28 02:18

I have done some google-ing around and couldn\'t find enough information about this format. It is the default format for camera preview. Can anyone suggest good sources of i

6条回答
  •  盖世英雄少女心
    2020-11-28 02:34

    When you only need a grayscale camera preview, you could use a very simple renderscript:

    # pragma version(1)
    # pragma rs java_package_name(com.example.name)
    # pragma rs_fp_relaxed
    
    rs_allocation gIn;   // Allocation filled with camera preview data (byte[])
    int previewwidth;    // camera preview width (int)
    
    // the parallel executed kernel
    void root(uchar4 *v_out, uint32_t x,uint32_t y){
       uchar c = rsGetElementAt_uchar(gIn,x+y*previewwidth); 
       *v_out = (uchar4){c,c,c,255};
    }
    

    Note : This is not faster than ScriptIntrinsicYuvToRGB (and a following ScriptIntrinsicColorMatrix to do the RGBA-> gray), but it runs with API 11+ (where the Intrinsics need Api 17+).

提交回复
热议问题