2012-05-19 3 views
4

문제가 있습니다. 그러나 무엇을 알지 못합니다! 나는 다음 코드를 가지고 있고, 내가 그것을 디버깅 할 때, 디버거는 내가이 CvSeq 윤곽 = 새 CvSeq (iplGray)와 관련이있다 생각JavaCV 또는 OPENCV에서 윤곽 찾기

IplImage iplGray = cvCreateImage(cvGetSize(iplUltima), 8, 1); 
CvMemStorage g_storage = null; 
CvSeq contours = new CvSeq(iplGray); 

opencv_imgproc.cvCvtColor(iplUltima, iplGray, opencv_imgproc.CV_BGR2GRAY); 
opencv_imgproc.cvThreshold(iplGray, iplGray, 100, 255, opencv_imgproc.CV_THRESH_BINARY); 

//HERE, the next line: 
opencv_imgproc.cvFindContours(iplGray, g_storage, contours, CV_C, CV_C, CV_C); 
cvZero(iplGray); 
if(contours != null){ 
    opencv_core.cvDrawContours(iplGray, contours, CvScalar.ONE, CvScalar.ONE, CV_C, CV_C, CV_C);    
} 
cvShowImage("Contours", iplGray); 

에 중지; 그러나 나는 왜 그런지 이해하지 못합니다. 유용한 아이디어가 있습니까?

+0

헤이 어떤 해결책을 제안 했니? 그렇다면 친절하게 공유하십시오. 감사합니다 –

답변

4

등고선 탐지의 경우이 방법을 사용했습니다. 잘 수행됩니다.

public static IplImage detectObjects(IplImage srcImage){ 

    IplImage resultImage = cvCloneImage(srcImage); 

    CvMemStorage mem = CvMemStorage.create(); 
    CvSeq contours = new CvSeq(); 
    CvSeq ptr = new CvSeq(); 

    cvFindContours(srcImage, mem, contours, Loader.sizeof(CvContour.class) , CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0)); 

    CvRect boundbox; 

    for (ptr = contours; ptr != null; ptr = ptr.h_next()) { 
     boundbox = cvBoundingRect(ptr, 0); 

      cvRectangle(resultImage , cvPoint(boundbox.x(), boundbox.y()), 
       cvPoint(boundbox.x() + boundbox.width(), boundbox.y() + boundbox.height()), 
       cvScalar(0, 255, 0, 0), 1, 0, 0); 
    } 

    return resultImage; 
} 
+0

위의 방법을 특별히 길이 사용하여 다각형 모양을 식별하는 방법을 설명해 주시겠습니까? –

+0

건초는이 코드가 맞습니까 ?? cvRectangle() 메서드가 올바른 매개 변수가 아니기 때문에 그것은 아닌가요? –

0

기본 예제와 여기에 다른 대답은 (함수와 클래스는 이력서 * 접두어) 이전 OpenCV의 1.x에서의 C API와 유사한 구문을 사용합니다.

OpenCV는 OpenCV 2.x에 최신 C++ API를 도입하여 훨씬 간단하고 이해하기 쉽습니다. JavaCV는 또한 최근 버전에서이 구문을 추가했습니다. 합니다 (OpenCV의 C++ API와 유사) 새로운 구문을 사용하고자하는 사람들을 위해

가 여기 윤곽 검출을위한 JavaCV 조각입니다 - (JavaCV 1.3.2를 사용)

Mat img = imread("/path/to/image.jpg",CV_LOAD_IMAGE_GRAYSCALE); 

MatVector result = new MatVector(); // MatVector is a JavaCV list of Mats 

findContours(img, result, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE); 

// The contours are now available in "result" 

// You can access them using result.get(index), check the docs linked below for more info 

MatVector documentation