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下载

相关推荐
TalkU浩克3 分钟前
C++中使用Essentia实现STFT/ISTFT
开发语言·c++·音频·istft·stft·essentia
awonw16 分钟前
[python][flask]flask静态资源
开发语言·python·flask
Chef_Chen23 分钟前
从0开始学习R语言--Day57--SCAD模型
开发语言·学习·r语言
医工交叉实验工坊28 分钟前
R 语言绘制六种精美热图:转录组数据可视化实践(基于 pheatmap 包)
开发语言·信息可视化·r语言
小关会打代码32 分钟前
Python编程进阶知识之第五课处理数据(matplotlib)
开发语言·python·机器学习·matplotlib·绘图
小比卡丘34 分钟前
【C++进阶】第7课—红黑树
java·开发语言·c++
超浪的晨1 小时前
Java 单元测试详解:从入门到实战,彻底掌握 JUnit 5 + Mockito + Spring Boot 测试技巧
java·开发语言·后端·学习·单元测试·个人开发
不断努力的根号七1 小时前
qt框架,使用webEngine如何调试前端
开发语言·前端·qt
赵英英俊1 小时前
Python day24
开发语言·python
Harbor Lau1 小时前
多线程插入保证事务的一致性,亲测可用方式一实测
java·开发语言