C# - 머신 비전 알고리즘 - OpenCV - 이미지처리7
# 디지털 이미지 처리
# 이미지의 상태 정보에서 특별한 영역을 추출한다.
> blob 으로 처리
# 이미지 처리 - OpenCV 4.5.3 으로 테스트
# 이미지의 상태 정보에서 특별한 영역을 추출
> srcImage : 입력, dst_label : 결과, stats : 결과 정보, centroids : 중심 위치, connectivity : 검색, ltype : 자료형
# cv::connectedComponentWithStats
> 이미지의 상태 정보를 특별한 형태로 재표현 - 출력 : 32비트 이미지
> double thresh = 128.0, max_val = 255.0;
> ThresholdTypes type = ThresholdTypes.Binary;
> Cv2.Threshold(srcImage, dstImage, thresh, max_val, type);
> PixelConnectivity connectivity = PixelConnectivity.Connectivity8;
> MatType ltype = MatType.CV_32S;
> Mat dst_label = new Mat(), stats = new Mat(), centroids = new Mat();
> int nCount = Cv2.ConnectedComponentsWithStats(dstImage, dst_label, stats, centroids, connectivity, ltype);
if (0 < nCount)
{
for (int i = 0; i < nCount; i++)
{
int nL = stats.At<int>(i, (int)ConnectedComponentsTypes.Left);
int nT = stats.At<int>(i, (int)ConnectedComponentsTypes.Top);
int nW = stats.At<int>(i, (int)ConnectedComponentsTypes.Width);
int nH = stats.At<int>(i, (int)ConnectedComponentsTypes.Height);
int nA = stats.At<int>(i, (int)ConnectedComponentsTypes.Area);
}
}