using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenCvSharp;
using OpenCvSharp.CPlusPlus; // コレ
using System.Diagnostics;
namespace _03_matTest
{
class Program
{
static void Main(string[] args)
{
/*
CvMat mat1 = new CvMat(10, 10, MatrixType.U16C1);
CvMat mat2 = new CvMat(320, 480, MatrixType.U8C3, new CvScalar(0,0,255));
using (new CvWindow(mat2))
{
Debug.WriteLine(mat2.Width + " : " + mat2.Height);
Debug.WriteLine(mat2.ElemDepth + " : " + mat2.ElemType);
Cv.WaitKey();
}
*/
Mat matImage = new Mat(@"C:\Users\hogehoge\\Pictures\hogehoge.jpg");
Mat grayImage = new Mat();
Cv2.CvtColor(matImage, grayImage, ColorConversion.RgbToGray);
/*
var indexer = matImage.GetGenericIndexer<Vec3b>();
var px = indexer[5, 5];
Debug.WriteLine(px[0] + ":" + px[1] + ":" + px[2]);
px[0] = 0; // B
px[1] = 0; // G
px[2] = 255; // R
indexer[5, 5] = px;
// var type = matImage.Type;
using (new Window("photo", matImage)) // ウィンドウを作成して画像を表示
*/
CvSize size = new CvSize(matImage.Width / 8, matImage.Height / 8);
Mat dispImage = new Mat();
Cv2.Resize(matImage, dispImage, size);
using (new Window("resized image", dispImage))
{
Cv.WaitKey();
}
Mat copyImage = dispImage.Clone(new Rect(0, 0, matImage.Width / 8, matImage.Height / 8)); // 画像をコピー(というかcloneなのでポインタではなく深い)
Mat bwImage = copyImage.Clone();
Cv2.CvtColor(bwImage, bwImage, ColorConversion.RgbToGray);
KeyPoint[] keypoints;
// Cv2.FAST(bwImage, out keypoints, 50, true); // FAST : cornerを検出する 桜の場合はコーナーだらけ
// Cv2.FAST(bwImage, out keypoints, 50, true); // 建物 : まあまあ
// Cv2.FAST(bwImage, out keypoints, 20, true); // 建物 : やや増える
Cv2.FAST(bwImage, out keypoints, 100, true); // 建物 : 減る
foreach (KeyPoint kp in keypoints)
{
dispImage.Circle(kp.Pt, 3, Scalar.Red, -1, LineType.AntiAlias, 0);
}
using (new Window("copy image", dispImage))
{
Cv2.WaitKey();
}
/*
using (new Window("gray image", grayImage))
{
Debug.WriteLine(grayImage.Width + " : " + grayImage.Height); // 4896 : 3264
Debug.WriteLine(grayImage.Depth() + " : " + grayImage.Type()); // 0 : CV_8UC1
Cv.WaitKey();
}
*/
}
}
}
0 件のコメント:
コメントを投稿