Fix EmguCV针对图像宽不是4的倍数的改变bug修复
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using System.Configuration;
|
||||
using System.Configuration;
|
||||
using XP.Common.Configs;
|
||||
using XP.Common.Dump.Configs;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Prism.Mvvm;
|
||||
using Prism.Mvvm;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Prism.Ioc;
|
||||
using Prism.Ioc;
|
||||
using Prism.Modularity;
|
||||
using System.Resources;
|
||||
using XP.Common.Localization;
|
||||
|
||||
@@ -28,11 +28,11 @@ namespace XplorePlane.Services
|
||||
var formatted = new FormatConvertedBitmap(bitmapSource, PixelFormats.Gray8, null, 0);
|
||||
int width = formatted.PixelWidth;
|
||||
int height = formatted.PixelHeight;
|
||||
int stride = width;
|
||||
byte[] pixels = new byte[height * stride];
|
||||
formatted.CopyPixels(pixels, stride, 0);
|
||||
|
||||
var image = new Image<Gray, byte>(width, height);
|
||||
int stride = image.Bytes.Length / height;
|
||||
var pixels = new byte[height * stride];
|
||||
formatted.CopyPixels(pixels, stride, 0);
|
||||
image.Bytes = pixels;
|
||||
return image;
|
||||
}
|
||||
@@ -40,7 +40,19 @@ namespace XplorePlane.Services
|
||||
public static Image<Gray, byte> ToEmguCVFromPixels(byte[] pixels, int width, int height)
|
||||
{
|
||||
var image = new Image<Gray, byte>(width, height);
|
||||
image.Bytes = pixels;
|
||||
int required = image.Bytes.Length;
|
||||
if (pixels.Length == required)
|
||||
{
|
||||
image.Bytes = pixels;
|
||||
}
|
||||
else
|
||||
{
|
||||
int stride = required / height;
|
||||
var padded = new byte[required];
|
||||
for (int row = 0; row < height; row++)
|
||||
Buffer.BlockCopy(pixels, row * width, padded, row * stride, width);
|
||||
image.Bytes = padded;
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
@@ -50,8 +62,8 @@ namespace XplorePlane.Services
|
||||
|
||||
int width = emguImage.Width;
|
||||
int height = emguImage.Height;
|
||||
int stride = width;
|
||||
byte[] pixels = emguImage.Bytes;
|
||||
int stride = pixels.Length / height;
|
||||
|
||||
return BitmapSource.Create(width, height, 96, 96, PixelFormats.Gray8, null, pixels, stride);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user