Pleora SDK Horizontal Line Artifacts when saving bitmap to jpg

274 views Asked by At

My Pleora SDK is licensed, I am not talking about the watermark.

Sometimes it saves just fine, other times though the images saves with these horizontal line artifacts.

I'm saving the image like this:

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

Example image with issue:

enter image description here

Those 2 horizontal lines are what I am talking about. Sometimes they are present, sometimes not, sometimes it's only 1 line.

What could I be doing differently to avoid this issue?

1

There are 1 answers

0
AJ Venturella On BEST ANSWER

Instead of using image.CopyToBitmap(bitmap); as outlined above. I attached an OpenCV Mat (Emgu) to the PvImage when I allocate buffers for the 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
);

When I retrieve the buffer, I do a color conversion since the camera captures BayerRG8 (costs about 9ms on average):

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

And save that:

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

Seems I get no artifacts anymore.