美文网首页
android 将yuyv数据提取y(灰度值),取前几个y数据将

android 将yuyv数据提取y(灰度值),取前几个y数据将

作者: 怪咖小青年_56e8 | 来源:发表于2023-04-27 16:12 被阅读0次
保存图片
public void saveImage(byte[] yuv, int[] rgb , int width, int height) {
        Bitmap text_bitmap = null;
        int t1 = 0 , t2 = 0 ,t3 = 0 ,t4 = 0 ,t5 = 0 ,t6 = 0 ,t7 = 0 ,t8 = 0 ,t9 = 0 ,t10 = 0 ,t11 = 0;
        t1 = 0xff & yuv[0];
        t2 = 0xff & yuv[1];
        t3 = 0xff & yuv[2];
        t4 = 0xff & yuv[3];
        t5 = 0xff & yuv[4];
        t6 = 0xff & yuv[5];
        t7 = 0xff & yuv[6];
        t8 = 0xff & yuv[7];
        t9 = 0xff & yuv[8];
        t10 = 0xff & yuv[9];
        t11 = 0xff & yuv[10];
        String strT6 = String.format("%02x", t6);//02拿两位十六进制 08拿八位十六进制
        String strT10 = String.format("%02x", t10);
        String strT11 = String.format("%02x", t11);
//        showShortMsg("y= "+strT10+"--"+strT11);
        text_bitmap = generateBitmap(t1+"",t2+"",t3+"",t4+"",t5+"","增益:0x"+strT6+"","LED:"+t7+"","亮度:"+t8+"","评分:"+t9+"","曝光:0x"+strT10+""+strT11,"注册:"+Cmd.regtime+"","识别:"+Cmd.identifytime+"",20,Color.RED);

        int y = 0;

        for (int i = 0; i < height; i++) {
            for (int j = 0; j < width; j++) {
                int dex = (i * width + j)*2;
                y = 0xff & yuv[dex];
                rgb[i*width + j] = 0xff000000| y << 16 | y << 8 | y;
                yuv_y[i*width + j] = yuv[dex];
            }
        }
        Bitmap bmp = Bitmap.createBitmap(rgb,width, height, Bitmap.Config.ARGB_8888);
        Bitmap adjustPhotoRotation = adjustPhotoRotation(bmp, 90);

        Bitmap combineBitmap = combineBitmap(adjustPhotoRotation, text_bitmap);

        if (!TextUtils.isEmpty(text1)&&!TextUtils.isEmpty(text2)&&!TextUtils.isEmpty(text3)&&!TextUtils.isEmpty(text4)&&!TextUtils.isEmpty(text5)&&!TextUtils.isEmpty(text6)&&!TextUtils.isEmpty(text7)) {
            fileName = System.currentTimeMillis()+"_"+tv_scene.getText()+"_"+textLh(text1)+"_"+textLh(text2)+"_"+textLh(text3)+"_"+textLh(text4)+"_"+textLh(text5)+"_"+textLh(text6)+"_"+text7 + ".jpg";

        }else {
            fileName = str = System.currentTimeMillis() +"_"+tv_scene.getText()+"_"+"7005"+"_"+"0301"+"_"+"0420"+"_"+"7005"+"_"+"0301"+"_"+"0420"+"_"+"00"+ ".jpg";

        }
        File appDir = new File(Environment.getExternalStorageDirectory(), "wy/"+getDate()+"/"+tv_scene.getText());
        if (!appDir.exists()) {
            appDir.mkdirs();
        }
        File file = new File(appDir, fileName);

        try {
            FileOutputStream fos = new FileOutputStream(file);
            //保存两张bitmap合并之后的jpg图片
            combineBitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
            fos.flush();
            fos.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
}
/**
 * 将 text 转成bitmap
 * */
public static Bitmap generateBitmap(String text1,String text2,String text3,String text4,String text5,String text6,String text7,String text8,String text9,String text10,String regtime,String identifytime,int textSizePx,int textColor){
    TextPaint textPaint = new TextPaint();
    textPaint.setTextSize(textSizePx);
    textPaint.setColor(textColor);
//    int width = (int) Math.ceil(textPaint.measureText(text));
    Paint.FontMetrics fontMetrics = textPaint.getFontMetrics();
//    int height = (int) Math.ceil(Math.abs(fontMetrics.bottom) + Math.abs(fontMetrics.top));
    Bitmap bitmap = Bitmap.createBitmap(960,640, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    canvas.drawText(text1,0,Math.abs(fontMetrics.ascent),textPaint);
    canvas.drawText(text2,450,Math.abs(fontMetrics.ascent),textPaint);
    canvas.drawText(text3,0,630,textPaint);
    canvas.drawText(text4,450,630,textPaint);
    canvas.drawText(text5,225,315,textPaint);
    canvas.drawText(text6,360,280,textPaint);
    canvas.drawText(text7,360,300,textPaint);
    canvas.drawText(text8,360,320,textPaint);
    canvas.drawText(text9,360,340,textPaint);
    canvas.drawText(regtime,360,360,textPaint);
    canvas.drawText(identifytime,360,380,textPaint);
    canvas.drawText(text10,360,400,textPaint);
    return bitmap;
}
/**
     * 整张jpg图片顺时针旋转90度
     * */
    Bitmap adjustPhotoRotation(Bitmap bm, final int orientationDegree) {

        Matrix m = new Matrix();
        m.setRotate(orientationDegree, (float) bm.getWidth() / 2, (float) bm.getHeight() / 2);

        try {
            Bitmap bm1 = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), m, true);

            return bm1;

        } catch (OutOfMemoryError ex) {
        }
        return null;

    }
  /**

     * 合并两张bitmap为一张

     *

     * @param background

     * @param foreground

     * @return Bitmap

     */

    public static Bitmap combineBitmap(Bitmap background, Bitmap foreground) {

        if (background == null) {

            return null;

        }

        int bgWidth = background.getWidth();

        int bgHeight = background.getHeight();

//        foreground =zoomImg(foreground,200,200);

        int fgWidth = foreground.getWidth();

        int fgHeight = foreground.getHeight();

        Bitmap newmap = Bitmap.createBitmap(bgWidth, bgHeight, Bitmap.Config.ARGB_8888);

        Canvas canvas = new Canvas(newmap);

        canvas.drawBitmap(background, 0, 0, null);

        canvas.drawBitmap(foreground, (bgWidth - fgWidth) / 2, (bgHeight - fgHeight) / 2, null);

        canvas.save();

        canvas.restore();

        return newmap;

    }

