rindarith / javacv

Automatically exported from code.google.com/p/javacv
GNU General Public License v2.0
0 stars 0 forks source link

cvFindContours different results #126

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,
I'm running the codes below in JavaCV (Android) and C (VisualStudio) and I'm 
getting different results. Is anything  wrong with the code? Did I translate 
wrongly? I'm loading the same image on both codes.

JavaCV code:

IplImage source = cvLoadImage(imageName,0);
CvMemStorage storage = CvMemStorage.create();
CvSeq contour = new CvSeq(null);

cvFindContours( source, storage, contour,Loader.sizeof(CvContour.class), 
CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE,cvPoint(0, 0));
         for(int i=0; i< (contour != null ? contour.total() : 0); i++)
         {
                CvRect rect = new CvRect(cvGetSeqElem(contour, i));
         }

C code:

CvMemStorage* storage = cvCreateMemStorage(0);
CvSeq* contour = 0;
IplImage* src =  cvLoadImage(imageName, 0) ;

cvFindContours( src, storage, &contour,sizeof(CvContour), CV_RETR_LIST, 
CV_CHAIN_APPROX_SIMPLE  , cvPoint(0,0) );
        for( ; contour != 0; contour = contour->h_next )
        {
          CvRect rect3 = ((CvContour*)contour)->rect;
        }

Original issue reported on code.google.com by rkrind...@gmail.com on 1 Nov 2011 at 9:54

GoogleCodeExporter commented 9 years ago
How different?

Also, you are not doing /exactly/ the same thing, so you may get different 
results, yes. Try to run code that matches as closing as possible, using 
NetBeans/Java instead of Visual C++ for example, and also use the same version 
of OpenCV.

Original comment by samuel.a...@gmail.com on 2 Nov 2011 at 12:35

GoogleCodeExporter commented 9 years ago
Looking back at this, if you would like the Java code to give the same results 
as in C, you should call `contour = contour.h_next()` in your loop, not 
`cvGetSeqElem(contour, i)`

Please post your questions on the mailing list next time, this is not a valid 
issue, thank you.

Original comment by samuel.a...@gmail.com on 8 Jan 2012 at 3:46