简体   繁体   English

如何使用 OpenCvSharp4 v4.2 合并两个图像

[英]How to merge two images using OpenCvSharp4 v4.2

I need to create a method in C# that will receive an image (or path to it), blur it and then try to merge the blurred image with the original using OpenCvSharp4.我需要在 C# 中创建一个方法来接收图像(或它的路径),对其进行模糊处理,然后尝试使用 OpenCvSharp4 将模糊图像与原始图像合并。 So far, I can create the blur image just fine, but the merging part is giving me a hard time.到目前为止,我可以很好地创建模糊图像,但合并部分给我带来了困难。 I've had tried a few pieces of sample code found online to no avail.我已经尝试了一些在线找到的示例代码,但无济于事。 Any idea how to get the merging part ?知道如何获得合并部分吗?

-thanks, -谢谢,

  var mat = Cv2.ImRead(OriginalFileName, ImreadModes.Unchanged);
        Cv2.Resize(mat, mat, new Size(933, 934), 0d, 0d, InterpolationFlags.Linear);
        Cv2.CvtColor(mat, mat, ColorConversionCodes.BGR2RGB);
        Mat newImage = new Mat();
        Cv2.GaussianBlur(mat, newImage, new Size(67, 67), 0d, 0d, BorderTypes.Default);
        Cv2.CvtColor(newImage, newImage, ColorConversionCodes.BGR2RGB);
        Mat merged = Mat.Ones || Mat.Zeros // HELP NEEDED HERE
        Cv2.Merge(new Mat[] { mat, newImage }, merged);

Found a good hint and sample code here: How to merge two images in opencv?在这里找到了一个很好的提示和示例代码: 如何在 opencv 中合并两个图像?

Here's my final solution:这是我的最终解决方案:

 var mat = Cv2.ImRead(OriginalFileName, ImreadModes.Unchanged);
        Cv2.Resize(mat, mat, new Size(933, 934), 0d, 0d, InterpolationFlags.Linear);
        Cv2.CvtColor(mat, mat, ColorConversionCodes.BGR2RGB);
        Mat newImage = new Mat();
        Cv2.GaussianBlur(mat, newImage, new Size(67, 67), 0d, 0d, BorderTypes.Default);
        Cv2.CvtColor(newImage, newImage, ColorConversionCodes.BGR2RGB);

        //merging
        double alpha = 0; double beta; 
        Mat src1, src2, merge;
        merge = new Mat();
        src1 = mat;
        src2 = newImage;
        beta = (1.0 - alpha);
        Cv2.AddWeighted(src1, alpha, src2, beta, 0.0, merge);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 OpenCvSharp4 查找可用网络摄像头的索引? - How to find the index of available webcams using OpenCvSharp4? 在没有Static API的应用程序启动时配置AutoMapper v4.2 - Configuring AutoMapper v4.2 on application start without the Static API OpenCVsharp4以最大分辨率保存图像 - OpenCVsharp4 save Image at max resolution Bot Framework v4.2 - 从OnTurnError异常中恢复 - Bot Framework v4.2 - Gacefully Recover From OnTurnError Exception 将 OpenCVSharp4 矩形转换为 IronOCR CropRectangle(System.Drawing.Rectangle) - Converting OpenCVSharp4 Rectangle to IronOCR CropRectangle(System.Drawing.Rectangle) 如何将两个图像合而为一? - How to merge two images in one? 如何使用opencvsharp在PictureBox中显示实时视频? - How to display live video in picturebox using opencvsharp? .NET Core 2.0加密样本无法正常工作 - 错误Cng v4.3使用的算法v4.3高于引用的算法v4.2 - .NET Core 2.0 Crypto sample not working - Error Cng v4.3 uses Algorithms v4.3 higher than referenced Algorithms v4.2 如何在第三张图像中合并两个不同的图像? - How to Merge Two Differnt Images in Third Image? 如何在Windows Phone 8中合并两个图像 - How to merge two images in windows phone 8
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM