目录
效果
项目
代码
下载
效果
项目
代码
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 class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private string fileFilter = "*.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png";
Bitmap bmp;
String imgPath = "";
const string prototxt_path = "sr.prototxt";
const string caffe_model_path = "sr.caffemodel";
private void button2_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = fileFilter;
if (ofd.ShowDialog() != DialogResult.OK) return;
imgPath = ofd.FileName;
bmp = new Bitmap(imgPath);
pictureBox1.Image = bmp;
}
private void button1_Click(object sender, EventArgs e)
{
if (pictureBox1.Image == null)
{
return;
}
var src = Cv2.ImRead(imgPath, ImreadModes.Grayscale);
var srnet = CvDnn.ReadNetFromCaffe(prototxt_path, caffe_model_path);
Mat blob = CvDnn.BlobFromImage(src, 1.0 / 255, src.Size(), new Scalar(0.0f), false, false);
srnet.SetInput(blob);
var prob = srnet.Forward();
var dst = new Mat(prob.Size(2), prob.Size(3), MatType.CV_8UC1);
for (int row = 0; row < prob.Size(2); row++)
{
for (int col = 0; col < prob.Size(3); col++)
{
float pixel = prob.At<float>(0, 0, row, col) * 255;
dst.Set<byte>(row, col, (byte)(Math.Max(0, Math.Min(pixel, 255f))));
}
}
pictureBox2.Image = BitmapConverter.ToBitmap(dst);
// Cv2.ImShow("src", src);
// Cv2.ImShow("dst", dst);
}
}
}文章来源:https://www.toymoban.com/news/detail-663302.html
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 class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private string fileFilter = "*.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png";
Bitmap bmp;
String imgPath = "";
const string prototxt_path = "sr.prototxt";
const string caffe_model_path = "sr.caffemodel";
private void button2_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = fileFilter;
if (ofd.ShowDialog() != DialogResult.OK) return;
imgPath = ofd.FileName;
bmp = new Bitmap(imgPath);
pictureBox1.Image = bmp;
}
private void button1_Click(object sender, EventArgs e)
{
if (pictureBox1.Image == null)
{
return;
}
var src = Cv2.ImRead(imgPath, ImreadModes.Grayscale);
var srnet = CvDnn.ReadNetFromCaffe(prototxt_path, caffe_model_path);
Mat blob = CvDnn.BlobFromImage(src, 1.0 / 255, src.Size(), new Scalar(0.0f), false, false);
srnet.SetInput(blob);
var prob = srnet.Forward();
var dst = new Mat(prob.Size(2), prob.Size(3), MatType.CV_8UC1);
for (int row = 0; row < prob.Size(2); row++)
{
for (int col = 0; col < prob.Size(3); col++)
{
float pixel = prob.At<float>(0, 0, row, col) * 255;
dst.Set<byte>(row, col, (byte)(Math.Max(0, Math.Min(pixel, 255f))));
}
}
pictureBox2.Image = BitmapConverter.ToBitmap(dst);
// Cv2.ImShow("src", src);
// Cv2.ImShow("dst", dst);
}
}
}
下载
Demo下载文章来源地址https://www.toymoban.com/news/detail-663302.html
到了这里,关于C# OpenCvSharp DNN 二维码增强 超分辨率的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!