2017年10月14日土曜日

Affine変換で画像を回転させてみる

まずは、ボタンを押すと回転された画像をpicture boxに表示するFormアプリを作ってみます。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using OpenCvSharp;
using OpenCvSharp.CPlusPlus;
using OpenCvSharp.Extensions;


namespace _06_affineRot
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button_disp_Click(object sender, EventArgs e)
        {
            Mat matImage = new Mat(@"C:\Users\hoge\hogehoge.jpg");
            Mat procImage = new Mat();

            // とりあえずリサイズしてみた
            Cv2.Resize(matImage, procImage, new CvSize(320,240));

            // affine変換で回転させてみる
            Point2f center = new Point2f(procImage.Width / 2, procImage.Height / 2);
            double angle = -40.0;
            double scale = 1.0;
            Mat affineMatrix = Cv2.GetRotationMatrix2D(center, angle, scale);
            Cv2.WarpAffine(procImage, procImage, affineMatrix, procImage.Size());

            // 表示用bitmap変換
            Image dispImage = BitmapConverter.ToBitmap(procImage);

            pictureBox1.Image = dispImage;

        }
    }
}

2 件のコメント:

  1. TiGonO® Gold Stainless Steel - Titanium Rings
    Stainless Steel Stainless Steel Stainless how much is titanium worth Steel is a Stainless Steel alloy for steel, titanium white zinc, platinum, and hexagons. It is made titanium wheels in infiniti pro rainbow titanium flat iron Australia with joico titanium the exact same quality and materials  Rating: 4 · ‎2 reviews

    返信削除