티스토리 뷰

OpenCV를 이용해서 구현한 프로그램이 디버그 모드에서 아래와 같은 런타임 오류를 발생했다.


Run-Time Check Failure #2 - Stack around the variable "변수이름" was corrupted.


오류가 나는 변수 이름을 검색하니 OpenCV minMaxIdx 함수를 이용할때 최소값 index를 얻기 위해 사용한 변수이다.


오류의 원인을 찾아보니 일단,


Run-Time Check Failure #2 오류는 설정한 배열이나 변수 범위를 넘는 값이 전달될때 발생한다. 그리고 OpenCV minMaxIdx 함수 도큐먼트를 확인해 보니 min, max 인덱스 변수를 최소 2개의 element를 가져야 한다고 명시되어 있다.


When minIdx is not NULL, it must have at least 2 elements (as well as maxIdx), even if src is a single-row or single-column matrix. In OpenCV (following MATLAB) each array has at least 2 dimensions, i.e. single-column matrix is Mx1 matrix (and therefore minIdx/maxIdx will be (i1,0)/(i2,0)) and single-row matrix is 1xN matrix (and therefore minIdx/maxIdx will be (0,j1)/(0,j2)).

구현한 minMaxIdx 함수에 사용한 min, max 인덱스 변수를 array로 선언해서 사용하면 문제가 해결이 된다.


수정전


int min, max;

 double minVal, maxVal;


 minMaxIdx(src, &minVal, &maxVal, &min, &max)


수정후


int min[2], max[2];

 double minVal, maxVal;


 minMaxIdx(src, &minVal, &maxVal, min, max)




'OpenCV' 카테고리의 다른 글

OpenCV Smoothing Median Filter error  (0) 2016.10.31
OpenCV 2.4.10 Mac OS X 설치  (0) 2016.10.31
카메라 입력영상 AVI 저장  (0) 2016.10.30
OpenCV 2.4.9 설치 (Visual Studio 2012)  (0) 2016.10.30
댓글