안녕하세요. 요즘 Matrox Mil을 공부하고 있는데요.
관련 예제코드를 학습하는데 예제코드의 결과값이 안나와서
MappAllocDefault라는 함수를 제거하고
Application, System, Image ID값을 각각 할당 받게해서 바꿔서 했습니다.
예를들어,
MappAllocDefault(M_SETUP, &MilApplication, &MilSystem, M_NULL, M_NULL, M_NULL); //이 함수를
MappAlloc(M_SETUP, &MilApplication); //이 두가지
MsysAlloc(M_DEF_SYSTEM_TYPE, M_DEF_SYSTEM_NUM, M_SETUP, &MilSystem); //함수로
이랬더니 비록 application id는 0이지만 system id값을 할당 받아서
MbufRestore 이 함수를 호출했습니다. 근데 계속 여기서 access violation이 발생하네요.....(error 이미지 업로드했습니다.)
이유를 잘 모르겠어서 질문을 올립니다.
코딩 환경은 XE1에 mil 8.0입니다. 그리고 제가만든 코드와 원본 예제코드를 올리겠습니다.
//저의 코드
#define GRID_IMAGE_FILE_EX2 ".\\Images\\CalGrid.mim"
#define BOARD_IMAGE_FILE_EX2 ".\\Images\\GenBoard.mim"
#define GRID_OFFSET_X_EX2 0
#define GRID_OFFSET_Y_EX2 0
#define GRID_OFFSET_Z_EX2 0
#define GRID_ROW_SPACING_EX2 1
#define GRID_COLUMN_SPACING_EX2 1
#define GRID_ROW_NUMBER_EX2 18
#define GRID_COLUMN_NUMBER_EX2 25
#define MEAS_BOX_POS_X_EX2 55
#define MEAS_BOX_POS_Y_EX2 24
#define MEAS_BOX_WIDTH_EX2 7
#define MEAS_BOX_HEIGHT_EX2 425
#define APPROXIMATE_STRIPE_WIDTH_EX2 425
#define M_WIDTH_WEIGHT_FACTOR_EX2 98
void __fastcall TfrmVisionTestMilEx::ExampleCalibration(void)
{
MIL_ID MilApplication;
MIL_ID MilSystem;
MIL_ID MilImage;
MIL_ID MilCalibration;
MIL_ID MeasMarker;
double WorldWidth;
/*Allocate defaults*/
//MappAllocDefault(M_SETUP, &MilApplication, &MilSystem, M_NULL, M_NULL, M_NULL);
MappAlloc(M_SETUP, &MilApplication);
MsysAlloc(M_DEF_SYSTEM_TYPE, M_DEF_SYSTEM_NUM, M_SETUP, &MilSystem);
/*Restore an image of a grid grabbed with a camera with severe lens aberration into an automatically allocated image buffer.*/
MbufRestore(GRID_IMAGE_FILE_EX2, MilSystem, &MilImage);
/*Allocate a camera calibration object*/
McalAlloc(MilSystem, M_DEFAULT, M_DEFAULT, &MilCalibration);
/* Calibrate the camera with the image of the grid*/
/* and its world description.*/
McalGrid(MilCalibration, MilImage,
GRID_OFFSET_X_EX2, GRID_OFFSET_Y_EX2, GRID_OFFSET_Z_EX2,
GRID_ROW_NUMBER_EX2, GRID_COLUMN_NUMBER_EX2, GRID_ROW_SPACING_EX2, GRID_COLUMN_SPACING_EX2,
M_DEFAULT, M_DEFAULT);
/*Load an image of a board grabbed with a camera with severe lens aberration and associate the calibration to the image.*/
MbufLoad(BOARD_IMAGE_FILE_EX2, MilImage);
McalAssociate(MilCalibration, MilImage, M_DEFAULT);
/*Allocate a measurement marker to perform measurement on the calibrated image in "Real world" unit*/
MmeasAllocMarker(MilSystem, M_STRIPE, M_DEFAULT, &MeasMarker);
/*Set the marker measurement box*/
MmeasSetMarker(MeasMarker, M_BOX_ORIGIN, MEAS_BOX_POS_X_EX2, MEAS_BOX_POS_Y_EX2);
MmeasSetMarker(MeasMarker, M_BOX_SIZE, MEAS_BOX_WIDTH_EX2, MEAS_BOX_HEIGHT_EX2);
/*Set marker orientation.*/
MmeasSetMarker(MeasMarker, M_ORIENTATION, M_HORIZONTAL, M_NULL);
/*Set marker approximative width and the associated weight factor.*/
MmeasSetMarker(MeasMarker, M_WIDTH, APPROXIMATE_STRIPE_WIDTH_EX2, M_NULL);
MmeasSetMarker(MeasMarker, M_WEIGHT_FACTOR+M_WIDTH, M_WIDTH_WEIGHT_FACTOR_EX2, M_NULL);
/*Find the stripe(2 board edges) in the calibrated image and measure its width in "real world" unit.*/
MmeasFindMarker(M_DEFAULT, MilImage, MeasMarker, M_WIDTH);
/*Get the world width of the marker.*/
MmeasGetResult(MeasMarker, M_WIDTH, &WorldWidth, M_NULL);
/*Show measurement result.*/
UnicodeString strLog;
strLog.sprintf(L"The board width is %8.4lf centimeters.", WorldWidth);
Log->Lines->Add(strLog);
/*Free all allocations*/
MmeasFree(MeasMarker);
McalFree(MilCalibration);
MbufFree(MilImage);
MappFreeDefault(MilApplication, MilSystem, M_NULL, M_NULL, M_NULL);
}
//원본코드 (c++ 코드)
/* Regular includes. */
#include <mil.h>
#include <stdio.h>
/* Source image files specification. */
#define GRID_IMAGE_FILE "CalGrid.mim"
#define BOARD_IMAGE_FILE "GenBoard.mim"
/* World description of the calibration grid. */
#define GRID_OFFSET_X 0
#define GRID_OFFSET_Y 0
#define GRID_OFFSET_Z 0
#define GRID_ROW_SPACING 1
#define GRID_COLUMN_SPACING 1
#define GRID_ROW_NUMBER 18
#define GRID_COLUMN_NUMBER 25
/* Measurement box specification */
#define MEAS_BOX_POS_X 55
#define MEAS_BOX_POS_Y 24
#define MEAS_BOX_WIDTH 7
#define MEAS_BOX_HEIGHT 425
/* Specification of the stripe constraints. */
#define APPROXIMATE_STRIPE_WIDTH 425
#define M_WIDTH_WEIGHT_FACTOR 98
/* Main application function */
void main()
{
MIL_ID MilApplication, /* Application identifier. */
MilSystem, /* System identifier. */
MilImage, /* Image buffer identifier. */
MilCalibration, /* Calibration identifier. */
MeasMarker, /* Measurement marker identifier. */
double WorldWidth;
/* Allocate defaults */
MappAllocDefault(M_SETUP, &MilApplication, &MilSystem, M_NULL, M_NULL, M_NULL);
/* Restore an image of a grid grabbed with a camera with severe lens aberration into an automatically allocated image buffer.
*/
MbufRestore(GRID_IMAGE_FILE, MilSystem, &MilImage);
/* Allocate a camera calibration object. */
McalAlloc(M_DEFAULT, M_DEFAULT, &MilCalibration);
/* Calibrate the camera with the image of the grid
* and its world description.
*/
McalGrid(MilCalibration, MilImage,
GRID_OFFSET_X, GRID_OFFSET_Y, GRID_OFFSET_Z, GRID_ROW_NUMBER, GRID_COLUMN_NUMBER,
GRID_ROW_SPACING, GRID_COLUMN_SPACING, M_DEFAULT, M_DEFAULT);
/* Load an image of a board grabbed with a camera with severe lens aberration and associate the calibration to the image. */
MbufLoad(BOARD_IMAGE_FILE, MilImage);
McalAssociate(MilCalibration, MilImage, M_DEFAULT);
/* Allocate a measurement marker to perform measurement on the calibrated image in "real world" unit. */
MmeasAllocMarker(MilSystem, M_STRIPE, M_DEFAULT, &MeasMarker);
/* Set the marker measurement box. */
MmeasSetMarker(MeasMarker, M_BOX_ORIGIN, MEAS_BOX_POS_X, MEAS_BOX_POS_Y);
MmeasSetMarker(MeasMarker, M_BOX_SIZE, MEAS_BOX_WIDTH, MEAS_BOX_HEIGHT);
/* Set marker orientation. */
MmeasSetMarker(MeasMarker, M_ORIENTATION, M_HORIZONTAL, M_NULL);
/* Set marker approximative width and the associated weight factor. */
MmeasSetMarker(MeasMarker, M_WIDTH, APPROXIMATE_STRIPE_WIDTH, M_NULL);
MmeasSetMarker(MeasMarker, M_WEIGHT_FACTOR+M_WIDTH, M_WIDTH_WEIGHT_FACTOR, M_NULL);
/* Find the stripe (2 board edges) in the calibrated image and measure its width in "real world" unit.
*/
MmeasFindMarker(M_DEFAULT, MilImage, MeasMarker, M_WIDTH);
/* Get the world width of the marker. */
MmeasGetResult(MeasMarker, M_WIDTH, &WorldWidth, M_NULL);
/* Pause to show the measurement result. */
printf("The board width is %8.4lf centimeters.\n", WorldWidth);
printf("Press <Enter> to end.\n\n");
getchar();
/* Free all allocations */
MmeasFree(MeasMarker);
McalFree(MilCalibration);
MbufFree(MilImage);
MappFreeDefault(MilApplication, MilSystem, M_NULL, M_NULL, M_NULL);
}
아낌 없는 조언 부탁드립니다.
|