Skip to content

Instantly share code, notes, and snippets.

@jyoshida-sci
Last active July 27, 2016 07:22
Show Gist options
  • Save jyoshida-sci/9fb54a228c64ab88eb05 to your computer and use it in GitHub Desktop.
Save jyoshida-sci/9fb54a228c64ab88eb05 to your computer and use it in GitHub Desktop.
OpenCVSharp_sample
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenCvSharp;
using OpenCvSharp.CPlusPlus;
namespace OpenCVSharp
{
class Program
{
static int Main(string[] args)
{
try
{
System.Console.WriteLine("Difference of Gaussian\n");
Mat src = Cv2.ImRead("image.png");
Mat blured = new Mat();
Cv2.Blur(src, blured, Cv.Size(13, 13));
Mat dog = new Mat();
Cv2.Subtract(src, blured, dog);
Mat bin = new Mat();
Cv2.Threshold(dog, bin, 50/255, 255, ThresholdType.Binary);
Cv2.ImShow("src", src);
Cv2.ImShow("blured", blured);
Cv2.ImShow("dog", dog);
Cv2.ImShow("bin", bin);
Cv2.WaitKey(0);
Mat mymatrix = Mat.Zeros(4, 5, MatType.CV_8UC1);
Mat mymatrix64 = Mat.Zeros(4, 5, MatType.CV_64FC1);
mymatrix.ConvertTo(mymatrix64, MatType.CV_64FC1);
//http://shimat.github.io/opencvsharp/html/9d89f778-a16f-3c09-e194-aabe1067f80d.htm
//http://shimat.github.io/opencvsharp/html/7bb05237-7ff6-0e19-bfeb-36ea352b3051.htm
mymatrix64 = mymatrix64.Reduce(OpenCvSharp.ReduceDimension.Column, OpenCvSharp.ReduceOperation.Sum, -1);
Console.WriteLine("{0} {1}", mymatrix.Cols, mymatrix.Rows);
Console.WriteLine("{0} {1}", mymatrix64.Cols, mymatrix64.Rows);
}
catch (Exception e)
{
string s = System.String.Format("Exception: {0}", e.ToString());
System.Console.WriteLine(s);
}
return 0;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment