Emgu Matrix[Double] matrix = new Matrix[Double](height, width)的简单应用

本文介绍了一个简单的矩阵创建及元素赋值方法,并展示了如何通过特定组件显示该矩阵。使用了Matrix<Double>类创建一个5x7的矩阵,并通过双重循环为每个元素赋值。
//Matrix<Double> matrix = new Matrix<Double>(height, width);
    private void button1_Click(object sender, EventArgs e)
    {
        //创建一个矩阵
        Matrix<Double> matrix1 = new Matrix<Double>(5, 7);

        double element = 0;
        //设置矩阵元素值
        for (int i = 0; i < 5; i++)
        {
            for (int j = 0; j < 7; j++)
            {
                matrix1.Data[i, j] = element;
                element++;
            }
        }
        //显示
        matrixBox1.Matrix = matrix1;
    }
using System; using System.Collections.Generic; using System.Drawing; using Emgu.CV; using Emgu.CV.CvEnum; using Emgu.CV.Structure; using MathNet.Numerics; namespace ImageProcessingExample { class Program { static void Main(string[] args) { // 读取图像 Image<Bgr, byte> originalImage = new Image<Bgr, byte>("path_to_your_image.jpg"); // 图像金字塔预处理 List<Image<Bgr, byte>> imagePyramid = GenerateImagePyramid(originalImage, 3); // 取金字塔中的某一层进行后续处理,这里取最后一层 Image<Bgr, byte> processedImage = imagePyramid[imagePyramid.Count - 1]; // 假设我们已经有了一些目标点的坐标,这里简单模拟 List<Point> targetPoints = new List<Point>(); Random random = new Random(); for (int i = 0; i < 10; i++) { targetPoints.Add(new Point(random.Next(processedImage.Width), random.Next(processedImage.Height))); } // 使用DBSCAN聚类 List<List<Point>> clusters = DBSCANClustering(targetPoints, 10, 3); // 在图像上绘制正方形框选目标 DrawBoundingBoxes(processedImage, clusters); // 显示处理后的图像 CvInvoke.Imshow("Processed Image", processedImage); CvInvoke.WaitKey(0); } static List<Image<Bgr, byte>> GenerateImagePyramid(Image<Bgr, byte> originalImage, int levels) { List<Image<Bgr, byte>> pyramid = new List<Image<Bgr, byte>>(); pyramid.Add(originalImage); for (int i = 1; i < levels; i++) { Image<Bgr, byte> downsampledImage = pyramid[i - 1].PyrDown(); pyramid.Add(downsampledImage); } return pyramid; } static List<List<Point>> DBSCANClustering(List<Point> points, double eps, int minPts) { var data = new double[points.Count, 2]; for (int i = 0; i < points.Count; i++) { data[i, 0] = points[i].X; data[i, 1] = points[i].Y; } var dbscan = new DBSCAN(); var clusters = dbscan.Train(data, eps, minPts); List<List<Point>> result = new List<List<Point>>(); for (int i = 0; i < clusters.Length; i++) { List<Point> clusterPoints = new List<Point>(); for (int j = 0; j < clusters[i].Length; j++) { if (clusters[i][j]) { clusterPoints.Add(points[j]); } } if (clusterPoints.Count > 0) { result.Add(clusterPoints); } } return result; } static void DrawBoundingBoxes(Image<Bgr, byte> image, List<List<Point>> clusters) { foreach (var cluster in clusters) { int minX = int.MaxValue; int minY = int.MaxValue; int maxX = int.MinValue; int maxY = int.MinValue; foreach (var point in cluster) { if (point.X < minX) minX = point.X; if (point.X > maxX) maxX = point.X; if (point.Y < minY) minY = point.Y; if (point.Y > maxY) maxY = point.Y; } Rectangle boundingBox = new Rectangle(minX, minY, maxX - minX, maxY - minY); image.Draw(boundingBox, new Bgr(Color.Red), 2); } } } } 中报错DBSCAN
最新发布
11-13
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值