2014-05-19 5 views
1

이미지에서 윤곽선을 그려 가고 있습니다. 내 웹캠에서 윤곽을 추출하는 프레임이 있습니다. 그런 다음 영역별로 필터를 적용하고 drawContours()를 호출하여 표시합니다. 문제는 필자가 필터링 된 윤곽선을 그릴 때입니다. 원본을 그리면 모든 것이 정상적으로 작동합니다. 다음 코드는 :OpenCV : 어설 션이 drawContours()와 함께 실패했습니다.

size_t contours_size=contours.size(); 
    bool contour_is_valid[contours_size]; 
    size_t filtered_contours=0; 
    size_t copied_contours=0; 
    size_t i; 
    double area; 
    for(i=0;i<contours_size;i++){ 
     area=contourArea(contours.at(i),false); 
     if(area>minArea && area<maxArea){ 
      contour_is_valid[i]=true; 
      filtered_contours++; 
     } 
     else{ 
      contour_is_valid[i]=false; 
     } 
    } 
    area_filtered_contours.resize(filtered_contours); 
    for(i=0;i<contours_size;i++){ 
    if(contour_is_valid[i]==true){ 
      area_filtered_contours.at(copied_contours).resize(contours.at(i).size()); 
      copy(contours.at(i).begin(),contours.at(i).end(),back_inserter(area_filtered_contours.at(copied_contours))); 
      copied_contours++; 
     } 
    } 

윤곽 findContours() 및 이와의 출력, area_filtered_contours 동등한 벡터로서의 벡터 < < 포인트 ""데이터. 내가 뭘 하려는지는 지역 감각으로 유용한 윤곽선을 가진 것과 같은 다른 구조를 생성하는 것입니다. 그런 다음

drawContours(cnt_img2,contours,_levels <= 0 ? 3 : -1, 255,1,8,hierarchy, std::abs(_levels)); 

잘 작동하지만

drawContours(cnt_img2,area_filtered_contours,_levels <= 0 ? 3 : -1, 255,1,8,hierarchy, std::abs(_levels)); 

나에게 주장의 오류를 제공합니다. 무엇이 문제 일 수 있습니까? 사전에

감사합니다,

페데리코

+0

는 어쩌면이 같은 오류가이 선 발생, 도움이 될 것입니다 '벡터 <벡터 > 테스트; \t \t test.resize (1); \t \t test.at (0) .resize (1); \t drawContours (cnt_img2, test, _levels <= 0? 3 : -1, 255,1,8, hierarchy, std :: abs (_levels)); ' – gedefet

+0

어설 션 오류를 제공 해주실 수 있습니까? –

+0

@ ØysteinW. OpenCV 오류 : drawContours에서 어설 션이 실패했습니다 (hierarchy.total() == ncontours && hierarchy.type() == CV_32SC4). /tmp/buildd/opencv-2.3.1/modules/imgproc/src/contours.cpp 파일 , 1604 'cv :: Exception'인스턴스를 던진 후 호출 됨 terminate : what() : /tmp/buildd/opencv-2.3.1/modules/imgproc/src/contours.cpp:1604 : 오류 : (-215)) hierarchy.total() == ncontours && hierarchy.type() == 함수 drawContours의 CV_32SC4 – gedefet

답변

3

당신의 주장이 말하기를 : OpenCV의 오류 : 어설 션 실패 (== hierarchy.total() ncontours & & hierarchy.type() == CV_32SC4)

findContours() (opencv.org)의 계층 구조에 대한 정보 : 이미지 토폴로지에 대한 정보를 포함하는 선택적 출력 벡터. 윤곽선 수만큼 요소가 있습니다.

카운트 수를 변경하는 경우에도 계층을 편집해야합니다. 이것은 선택적 입력입니다. 이것을 편집하거나 사용하지 마십시오.

+1

계층 구조를 사용하지 않는 drawContours에 과부하가 있습니다. – berak

+0

이제 작동하지만 윤곽선이 제대로 표시되지 않습니다. (0,0)에서 윤곽선으로가는 선이 있고 때로는 (필터링 된 윤곽선이 없을 때) 창에 마지막 윤곽선이 있습니다. – gedefet

+0

모든 윤곽선에 (0,0)의 선이 있습니까? 필터링 된 경우입니까? 그리고 "창에는 마지막 윤곽이 있습니다"라는 의미는 무엇입니까? –

관련 문제