2014년 10월 8일 수요일

Iplimage의 depth와 Mat의 depth()

 Opencv를 쓸때 예전엔 Iplimage 자료형을 많이 쓰다가 최근 들어 Mat 자료형을 많이 쓰려고 한다. 그래서 이전에 만들었던 함수중 Iplimage* 를 인자로 받는 함수를 Mat도 가능하게 끔 오버라이딩해서 하나 더 만들려고 했다. 당연히 Iplimage->depth와 Mat.depth()가 동일할 것으로 예상했는데 에러가 떳다.
 Opencv tutorial에는 아래처럼 설명이 되어있는데 실제 코드 상(types_c.h)에 define 되어 있는 값은 서로 다르다. ㅜ
----------------------------------------------------------------------------------------------------------------------------------
int depth
Channel depth in bits + the optional sign bit ( IPL_DEPTH_SIGN ). The supported depths are:
•IPL_DEPTH_8U - unsigned 8-bit integer. Equivalent to CV_8U in matrix types.
•IPL_DEPTH_8S - signed 8-bit integer. Equivalent to CV_8S in matrix types.
•IPL_DEPTH_16U - unsigned 16-bit integer. Equivalent to CV_16U in matrix types.
•IPL_DEPTH_16S - signed 8-bit integer. Equivalent to CV_16S in matrix types.
•IPL_DEPTH_32S - signed 32-bit integer. Equivalent to CV_32S in matrix types.
•IPL_DEPTH_32F - single-precision floating-point number. Equivalent to CV_32F in matrix types.
•IPL_DEPTH_64F - double-precision floating-point number. Equivalent to CV_64F in matrix types.

----------------------------------------------------------------------------------------------------------------

 아래가 define된 실제 값들이다.

#define IPL_DEPTH_1U 1
#define IPL_DEPTH_8U 8
#define IPL_DEPTH_16U 16
#define IPL_DEPTH_32F 32

#define CV_8U 0
#define CV_8S 1
#define CV_16U 2
#define CV_16S 3
#define CV_32S 4
#define CV_32F 5
#define CV_64F 6


 해당 헤더 파일을 한참 읽어 내려가다 아래와 같은 함수를 하나 찾았다. 인자로 type을 받는 거보니 Mat.type()을 인자로 넣어 주면 될 거 같다.
CV_INLINE int cvIplDepth( int type )
{
    int depth = CV_MAT_DEPTH(type);
    return CV_ELEM_SIZE1(depth)*8 | (depth == CV_8S || depth == CV_16S ||
           depth == CV_32S ? IPL_DEPTH_SIGN : 0);
}

댓글 없음:

댓글 쓰기