C# OpenCvSharp DNN Image Retouching

这篇具有很好参考价值的文章主要介绍了C# OpenCvSharp DNN Image Retouching。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

目录

介绍

模型

项目

效果

代码

下载


C# OpenCvSharp DNN Image Retouching

介绍

github地址:https://github.com/hejingwenhejingwen/CSRNet

(ECCV 2020) Conditional Sequential Modulation for Efficient Global Image Retouching

C# OpenCvSharp DNN Image Retouching,C#人工智能实践,dnn,人工智能,神经网络,opencv,计算机视觉,机器学习,深度学习

模型

Model Properties
-------------------------
---------------------------------------------------------------

Inputs
-------------------------
name:input
tensor:Float[1, 3, 360, 640]
---------------------------------------------------------------

Outputs
-------------------------
name:output
tensor:Float[1, 3, 360, 640]
---------------------------------------------------------------

项目

C# OpenCvSharp DNN Image Retouching,C#人工智能实践,dnn,人工智能,神经网络,opencv,计算机视觉,机器学习,深度学习

效果

C# OpenCvSharp DNN Image Retouching,C#人工智能实践,dnn,人工智能,神经网络,opencv,计算机视觉,机器学习,深度学习

C# OpenCvSharp DNN Image Retouching,C#人工智能实践,dnn,人工智能,神经网络,opencv,计算机视觉,机器学习,深度学习

代码

using OpenCvSharp;
using OpenCvSharp.Dnn;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Numerics;
using System.Reflection;
using System.Windows.Forms;

namespace OpenCvSharp_DNN_Demo
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }

        string fileFilter = "*.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png";
        string image_path = "";

        DateTime dt1 = DateTime.Now;
        DateTime dt2 = DateTime.Now;

        string modelpath;

        int inpHeight;
        int inpWidth;

        Net opencv_net;
        Mat BN_image;

        Mat image;
        Mat result_image;

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = fileFilter;
            if (ofd.ShowDialog() != DialogResult.OK) return;

            pictureBox1.Image = null;
            pictureBox2.Image = null;
            textBox1.Text = "";

            image_path = ofd.FileName;
            pictureBox1.Image = new Bitmap(image_path);
            image = new Mat(image_path);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            modelpath = "model/csrnet_360x640.onnx";

            inpHeight = 360;
            inpWidth = 640;

            opencv_net = CvDnn.ReadNetFromOnnx(modelpath);

            image_path = "test_img/0014.jpg";
            pictureBox1.Image = new Bitmap(image_path);

        }

        private unsafe void button2_Click(object sender, EventArgs e)
        {
            if (image_path == "")
            {
                return;
            }
            textBox1.Text = "检测中,请稍等……";
            pictureBox2.Image = null;
            Application.DoEvents();

            image = new Mat(image_path);

            int srch = image.Rows;
            int srcw = image.Cols;


            BN_image = CvDnn.BlobFromImage(image, 1 / 255.0, new OpenCvSharp.Size(inpWidth, inpHeight), new Scalar(0, 0, 0), true, false);

            //配置图片输入数据
            opencv_net.SetInput(BN_image);

            //模型推理,读取推理结果
            Mat[] outs = new Mat[1] { new Mat() };
            string[] outBlobNames = opencv_net.GetUnconnectedOutLayersNames().ToArray();

            dt1 = DateTime.Now;

            opencv_net.Forward(outs, outBlobNames);

            dt2 = DateTime.Now;

            float* pdata = (float*)outs[0].Data;
            int out_h = outs[0].Size(2);
            int out_w = outs[0].Size(3);
            int channel_step = out_h * out_w;
            float[] data = new float[channel_step * 3];
            for (int i = 0; i < data.Length; i++)
            {
                data[i] = pdata[i] * 255;

                if (data[i] < 0)
                {
                    data[i] = 0;
                }
                else if (data[i] > 255)
                {
                    data[i] = 255;
                }
            }

            float[] temp_r = new float[out_h * out_w];
            float[] temp_g = new float[out_h * out_w];
            float[] temp_b = new float[out_h * out_w];

            Array.Copy(data, temp_r, out_h * out_w);
            Array.Copy(data, out_h * out_w, temp_g, 0, out_h * out_w);
            Array.Copy(data, out_h * out_w * 2, temp_b, 0, out_h * out_w);

            Mat rmat = new Mat(out_h, out_w, MatType.CV_32F, temp_r);
            Mat gmat = new Mat(out_h, out_w, MatType.CV_32F, temp_g);
            Mat bmat = new Mat(out_h, out_w, MatType.CV_32F, temp_b);

            result_image = new Mat();
            Cv2.Merge(new Mat[] { bmat, gmat, rmat }, result_image);

            Cv2.Resize(result_image, result_image, new OpenCvSharp.Size(srcw, srch));

            pictureBox2.Image = new Bitmap(result_image.ToMemoryStream());
            textBox1.Text = "推理耗时:" + (dt2 - dt1).TotalMilliseconds + "ms";
        }

        private void pictureBox2_DoubleClick(object sender, EventArgs e)
        {
            Common.ShowNormalImg(pictureBox2.Image);
        }

        private void pictureBox1_DoubleClick(object sender, EventArgs e)
        {
            Common.ShowNormalImg(pictureBox1.Image);
        }
    }
}
 

