請問各位大佬,c#怎么讀入一個二維陣列來繪圖呢?我是想用c#來做影像的canny邊緣檢測,這個二維陣列就相當于灰度圖片的灰度值,
下面的代碼還用到了c#的指標,不知道我使用的對不對,
StreamReader sr;
String line;
List<int[]> datas = new List<int[]>(200);
string dataFilePath = @"E:\0831下午實驗資料\縫隙1(16922).txt"; //工況5
//string dataFilePath = @"C:\Users\wufeng\Desktop\縫隙1(16922).txt"; //工況5
sr = new StreamReader(dataFilePath, Encoding.Default);
while ((line = sr.ReadLine()) != null)
{
if (line != "")
{
string[] strLine = line.Split(' ');
int[] data = Array.ConvertAll(strLine, int.Parse);//將string型別的陣列轉換成int型別陣列
datas.Add(data);
}
}
int[][] all = datas.ToArray();//待處理的二維陣列
int width = all.Length;
int height = all[0].Length;
int stride = width * 4;
unsafe
{
fixed (int* intPtr = &all[10][10])
{
bitmap = new Bitmap(width, height, stride, PixelFormat.Format32bppRgb, new IntPtr(intPtr));
Mat mat = OpenCvSharp.Extensions.BitmapConverter.ToMat(bitmap); //bitmap轉 mat
Cv2.ImShow("Demo", mat);
// Cv2.Canny(mat,mat,1,3 );
Cv2.WaitKey(0);
}
}
生成的圖片是如下

把二維陣列轉置了之后如下

但是我使用MATLAB繪制的影像是這樣的

煩請各位能解答一下,感謝感謝。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/238287.html
標籤:C#
