代码之家  ›  专栏  ›  技术社区  ›  AJ Venturella

Pleora SDK将位图保存到jpg时出现水平线瑕疵

  •  0
  • AJ Venturella  · 技术社区  · 6 年前

    我的Pleora SDK是授权的,我不是说水印。

    有时它保存的很好,其他时候,虽然图像保存这些水平线文物。

    PvBuffer buffer;
    PvResult operationalResult;
    var filename = "...some filename...";
    var result = stream.RetieveBuffer(ref buffer, ref operationalResult, 100);
    
    if(result.IsOK())
    {
        PvImage image = buffer.Image;
        var bitmap = new System.Drawing.Bitmap(
            width: (int)image.Width,
            height: (int)image.Height,
            format: PixelFormat.Format24bppRgb
        );
    
        image.CopyToBitmap(bitmap);
    
        bitmap.save(filename, ImageFormat.Jpeg);
    }
    

    enter image description here

    这两条水平线就是我要说的。有时他们在场,有时不在场,有时只有一行。

    我能做些什么来避免这个问题?

    0 回复  |  直到 6 年前
        1
  •  0
  •   AJ Venturella    6 年前

    而不是使用 image.CopyToBitmap(bitmap); PvStream

    Mat mat = new Mat(
        rows: height, 
        cols: width, 
        type: DepthType.Cv8U, 
        channels: 1
    );
    
    buffer.Buffer.Image.Attach(
        aRawBuffer: (byte*)mat.DataPointer, // <-- Needs to be in an `unsafe` method
        aSizeX: (uint)width,
        aSizeY: (uint)height,
        aPixelType: PvPixelType.BayerRG8
    );
    

    当我检索缓冲区时,我会进行颜色转换,因为相机会捕捉到RG8(平均花费约9ms):

    Mat rgb = new Mat(rows: mat.Rows, cols: mat.Cols, type: DepthType.Cv8U, channels: 3);
    CvInvoke.CvtColor(matFromPvBuffer, rgb, ColorConversion.BayerRg2Rgb);
    

    除此之外:

    rgb.Bitmap.Save(path, ImageFormat.Jpeg);