2011-01-18 2 views
6

OpenCV 워드 프로세서에서 약간의 손실이 있습니다. 배열에 cvFindContours가 반환 한 CvSeq을 저장하고 싶습니다. CvContour의 seq가 반환 될지 알지만, 찾을 수 없습니다. 들어 있습니까? 어떤 부분을 저장해야하는지 나중에 나중에 반복해서 cvBoundingRect 등을 호출 할 수 있습니다.배열에 CvSeq 저장

답변

8

CvContour는 CvSeq과 동일한 필드를 가진 구조체이며, 이것은 CvRect rect입니다 (include/opencv/cxtypes.h 참조). 그래서 그것은 CvSeq이 무엇인지에 달려 있습니다.

OpenCV 소스와 함께 제공되는 opencv.pdf이라는 파일이 있습니다. contourscvFindContours를 호출 한 후 첫 번째 윤곽을 가리키는 것

cvFindContours(img, storage, &contours, sizeof(CvContour), CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0)); 

을 :

#define CV_SEQUENCE\_FIELDS() 
    int flags; /* micsellaneous flags */ \ 
    int header_size; /* size of sequence header */ \ 
    struct CvSeq* h_prev; /* previous sequence */ \ 
    struct CvSeq* h_next; /* next sequence */ \ 
    struct CvSeq* v_prev; /* 2nd previous sequence */ \ 
    struct CvSeq* v_next; /* 2nd next sequence */ \ 
    int total; /* total number of elements */ \ 
    int elem_size;/* size of sequence element in bytes */ \ 
    char* block_max;/* maximal bound of the last block */ \ 
    char* ptr; /* current write pointer */ \ 
    int delta_elems; /* how many elements allocated when the sequence grows 
    (sequence granularity) */ \ 
    CvMemStorage* storage; /* where the seq is stored */ \ 
    CvSeqBlock* free_blocks; /* free blocks list */ \ 
    CvSeqBlock* first; /* pointer to the first sequence block */ 

typedef struct CvSeq 
{ 
    CV_SEQUENCE_FIELDS() 
} CvSeq; 

이의는이 같은 cvFindContours 전화를 가정 해 봅시다 : 138 (OpenCV의 2.1)는 다음과 같이 CvSeq가 정의되어 있다고 . 경계 사각형을 가져 오려면 cvBoundingRect에 전달하면됩니다. 시퀀스의 다음 윤곽선은 contours->h_next을 통해 액세스 할 수 있습니다. 윤곽 트리의 경우, 즉 윤곽선이 이미지의 다른 윤곽선 안에있을 때 contours->v_next을 통해 현재 윤곽선의 첫 번째 내부 윤곽에 액세스 할 수 있습니다. 다음 내부 윤곽선이있는 경우 contours->v_next->h_next 등이됩니다.

시퀀스를 배열로 변환하려면 cvCvtSeqToArray을 사용할 수 있습니다.

OpenCV 2.0에서 시작하여 사용하기가 더 좋은 C++ 인터페이스를 사용할 수도 있습니다. 예를 들어 CvSeq** contours의 매개 변수가 cvFindContours이면 vector<vector<Point> >& contours이됩니다.

관련 문제