相关文章

  • 离散函数(discrete functions)备忘

    形式 x,y代表坐标(笛卡尔坐标系),其中的值可以是颜色,灰度等等 Moving Average 再我看来就是将图...

  • 2018-12-15多类别分类:一对多

    当我们有两个以上的类别时,我们将进行数据分类。将扩展我们的定义,不是y = {0,1},而是y = {0,1 .....

  • python数据样本不平衡处理

    # 将数据拆分为训练集和测试集 X_train,X_test,y_train,y_test = model_sel...

  • Fisher线性判别(FDA)

    Fisher线性判别思想是将高维数据找到一个最佳投影方向u,令Y=uX,然后根据投影结果Y这个一维数据找到分类阈值...

  • 线段树

    对于一组数据a[],线段树可以实现以下操作: 1.给定x,y,求区间[x,y]的和; 2.给定x,y,k,将区间[...

  • FFmpeg处理原始数据

    这里的原始数据指的是FFmpeg解码后的数据,对于音频就是PCM数据,对于视频就是YUV数据。 FFmpeg提取Y...

  • 关于this,作用域,属性,原型链的一个小练习

    getName方法里面返回name值,此时name值从作用域里面找,即var name = 'y';,返回y;将g...

  • MYSQL函数

    round() 函数: round(x,y): 根据y值将x四舍五入后保留小数点后y位,不够的补0 如果y是负数,...

  • 2018-02-28

    每条数据包含有若干个特征xi,模型需要计算数据属于y个类别的概率,然后取最大概率对应类别y作为该数据的归属类别。 ...

  • featList = [example[i] for examp

    该语句是将列表list,取一列元素数据的方法。运营原理为:先提取一行dataSet的数据,然后取该行数据的第“ i...

网友评论

      本文标题:android 将yuyv数据提取y(灰度值),取前几个y数据将

      本文链接:https://www.haomeiwen.com/subject/phxijdtx.html