|
|
|
@ -18,6 +18,11 @@ namespace OpenCV |
|
|
|
|
IplImage affine; |
|
|
|
|
IplImage perspective; |
|
|
|
|
IplImage draw; |
|
|
|
|
IplImage hsv; |
|
|
|
|
IplImage hsvRed; |
|
|
|
|
IplImage morp; |
|
|
|
|
|
|
|
|
|
IplConvKernel convKernel; |
|
|
|
|
|
|
|
|
|
public IplImage GrayScale(IplImage src) |
|
|
|
|
{ |
|
|
|
@ -33,10 +38,10 @@ namespace OpenCV |
|
|
|
|
return inversion; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public IplImage Binary(IplImage src) |
|
|
|
|
public IplImage Binary(IplImage src, int threshold) |
|
|
|
|
{ |
|
|
|
|
bin = GrayScale(src); |
|
|
|
|
Cv.Threshold(bin, bin, 150, 255, ThresholdType.Binary); |
|
|
|
|
Cv.Threshold(bin, bin, threshold, 255, ThresholdType.Binary); |
|
|
|
|
return bin; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -133,11 +138,68 @@ namespace OpenCV |
|
|
|
|
Cv.DrawCircle(draw, new CvPoint(200, 200), 50, CvColor.Red, -1); |
|
|
|
|
Cv.DrawRect(draw, new CvPoint(300, 150), new CvPoint(500, 300), CvColor.Green, 5); |
|
|
|
|
Cv.DrawEllipse(draw, new CvPoint(150, 400), new CvSize(100, 50), 0, 90, 360, CvColor.Green, -1); |
|
|
|
|
Cv.PutText(draw, "Open CV 오?", new CvPoint(400, 400), new CvFont(FontFace.HersheyComplex, 1, 1), CvColor.White); |
|
|
|
|
Cv.PutText(draw, "Open CV", new CvPoint(400, 400), new CvFont(FontFace.HersheyComplex, 1, 1), CvColor.White); |
|
|
|
|
|
|
|
|
|
return draw; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public IplImage HSV(IplImage src) |
|
|
|
|
{ |
|
|
|
|
hsv = new IplImage(src.Size, BitDepth.U8, 3); |
|
|
|
|
|
|
|
|
|
IplImage h = new IplImage(src.Size, BitDepth.U8, 1); |
|
|
|
|
IplImage s = new IplImage(src.Size, BitDepth.U8, 1); |
|
|
|
|
IplImage v = new IplImage(src.Size, BitDepth.U8, 1); |
|
|
|
|
|
|
|
|
|
Cv.CvtColor(src, hsv, ColorConversion.BgrToHsv); |
|
|
|
|
Cv.Split(hsv, h, s, v, null); |
|
|
|
|
|
|
|
|
|
hsv.SetZero(); |
|
|
|
|
|
|
|
|
|
// Hue |
|
|
|
|
//Cv.InRangeS(h, 20, 30, h); // Yellow |
|
|
|
|
//Cv.Copy(src, hsv, h); |
|
|
|
|
|
|
|
|
|
// Hue - Red |
|
|
|
|
IplImage lowerRed = new IplImage(src.Size, BitDepth.U8, 1); |
|
|
|
|
IplImage upperRed = new IplImage(src.Size, BitDepth.U8, 1); |
|
|
|
|
IplImage red = new IplImage(src.Size, BitDepth.U8, 1); |
|
|
|
|
Cv.InRangeS(h, 0, 10, lowerRed); |
|
|
|
|
Cv.InRangeS(h, 170, 179, upperRed); |
|
|
|
|
Cv.AddWeighted(lowerRed, 1.0, upperRed, 1.0, 0.0, red); |
|
|
|
|
Cv.Copy(src, hsv, red); |
|
|
|
|
|
|
|
|
|
// Saturation |
|
|
|
|
//Cv.InRangeS(s, 20, 30, s); |
|
|
|
|
//Cv.Copy(src, hsv, s); |
|
|
|
|
|
|
|
|
|
// Value |
|
|
|
|
//Cv.InRangeS(v, 20, 30, v); |
|
|
|
|
//Cv.Copy(src, hsv, v); |
|
|
|
|
|
|
|
|
|
return hsv; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public IplImage HSVRed(IplImage src) |
|
|
|
|
{ |
|
|
|
|
hsvRed = new IplImage(src.Size, BitDepth.U8, 3); |
|
|
|
|
|
|
|
|
|
IplImage lowerRed = new IplImage(src.Size, BitDepth.U8, 1); |
|
|
|
|
IplImage upperRed = new IplImage(src.Size, BitDepth.U8, 1); |
|
|
|
|
IplImage red = new IplImage(src.Size, BitDepth.U8, 1); |
|
|
|
|
|
|
|
|
|
Cv.CvtColor(src, hsvRed, ColorConversion.BgrToHsv); |
|
|
|
|
|
|
|
|
|
Cv.InRangeS(hsvRed, new CvScalar(0, 100, 100), new CvScalar(10, 255, 255), lowerRed); |
|
|
|
|
Cv.InRangeS(hsvRed, new CvScalar(170, 100, 100), new CvScalar(179, 255, 255), upperRed); |
|
|
|
|
Cv.AddWeighted(lowerRed, 1.0, upperRed, 1.0, 0.0, red); |
|
|
|
|
|
|
|
|
|
hsvRed.SetZero(); |
|
|
|
|
Cv.Copy(src, hsvRed, red); |
|
|
|
|
|
|
|
|
|
return hsvRed; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void Release(params IplImage[] images) |
|
|
|
|
{ |
|
|
|
|
for (int i = 0; i < images.Length; i++) |
|
|
|
@ -147,6 +209,56 @@ namespace OpenCV |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public IplImage DilateImage(IplImage src, int threshold, int iteration) |
|
|
|
|
{ |
|
|
|
|
morp = new IplImage(src.Size, BitDepth.U8, 1); |
|
|
|
|
bin = Binary(src, threshold); |
|
|
|
|
Cv.Dilate(bin, morp, convKernel, iteration); |
|
|
|
|
|
|
|
|
|
return morp; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public IplImage ErodeImage(IplImage src, int threshold, int iteration) |
|
|
|
|
{ |
|
|
|
|
morp = new IplImage(src.Size, BitDepth.U8, 1); |
|
|
|
|
bin = Binary(src, threshold); |
|
|
|
|
Cv.Erode(bin, morp, convKernel, iteration); |
|
|
|
|
|
|
|
|
|
return morp; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public IplImage DEImage(IplImage src, int threshold, int iteration) |
|
|
|
|
{ |
|
|
|
|
morp = new IplImage(src.Size, BitDepth.U8, 1); |
|
|
|
|
bin = Binary(src, threshold); |
|
|
|
|
Cv.Dilate(bin, morp, convKernel, iteration); |
|
|
|
|
Cv.Erode(morp, morp, convKernel, iteration); |
|
|
|
|
|
|
|
|
|
return morp; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public IplImage EDImage(IplImage src, int threshold, int iteration) |
|
|
|
|
{ |
|
|
|
|
morp = new IplImage(src.Size, BitDepth.U8, 1); |
|
|
|
|
bin = Binary(src, threshold); |
|
|
|
|
Cv.Erode(bin, morp, convKernel, iteration); |
|
|
|
|
Cv.Dilate(morp, morp, convKernel, iteration); |
|
|
|
|
|
|
|
|
|
return morp; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public IplImage MorphologyImage(IplImage src, MorphologyOperation option, int iteration) |
|
|
|
|
{ |
|
|
|
|
if (convKernel == null) |
|
|
|
|
return null; |
|
|
|
|
|
|
|
|
|
morp = new IplImage(src.Size, BitDepth.U8, 1); |
|
|
|
|
bin = Binary(src, 50); |
|
|
|
|
|
|
|
|
|
Cv.MorphologyEx(bin, morp, bin, convKernel, option, iteration); |
|
|
|
|
return morp; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void Dispose() |
|
|
|
|
{ |
|
|
|
|
Release( |
|
|
|
@ -162,8 +274,17 @@ namespace OpenCV |
|
|
|
|
rotate, |
|
|
|
|
affine, |
|
|
|
|
perspective, |
|
|
|
|
draw |
|
|
|
|
draw, |
|
|
|
|
hsv, |
|
|
|
|
hsvRed, |
|
|
|
|
morp |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public IplConvKernel ConvKernel |
|
|
|
|
{ |
|
|
|
|
get { return this.convKernel; } |
|
|
|
|
set { this.convKernel = value; } |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|