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

相关推荐
喵了meme6 小时前
C语言实战4
c语言·开发语言
码界奇点6 小时前
Python从0到100一站式学习路线图与实战指南
开发语言·python·学习·青少年编程·贴图
9ilk6 小时前
【C++】--- 特殊类设计
开发语言·c++·后端
꧁执笔小白꧂7 小时前
C#+VisionMaster 学习笔记(目录)-目录
c#·visionmaster
sali-tec7 小时前
C# 基于halcon的视觉工作流-章68 深度学习-对象检测
开发语言·算法·计算机视觉·重构·c#
生骨大头菜8 小时前
使用python实现相似图片搜索功能,并接入springcloud
开发语言·python·spring cloud·微服务
绝不收费—免费看不了了联系我8 小时前
Fastapi的单进程响应问题 和 解决方法
开发语言·后端·python·fastapi
消失的旧时光-19439 小时前
深入理解 Java 线程池(二):ThreadPoolExecutor 执行流程 + 运行状态 + ctl 原理全解析
java·开发语言
咖啡续命又一天9 小时前
Trae CN IDE 中 Python 开发的具体流程和配置总结
开发语言·ide·python·ai编程
4311媒体网9 小时前
帝国cms调用文章内容 二开基本操作
java·开发语言·php