2019-10-31 17:00:52 +01:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using OpenCvSharp;
|
|
|
|
|
|
|
|
|
|
namespace Squirrowse.Core.Services
|
|
|
|
|
{
|
|
|
|
|
public static class ImgExtensions
|
|
|
|
|
{
|
|
|
|
|
public static byte[] ConvertToJpgByte(this Mat mat)
|
|
|
|
|
{
|
2019-11-04 09:29:37 +01:00
|
|
|
|
Cv2.ImEncode(".jpg", mat, out var imgbuffer); //no need to dispose
|
2019-10-31 17:00:52 +01:00
|
|
|
|
return imgbuffer.Any() ? imgbuffer : new byte[] { };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Mat ConvertByteToMat(this byte[] bytearr)
|
|
|
|
|
{
|
2019-11-06 13:47:00 +01:00
|
|
|
|
var tempMat = Cv2.ImDecode(bytearr, ImreadModes.Unchanged); //keep as disposable
|
2019-10-31 17:00:52 +01:00
|
|
|
|
return tempMat ?? new Mat();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|