저는 CvContourTree에 대한 포인터를 가지고 있으며 이에 대한 관련 윤곽을 도출하고자합니다.OpenCV : 등고선 트리에서 등고선으로 변환하기 - cvContourFromContourTree()
나는이 할 것 기능을 사용하려고 한 -
cvContourFromContourTree을 (const를 CvContourTree * 나무, CvMemStorage * 저장, CvTermCriteria 기준)
그러나 그것은 나에게 오류주고있다 :
을 'Matching_Hierarchial.exe에서 0x1005567f의 처리되지 않은 예외 : 0xC0000005 : 액세스 위반 읽기 위치가 0x00000002입니다.' 다음과 같이
은 내가 CvTermCriteria을 정의했습니다 :
CvTermCriteria termcrit = cvTermCriteria (CV_TERMCRIT_ITER | CV_TERMCRIT_EPS, 5,1)를;
등고선을 등고선 트리로 변환 한 다음 다시 등고선으로 다시 변환하는 방법에 대한 샘플 코드를 제공해주십시오. 나는이 문제에 대한 도움에 대해 매우 감사 할 것입니다. 감사합니다,
코너 귀하의 빠른 응답에 대한
감사합니다. attched 코드 세그먼트를 참조하십시오. 내 프로젝트 폴더에서 이미지를 가져 와서 이진 파일로 변환했습니다. 나는 그 다음 등고선을 발견했다. 임의의 윤곽선을 사용하여 폴리곤 근사를 통해 복잡성을 단순화했습니다. 이 등고선으로부터 등고선 트리를 구성합니다 (이 컨투어 트리를 cvMatchContourTrees()를 사용하여 유사한 윤곽 트리를 테스트하고 유리한 결과를 얻었으므로이 작업이 정상적으로 작동하고 있다고 확신합니다). 그러나 기능 및 게시물에서 찾을 수있는 모든 것을 읽었음에도 윤곽선 트리에서 윤곽 구조로 다시 변환 할 수는 없습니다.
#include "stdafx.h"
#include "cv.h"
#include "highgui.h"
#include "cxcore.h"
#include "cvaux.h"
#include <iostream>
using namespace std;
#define CVX_RED CV_RGB(0xff,0x00,0x00)
#define CVX_BLUE CV_RGB(0x00,0x00,0xff)
int _tmain(int argc, _TCHAR* argv[])
{
// define input image
IplImage *img1 = cvLoadImage("SHAPE1.jpg",0);
// define and construct binary image of input image
IplImage *imgEdge1 = cvCreateImage(cvGetSize(img1),IPL_DEPTH_8U,1);
cvThreshold(img1,imgEdge1,155,255,CV_THRESH_BINARY);
// define and zero image to place polygon image
IplImage *dst1 = cvCreateImage(cvGetSize(img1),IPL_DEPTH_8U,1);
cvZero(dst1);
// display ip and thresholded image
cvNamedWindow("img1",1);
cvNamedWindow("thresh1",1);
cvShowImage("img1",img1);
cvShowImage("thresh1",imgEdge1);
// find all the contours of the image
CvSeq* contours1 = NULL;
CvMemStorage* storage1 = cvCreateMemStorage();
int numContour1 = cvFindContours(imgEdge1,storage1,&contours1,sizeof(CvContour),CV_RETR_TREE,CV_CHAIN_APPROX_SIMPLE);
cout<<"number of contours"<<numContour1<<endl;
// extract a contour of interest
CvSeq* poly_approx1 = contours1->v_next; // interested in vertical level becaue tree structure
// CALCULATE PERIMETER
double perimeter1 = cvArcLength((CvSeq*)poly_approx1,CV_WHOLE_SEQ,-1);
// CREATE POLYGON APPROXIMATION -
// NB: CANNOT USE 'CV_CHAIN_CODE'ARGUEMENT IN THE cvFindContours() call
CvSeq* polySeq1 = cvApproxPoly((CvSeq*)poly_approx1,sizeof(CvContour),storage1,CV_POLY_APPROX_DP,perimeter1*0.02,0);
// draw approximated polygon
cvDrawContours(dst1,polySeq1,cvScalar(255),cvScalar(255),0,3,8); // draw
// display polygon
cvNamedWindow("Poly Approx1",1);
cvShowImage("Poly Approx1",dst1);
// NOW WE HAVE A POLYGON APPROXIMATED CONTOUR
// CREATE A CONTOUR TREE
CvMemStorage *treeStorage1 = cvCreateMemStorage(0);
CvContourTree* tree1 = cvCreateContourTree((const CvSeq*)polySeq1,treeStorage1,0);
// TO RECONSTRUCT A CONTOUR FROM THE CONTOUR TREE
// CANNOT GET TO WORK YET...
CvMemStorage *stor = cvCreateMemStorage(0);
CvTermCriteria termcrit = cvTermCriteria(CV_TERMCRIT_ITER | CV_TERMCRIT_EPS ,5,1); // more later
/* the next line will not compile */
CvSeq *contour_recap = cvContourFromContourTree(tree1,treeStorage1,termcrit);
cvWaitKey(0);
return 0;
}
도움이나 조언을 해주셔서 다시 한 번 감사드립니다. 나는 당신에게 그것이 대단히 감사하다는 것을 확신한다.
conor