Measurement의 두 번째 실전,
Multiple Marker를 측정해 보겠습니다.
Measurement 샘플코드
아래의 샘플 이미지 중앙의 칩에서 납땜이 된 부분을
Measurement로 측정해 볼까요?
빨간색이 Measurement Box 입니다.
Multiple marker를 사용하기 위해서는
반드시 marker의 속성이 같아야 하며,
Marker의 개수와 marker의 간격을 MmeasSetMarker() 를 이용하여 설정해야 합니다.
코딩
MIL_ID MilStripMarker;
double angle, width, spacing;
CString strangle, strWidth, strSpacing;
MmeasAllocMarker(MilSystem, M_STRIPE, M_DEFAULT, &MilStripMarker);
MmeasSetMarker(MilStripMarker, M_NUMBER, 12, M_NULL);
MmeasSetMarker(MilStripMarker, M_POLARITY, M_POSITIVE, M_NEGATIVE);
MmeasSetMarker(MilStripMarker, M_ORIENTATION, M_VERTICAL, M_NULL);
MmeasSetMarker(MilStripMarker, M_BOX_ORIGIN, 220, 171);
MmeasSetMarker(MilStripMarker, M_BOX_SIZE, 230, 7);
MmeasFindMarker(M_DEFAULT, MilTargetImage, MilStripMarker, M_POSITION+M_ANGLE+M_WIDTH);
MgraColor(M_DEFAULT, M_RGB888((255, 0, 0));
MmeasDraw(M_DEFAULT, MilStripMarker, MilOverlay, M_DRAW_BOX, M_DEFAULT, M_RESULT);
MgraColor(M_DEFAULT, M_RGB888((255, 255, 0));
MmeasDraw(M_DEFAULT, MilStripMarker, MilOverlay, M_DRAW_POSITION, M_ALL, M_RESULT);
MmeasGetResult(MilStripMarker, M_ANGLE+M_MEAN, &angle, M_NULL);
MmeasGetResult(MilStripMarker, M_WIDTH+M_MEAN, &width, M_NULL);
MmeasGetResult(MilStripMarker, M_SPACING+M_MEAN, &spacing, M_NULL);
strAngle.Format("Average Angle= %.2f", angle);
strWidth.Format("Average Width= %.2f", width);
strSpacing.Format("Average Spacing= %.2f", spacing);
MgraText(M_DEFAULT, MilOverlay, 10, 10, (char*)(const char*)strAngle);
MgraText(M_DEFAULT, MilOverlay, 10, 30, (char*)(const char*)strWidth);
MgraText(M_DEFAULT, MilOverlay, 10, 50, (char*)(const char*)strSpacing);
MmeasFree(MilStripMarker);
샘플 코드 실행방법
1. Example.dsw 파일을 VC++ 6.0에서 열기
2. VC++ 6.0 Menu > Build > Execute 클릭
3. Image Load 버튼: chip.mim 파일 로드
4. Pattern Matching 버튼: Measurement 수행
코드 분석
MIL_ID MilStripeMarker;
double angle, width, spacing;
CString strangle, strWidth, strSpacing;
// 1. Alloc
MmeasAllocMarker(MilSystem, M_STRIPE, M_DEFAULT, &MilStripeMarker);
è Stripe 타입으로 마커를 할당합니다.
// 2. Marker Setting
MmeasSetMarker(MilStripeMarker, M_NUMBER, 12, M_NULL);
MmeasSetMarker(MilStripeMarker, M_POLARITY, M_POSITIVE, M_NEGATIVE);
MmeasSetMarker(MilStripeMarker, M_ORIENTATION, M_VERTICAL, M_NULL);
MmeasSetMarker(MilStripeMarker, M_BOX_ORIGIN, 220, 171);
MmeasSetMarker(MilStripeMarker, M_BOX_SIZE, 230, 7);
è 마커에 대한 셋팅입니다.
M_NUMBER: 검색하려는 마커의 개수
M_POLARITY: 마커의 극성.
좌측은 검정에서 흰색이므로 positive, 우측은 반대 설정임
M_ORIENTATION: 마커의 방향을 세로로 설정
M_BOX_ORIGIN: 측정 상자의 offset 좌표
M_BOX_SIZE: 마카의 사이즈 X, Y
// 3. Find Marker
MmeasFindMarker(M_DEFAULT, MilTargetImage, MilStripeMarker, M_POSITION+M_ANGLE+M_WIDTH);
MgraColor(M_DEFAULT, M_RGB888((255, 0, 0));
MmeasDraw(M_DEFAULT, MilStripeMarker, MilOverlay, M_DRAW_BOX, M_DEFAULT, M_RESULT);
MgraColor(M_DEFAULT, M_RGB888((255, 255, 0));
MmeasDraw(M_DEFAULT, MilStripeMarker, MilOverlay, M_DRAW_POSITION, M_ALL, M_RESULT);
è MmeasFindMarker: MilTargetImage에서 MilStripemarker의 위치, 각도, 폭을 검색.
측정 상자와 측정 위치를 각각 색상을 지정하여 그려줌.
// 4. Result
MmeasGetResult(MilStripeMarker, M_ANGLE+M_MEAN, &angle, M_NULL);
MmeasGetResult(MilStripeMarker, M_WIDTH+M_MEAN, &width, M_NULL);
MmeasGetResult(MilStripeMarker, M_SPACING+M_MEAN, &spacing, M_NULL);
strAngle.Format("Average Angle= %.2f", angle);
strWidth.Format("Average Width= %.2f", width);
strSpacing.Format("Average Spacing= %.2f", spacing);
MgraText(M_DEFAULT, MilOverlay, 10, 10, (char*)(const char*)strAngle);
MgraText(M_DEFAULT, MilOverlay, 10, 30, (char*)(const char*)strWidth);
MgraText(M_DEFAULT, MilOverlay, 10, 50, (char*)(const char*)strSpacing);
è 결과 값 검색
각도(angle), 폭(width), 마커 간의 간격(spacing)의 값을 얻어옴.
검색되는 값은 M_MEAN 파라메터를 통해 마커 간의 평균값으로 함.
// 5. Free
MmeasFree(MilStripeMarker);
è 마커 해제
테스트해 보시고, 많은 도움 되기 바랍니다.
궁금한 사항은 언제든지 Q&A 문의게시판을 이용해 주시고요.
자~ 그럼 다음 강좌에서 뵐게요~
'영상처리(Matrox Library, Frame grabber) > Matrox Library' 카테고리의 다른 글
[Matrox Imaging Library - MIL] 13. BLOB 시작하기 (0) | 2023.05.22 |
---|---|
[Matrox Imaging Library - MIL] 11 : Meas(Measurement) 샘플코드 (0) | 2021.07.06 |
[Matrox Imaging Library - MIL] 9 : Pat(Pattern Matching) 각도 설정에 대한 처리 속도 차이 (0) | 2021.06.23 |
[Matrox Imaging Library - MIL] 8 : Pat(Pattern Matching) 예제코드 분석 (0) | 2021.06.21 |
[Matrox Imaging Library - MIL] 6 : GMF(Geometric Model Finder) 예제 코드 분석 (2) | 2021.06.16 |