• Getting Started
  • Api Documentation
  • Release Notes
Show / Hide Table of Contents
  • Installation
  • Photometric Stereo
  • Find Circle
  • Find Line
  • Image Synthesis

SaigeVision ImageProcess Quick Start - FindCircle

이 문서는 ImageProcess 기능 중 FindCircle 에 대해서 사용하는 방법에 대해 설명합니다

기능 소개

FindCircle 은 원하는 영역 내에서 원을 가지는 형상을 찾는 기술입니다. 위치정보, 반지름, 원형상의 정도에 대해서 알 수 있습니다.

API Detail

아래는 ‘FindCircle’ 을 설명하기 위한 샘플 코드 입니다.

List<Bitmap> _images = new List<Bitmap>();
string path = @"..\..\images";
_images.Add(new Bitmap(Path.Combine(path, "sample.png")));

ConvertImage convertImage = new ConvertImage();
convertImage.SetImage(_images[0]);
SaigeRectangle rectangle = new SaigeRectangle(int x, int y, int widhth, int height);
convertImage.SetArea(rectangle);

var convertOption = convertImage.GetOptions();
convertOption.ConvertType = ThresholdFlags.THRESH_BINARY;
convertOption.MaxThreshold = 255;
convertOption.Threshold = 50;
convertImage.SetOptions(convertOption);

convertImage.Inspection();
Bitmap binaryImage = convertImage.GetResultImage();

SaigeRectangle rectangle = new SaigeRectangle(int x, int y, int widhth, int height);

FindCircle findCircle = new FindCircle();
findCircle.SetImage(binaryImage);
findCircle.SetArea(rectangle);

var option = findCircle.GetOptions();
option.ScoreThreshold = 0.9;
option.BackgroundColorFlags = BackgroundColorFlags.BLACK;
findCircle.SetOptions(option);

findCircle.Inspection();

var result = findCircle.GetResult();

findCircle.Dispose();
convertImage.Dispose();

Inspection


FindCircle 함수를 사용하기 위해서는 이진화 이미지가 필요합니다. grayscale 이미지를 가지고 있을 경우 이진화 함수를 추가적으로 사용할 수 있습니다.

ConvertImage 를 이용하여 이진화를 진행하게 됩니다.

Option에서 이진화하는 방식에 대해서 선택을 하게 됩니다.

  • THRESH_BINARY: Threshold 값 이하는 0으로, 초과값으 255로 변환
  • THRESH_BINARY_INV: Threshold 값 이하는 255로, 초과값을 0로 변환
  • THRESH_TRUNC: Threshold 값 이하는 밝기 값 그대로, 초과값은 Threshold 값으로 변환
  • THRESH_TOZERO: Threshold 값 이하는 0으로, 초과값은 밝기 값 그대로 변환
  • THRESH_TOZERO_INV: Threshold 값 이하는 그대로, 초과값은 0으로
  • THRESH_MASK: 모든 픽셀 값을 0으로변환
  • THRESH_OTSU: 내부 알고리즘을 통하여 최적화된 값으로 이진화
  • THRESH_TRIANGLE: Triangle 알고리즘을 통하여 최적화된 값으로 이진화

SetArea 함수를 통하여 변환하고자 하는 이미지의 사이즈를 설정할 수 있습니다.

GetOptions 를 통하여 설정값을 가져오고 SetOptions 로 변경된 값을 적용

이후 Inspeciton 을 통해 검사 후 GetResultImage 를 통해 이진화된 이미지를 받아옵니다

ConvertImage convertImage = new ConvertImage();
convertImage.SetImage(_images[0]);
SaigeRectangle rectangle = new SaigeRectangle(int x, int y, int widhth, int height);
convertImage.SetArea(rectangle);

var convertOption = convertImage.GetOptions();
convertOption.ConvertType = ThresholdFlags.THRESH_BINARY;
convertOption.MaxThreshold = 255;
convertOption.Threshold = 50;
convertImage.SetOptions(convertOption);

convertImage.Inspection();
Bitmap binaryImage = convertImage.GetResultImage();

FindCircle 생성 후 SetImage 를 통해 찾을 이미지를 설정하고, SetArea 를 통해 검사 영역을 설정하게 됩니다.

GetOptions 를 통하여 설정값을 가져오고 SetOptions 로 변경된 값을 적용합니다

  • ScoreThreshold: 원을 찾게 할 최소 스코어값 입니다. 해당 스코어보다 낮은 경우 원을 찾지 않습니다.
  • BackgroundColorFlags: 배경색을 선택하고 해당하는 배경과 찾으려는 원의 색상에 맞춰 결과를 가져오게 됩니다.
    • BLACK: 배경은 검정색, 원은 흰색인 경우 찾게 됩니다.
    • WHITE: 배경은 흰색, 원은 검정색인 경우 찾게 됩니다.

이후 Inspeciton 을 통해 검사 후 GetResult 를 통해 최종 결과를 받아옵니다.


FindCircle findCircle = new FindCircle();
findCircle.SetImage(binaryImage);
findCircle.SetArea(rectangle);

var option = findCircle.GetOptions();
option.ScoreThreshold = 0.9;
option.BackgroundColorFlags = BackgroundColorFlags.BLACK;
findCircle.SetOptions(option);

findCircle.Inspection();

var result = findCircle.GetResult();

모든 검사가 완료되었다면 Dispose 를 통해 메모리를 해제해 줍니다.

findCircle.Dispose();
convertImage.Dispose();
  • Improve this Doc
In This Article
Back to top Generated by DocFX