using OpenCvSharp;
using OpenCvSharp.Dnn;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Numerics;
using System.Reflection;
using System.Windows.Forms;

namespace OpenCvSharp_DNN_Demo
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }

        string fileFilter = "*.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png";
        string image_path = "";

        DateTime dt1 = DateTime.Now;
        DateTime dt2 = DateTime.Now;

        string modelpath;

        int inpHeight;
        int inpWidth;

        Net opencv_net;
        Mat BN_image;

        Mat image;
        Mat result_image;

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = fileFilter;
            if (ofd.ShowDialog() != DialogResult.OK) return;

            pictureBox1.Image = null;
            pictureBox2.Image = null;
            textBox1.Text = "";

            image_path = ofd.FileName;
            pictureBox1.Image = new Bitmap(image_path);
            image = new Mat(image_path);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            modelpath = "model/csrnet_360x640.onnx";

            inpHeight = 360;
            inpWidth = 640;

            opencv_net = CvDnn.ReadNetFromOnnx(modelpath);

            image_path = "test_img/0014.jpg";
            pictureBox1.Image = new Bitmap(image_path);

        }

        private unsafe void button2_Click(object sender, EventArgs e)
        {
            if (image_path == "")
            {
                return;
            }
            textBox1.Text = "检测中,请稍等……";
            pictureBox2.Image = null;
            Application.DoEvents();

            image = new Mat(image_path);

            int srch = image.Rows;
            int srcw = image.Cols;


            BN_image = CvDnn.BlobFromImage(image, 1 / 255.0, new OpenCvSharp.Size(inpWidth, inpHeight), new Scalar(0, 0, 0), true, false);

            //配置图片输入数据
            opencv_net.SetInput(BN_image);

            //模型推理,读取推理结果
            Mat[] outs = new Mat[1] { new Mat() };
            string[] outBlobNames = opencv_net.GetUnconnectedOutLayersNames().ToArray();

            dt1 = DateTime.Now;

            opencv_net.Forward(outs, outBlobNames);

            dt2 = DateTime.Now;

            float* pdata = (float*)outs[0].Data;
            int out_h = outs[0].Size(2);
            int out_w = outs[0].Size(3);
            int channel_step = out_h * out_w;
            float[] data = new float[channel_step * 3];
            for (int i = 0; i < data.Length; i++)
            {
                data[i] = pdata[i] * 255;

                if (data[i] < 0)
                {
                    data[i] = 0;
                }
                else if (data[i] > 255)
                {
                    data[i] = 255;
                }
            }

            float[] temp_r = new float[out_h * out_w];
            float[] temp_g = new float[out_h * out_w];
            float[] temp_b = new float[out_h * out_w];

            Array.Copy(data, temp_r, out_h * out_w);
            Array.Copy(data, out_h * out_w, temp_g, 0, out_h * out_w);
            Array.Copy(data, out_h * out_w * 2, temp_b, 0, out_h * out_w);

            Mat rmat = new Mat(out_h, out_w, MatType.CV_32F, temp_r);
            Mat gmat = new Mat(out_h, out_w, MatType.CV_32F, temp_g);
            Mat bmat = new Mat(out_h, out_w, MatType.CV_32F, temp_b);

            result_image = new Mat();
            Cv2.Merge(new Mat[] { bmat, gmat, rmat }, result_image);

            Cv2.Resize(result_image, result_image, new OpenCvSharp.Size(srcw, srch));

            pictureBox2.Image = new Bitmap(result_image.ToMemoryStream());
            textBox1.Text = "推理耗时:" + (dt2 - dt1).TotalMilliseconds + "ms";
        }

        private void pictureBox2_DoubleClick(object sender, EventArgs e)
        {
            Common.ShowNormalImg(pictureBox2.Image);
        }

        private void pictureBox1_DoubleClick(object sender, EventArgs e)
        {
            Common.ShowNormalImg(pictureBox1.Image);
        }
    }
}

