|
楼主 |
发表于 2024-10-19 20:35:42
|
显示全部楼层
- // 读取图像
- string imagePath = "F18.JPG";
- Mat src = Cv2.ImRead(imagePath, ImreadModes.Color);
- if (src.Empty())
- {
- //Console.WriteLine("Could not open or find the image!");
- return;
- }
- // 将图像转换为灰度图像
- Mat gray = new Mat();
- Cv2.CvtColor(src, gray, ColorConversionCodes.BGR2GRAY);
- // 获取图像的尺寸
- int rows = gray.Rows;
- int cols = gray.Cols;
- // 创建一个二维数组来存储灰度值
- float[,] grayArray = new float[rows, cols];
- terrainData = new TerrainData(cols, rows);
- // 将灰度值从Mat复制到二维数组
- for (int i = 0; i < rows; i++)
- {
- for (int j = 0; j < cols; j++)
- {
- grayArray[i, j] = (float)(gray.Get<byte>(i, j));
- terrainData.terrainMap[j, i] = (float)(gray.Get<byte>(i, j));
- }
- }
- terrainData.ncols = cols;
- terrainData.nrows = rows;
- MessageBox.Show("已读取图像");
复制代码 |
|