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

相关推荐
软件黑马王子3 小时前
C#初级教程(4)——流程控制:从基础到实践
开发语言·c#
闲猫3 小时前
go orm GORM
开发语言·后端·golang
李白同学4 小时前
【C语言】结构体内存对齐问题
c语言·开发语言
黑子哥呢?5 小时前
安装Bash completion解决tab不能补全问题
开发语言·bash
青龙小码农5 小时前
yum报错:bash: /usr/bin/yum: /usr/bin/python: 坏的解释器:没有那个文件或目录
开发语言·python·bash·liunx
大数据追光猿5 小时前
Python应用算法之贪心算法理解和实践
大数据·开发语言·人工智能·python·深度学习·算法·贪心算法
彳卸风6 小时前
Unable to parse timestamp value: “20250220135445“, expected format is
开发语言
dorabighead7 小时前
JavaScript 高级程序设计 读书笔记(第三章)
开发语言·javascript·ecmascript
风与沙的较量丶7 小时前
Java中的局部变量和成员变量在内存中的位置
java·开发语言
水煮庄周鱼鱼7 小时前
C# 入门简介
开发语言·c#