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

相关推荐
月月吃喝2 分钟前
【PyQt5】嵌套多线程数据交互实现
开发语言·qt·交互
匿名4596 分钟前
Lombok注解使用无效的情况(未能获得后端数据)
java·开发语言
徐子童23 分钟前
JVM高频面试题---GC垃圾回收
java·开发语言·jvm·面试题·gc·垃圾回收算法
AutomanLV33 分钟前
c# datagridview添加list内容
程序人生·c#
Z_z在努力38 分钟前
【数据结构】队列(Queue)全面详解
java·开发语言·数据结构
qiu_zhongya2 小时前
iree 用C++来运行Qwen 2.5 0.5b
开发语言·c++·人工智能
汪宁宇2 小时前
giflib5.2.2 在Qt与VS C++中实现Gif缩放示例
开发语言·c++·qt
啊?啊?2 小时前
C/C++练手小项目之倒计时与下载进度条模拟
c语言·开发语言·c++
求一个demo2 小时前
Qt5.14.2配置MSVC2017
开发语言·qt
西阳未落2 小时前
C++基础(22)——模板的进阶
开发语言·c++