下载

源码下载文章来源地址https://www.toymoban.com/news/detail-832261.html

到了这里,关于C# OpenCvSharp DNN Image Retouching的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • C# OpenCvSharp DNN 二维码增强 超分辨率

    目录 效果 项目 代码 下载  using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using OpenCvSharp; using OpenCvSharp.Dnn; using OpenCvSharp.Extensions; namespace OpenCvSharp_DNN_二维码增强 {     public partial cl

    2024年02月12日
    浏览(29)
  • C# OpenCvSharp DNN FreeYOLO 人脸检测&人脸图像质量评估

    目录 效果 模型信息 yolo_free_huge_widerface_192x320.onnx face-quality-assessment.onnx 项目 代码 frmMain.cs FreeYoloFace FaceQualityAssessment.cs 下载 C# OpenCvSharp DNN FreeYOLO 人脸检测人脸图像质量评估 Inputs ------------------------- name:input tensor:Float[1, 3, 192, 320] ------------------------------------------------------

    2024年01月22日
    浏览(35)
  • 人工智能:CNN(卷积神经网络)、RNN(循环神经网络)、DNN(深度神经网络)的知识梳理

    卷积神经网络(CNN),也被称为ConvNets或Convolutional Neural Networks,是一种深度学习神经网络架构,主要用于处理和分析具有网格状结构的数据,特别是图像和视频数据。CNN 在计算机视觉任务中表现出色,因为它们能够有效地捕获和识别图像中的特征,具有平移不变性(transla

    2024年02月05日
    浏览(48)
  • 人工智能CSDN版AI和百度AI代码转化测试,C#、Java代码转Python

    工作中,需要完成以下的工作场景: 【场景】单据转换不支持多选基础资料下推; 【案例】通过单据转换插件,实现应收单单据头的多选基础资料下推到付款申请单的单据头的多选基础资料 原文链接:https://vip.kingdee.com/article/324304152484608000?productLineId=1 需要将原代码转换为

    2024年02月03日
    浏览(36)
  • C#,人工智能,机器人,路径规划,A*(AStar Algorithm)算法、源代码及计算数据可视化

    Peter Hart  Nils Nilsson  Bertram Raphael  参考: C#,人工智能(AI)机器人路径规划(Path Planning)的ARA*(Anytime Replanning A* Algorithm)算法与源程序 https://blog.csdn.net/beijinghorn/article/details/125464754 A*算法最初由斯坦福研究院(Stanford Institute)的  Peter Hart,Nils Nilsson,Bertram Raphael  发表于

    2024年01月18日
    浏览(49)
  • C# OpenCvSharp 图像校正

    目录 效果 代码 下载 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using OpenCvSharp; using OpenCvSharp.Extensions; namespace OpenCvSharp_图像校正 {     public partial class Form1 : Form     {         pu

    2024年02月15日
    浏览(28)
  • C# OpenCvSharp 通道分离

    目录 效果 项目 代码 下载  using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using OpenCvSharp; using OpenCvSharp.Extensions; namespace OpenCvSharp_通道分离 {     public partial class Form1 : Form     {    

    2024年02月09日
    浏览(34)
  • C# OpenCvSharp 轮廓检测

    目录 效果 代码 下载  using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using OpenCvSharp; using OpenCvSharp.Extensions; namespace OpenCvSharp_轮廓检测 {     public partial class Form1 : Form     {        

    2024年04月15日
    浏览(35)
  • c# OpenCvSharp安装(一)

    一  通过NuGet 安装四个拓展包 OpenCvSharp4、OpenCvSharp4.Extensions、OpenCvSharp4.runtime.win、OpenCvSharp4.WpfExtensions C#使用OpenCV的一些代码 需要加头文件 using OpenCvSharp;   //为了使用opencv using Point = OpenCvSharp.Point;   //为了确定我们使用的point是opencv的而不是draw的    c# OpenCV相关文章目录

    2024年04月16日
    浏览(23)
  • C# OpenCvSharp 图片批量改名

    目录 效果 项目 代码 下载 C# OpenCvSharp 图片批量改名 using NLog; using OpenCvSharp; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Windows.Forms; namespace OpenCvSharp_Demo {     public partial class Form1 : Form     {         public Form1()         {             InitializeCo

    2024年03月12日
    浏览(33)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包