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

45 篇文章 19 订阅

目录

效果1

效果2

项目

代码

其他

下载


效果1

效果2

项目

代码

/// <summary>
/// Remaps an image to polar space.
/// </summary>
/// <param name="src">Source image</param>
/// <param name="dst">Destination image</param>
/// <param name="center">The transformation center</param>
/// <param name="maxRadius">Inverse magnitude scale parameter</param>
/// <param name="flags">A combination of interpolation methods, see cv::InterpolationFlags</param>
public static void LinearPolar(InputArray src, OutputArray dst,Point2f center, double maxRadius, InterpolationFlags flags)


/// <summary>
/// Remaps an image to log-polar space.
/// </summary>
/// <param name="src">Source image</param>
/// <param name="dst">Destination image</param>
/// <param name="center">The transformation center; where the output precision is maximal</param>
/// <param name="m">Magnitude scale parameter.</param>
/// <param name="flags">A combination of interpolation methods, see cv::InterpolationFlags</param>
public static void LogPolar(InputArray src, OutputArray dst,Point2f center, double m, InterpolationFlags flags)

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);
        }

    }
}

其他

结合印章检测和OCR识别,可实现印章文字识别。

印章检测 C# PaddleDetection yolo 印章检测

OCR识别 C# OpenVINO 通用OCR识别 文字识别 中文识别 服务

下载

Demo下载

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
OpenCVSharpOpenCVC#封装库,用于图像处理和计算机视觉应用程序的开发。如果要使用OpenCVSharp进行点云坐标的直通滤波处理,可以按照以下步骤进行: 1. 将点云数据转换为OpenCVSharp的Mat对象,每个点的x、y、z坐标分别存储在Mat的不同通道中。 2. 使用OpenCVSharp的inRange函数对z坐标进行阈值过滤,将不在指定范围内的点的z坐标值设为0。 3. 使用OpenCVSharp的merge函数将过滤后的x、y、z坐标合并成一个Mat对象。 4. 将合并后的Mat对象转换回点云数据格式,即可得到直通滤波后的点云数据。 以下是示例代码: ```csharp using OpenCvSharp; using System.Collections.Generic; // 假设点云数据已经存储在List<Point3f>对象中 List<Point3f> pointCloud = ...; // 将点云数据转换为OpenCVSharp的Mat对象 Mat pointsMat = new Mat(pointCloud.Count, 1, MatType.CV_32FC3); for (int i = 0; i < pointCloud.Count; i++) { Point3f point = pointCloud[i]; pointsMat.Set(i, 0, new Vec3f(point.X, point.Y, point.Z)); } // 指定z坐标范围,进行阈值过滤 Scalar lowerBound = new Scalar(-100f); Scalar upperBound = new Scalar(100f); Mat zMask = new Mat(); Cv2.InRange(pointsMat.Split()[2], lowerBound, upperBound, zMask); pointsMat.SetTo(new Scalar(0), zMask); // 合并x、y、z坐标,得到直通滤波后的点云数据 Mat filteredPointCloud = new Mat(); Cv2.Merge(pointsMat.Split(), filteredPointCloud); // 将Mat对象转换回点云数据格式 List<Point3f> filteredPointCloudList = new List<Point3f>(); for (int i = 0; i < filteredPointCloud.Rows; i++) { Vec3f point = filteredPointCloud.At<Vec3f>(i, 0); filteredPointCloudList.Add(new Point3f(point.Item0, point.Item1, point.Item2)); } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

天天代码码天天

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值