【问题标题】:Pleora SDK Horizontal Line Artifacts when saving bitmap to jpg将位图保存为 jpg 时 Pleora SDK 水平线伪影
【发布时间】:2019-02-20 21:54:04
【问题描述】:

我的 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);
}

有问题的示例图片:

这两条水平线就是我所说的。有时它们存在,有时不存在,有时只有 1 行。

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

【问题讨论】:

    标签: c# pleora-sdk


    【解决方案1】:

    而不是如上所述使用image.CopyToBitmap(bitmap);。当我为 PvStream 分配缓冲区时,我将 OpenCV Mat (Emgu) 附加到 PvImage 上。

    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
    );
    

    当我检索缓冲区时,我会进行颜色转换,因为相机会捕获 BayerRG8(平均花费大约 9 毫秒):

    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);
    

    似乎我再也没有得到任何文物了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-14
      相关资源
      最近更新 更多