C# OpenCvSharp 环形文字处理 直角坐标与极坐标转换

效果1

效果2

项目

代码

复制代码
using OpenCvSharp;
using System;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace OpenCvSharp_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;

        Mat image;
        Mat result_image;

        StringBuilder sb = new StringBuilder();

        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;

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

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            image_path = "test_img/2.jpg";
            image = new Mat(image_path);
            pictureBox1.Image = new Bitmap(image_path);
            result_image = new Mat();

            float h, w, cx, cy;
            h = (float)image.Height;
            w = (float)image.Width;

            //以图像中心点作为变换中心
            cx = w / 2;
            cy = h / 2;
            double maxR = Math.Max(cx, cy); // 最大变换半径

            Cv2.LinearPolar(image, result_image, new Point2f(cx, cy), maxR, InterpolationFlags.Linear);

            Cv2.Rotate(result_image, result_image, RotateFlags.Rotate90Counterclockwise);

            pictureBox2.Image = new Bitmap(result_image.ToMemoryStream());

        }

        private void button3_Click(object sender, EventArgs e)
        {
            image_path = "test_img/1.jpg";
            image = new Mat(image_path);
            pictureBox1.Image = new Bitmap(image_path);
            result_image = new Mat();

            float h, w, cx, cy;
            h = (float)image.Height;
            w = (float)image.Width;

            //以图像中心点作为变换中心
            cx = w / 2;
            cy = h / 2;

            Cv2.LogPolar(image, result_image, new Point2f(cx, cy), 80, InterpolationFlags.Linear | InterpolationFlags.WarpFillOutliers);

            Cv2.Rotate(result_image, result_image, RotateFlags.Rotate90Counterclockwise);

            pictureBox2.Image = new Bitmap(result_image.ToMemoryStream());

        }

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

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

    }
}

下载

Demo下载

相关推荐
Neverfadeaway几秒前
【C语言】深入理解函数指针数组应用(4)
c语言·开发语言·算法·回调函数·转移表·c语言实现计算器
武子康2 分钟前
Java-152 深入浅出 MongoDB 索引详解 从 MongoDB B-树 到 MySQL B+树 索引机制、数据结构与应用场景的全面对比分析
java·开发语言·数据库·sql·mongodb·性能优化·nosql
杰克尼6 分钟前
JavaWeb_p165部门管理
java·开发语言·前端
一成码农27 分钟前
JavaSE面向对象(下)
java·开发语言
偶尔的鼠标人1 小时前
Avalonia DataGrid 控件的LostFocus事件会多次触发
开发语言·c#
晚风残1 小时前
【C++ Primer】第十二章:动态内存管理
开发语言·c++·c++ primer
ytttr8731 小时前
C# 仿QQ聊天功能实现 (SQL Server数据库)
数据库·oracle·c#
_extraordinary_1 小时前
Java Spring日志
java·开发语言·spring
初圣魔门首席弟子1 小时前
【C++ 学习】单词统计器:从 “代码乱炖” 到 “清晰可品” 的复习笔记
开发语言·c++
lsx2024062 小时前
SQL UPDATE 语句详解
开发语言