You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
using OpenCvSharp;
|
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
namespace OpenCV
|
|
|
|
|
{
|
|
|
|
|
class OpenCVClass : IDisposable
|
|
|
|
|
{
|
|
|
|
|
IplImage gray;
|
|
|
|
|
IplImage inversion;
|
|
|
|
|
IplImage bin;
|
|
|
|
|
IplImage blur;
|
|
|
|
|
|
|
|
|
|
public IplImage GrayScale(IplImage src)
|
|
|
|
|
{
|
|
|
|
|
gray = new IplImage(src.Size, BitDepth.U8, 1);
|
|
|
|
|
Cv.CvtColor(src, gray, ColorConversion.BgrToGray);
|
|
|
|
|
return gray;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IplImage InversionImage(IplImage src)
|
|
|
|
|
{
|
|
|
|
|
inversion = new IplImage(src.Size, BitDepth.U8, 3);
|
|
|
|
|
Cv.Not(src, inversion);
|
|
|
|
|
return inversion;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IplImage Binary(IplImage src)
|
|
|
|
|
{
|
|
|
|
|
bin = GrayScale(src);
|
|
|
|
|
Cv.Threshold(bin, bin, 150, 255, ThresholdType.Binary);
|
|
|
|
|
return bin;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IplImage Blur(IplImage src)
|
|
|
|
|
{
|
|
|
|
|
blur = new IplImage(src.Size, BitDepth.U8, 3);
|
|
|
|
|
Cv.Smooth(src, blur, SmoothType.Blur, 9); // param1은 홀수, 중간 픽셀 선택을 위함
|
|
|
|
|
return blur;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
if (gray != null)
|
|
|
|
|
Cv.ReleaseImage(gray);
|
|
|
|
|
if (inversion != null)
|
|
|
|
|
Cv.ReleaseImage(inversion);
|
|
|
|
|
if (bin != null)
|
|
|
|
|
Cv.ReleaseImage(bin);
|
|
|
|
|
if (blur != null)
|
|
|
|
|
Cv.ReleaseImage(blur);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|