Пример #1
0
        public CVImage DrawContours()
        {
            CVImage grayscaled = (this.Channels == 1 ? this : this.ToGrayscale());

            __CvMemStoragePtr storage = PInvoke.cvCreateMemStorage(0);
            __CvSeqPtr        first_contour;
            CVImage           result = new CVImage(this.Width, this.Height, CVDepth.Depth8U, 3);

            unsafe
            {
                int num_contours = PInvoke.cvFindContours(
                    grayscaled.Internal,
                    storage,
                    out first_contour,
                    sizeof(__CvContour),
                    CV_RETR.CV_RETR_EXTERNAL,
                    CV_CHAIN.CV_CHAIN_APPROX_SIMPLE,
                    new __CvPoint(0, 0)
                    );

                // Makes an output image and draw contours:
                __CvSeq *cont = first_contour.ToPointer();

                for (; (cont = cont->_cvSequenceFields.__cvTreeNodeFields.h_next.ToPointer()) != null;)
                {
                    PInvoke.cvDrawContours(result.Array, new __CvSeqPtr(cont), new __CvScalar(255, 0, 0), new __CvScalar(0, 0, 0), 0, (int)CVGlobalConsts.CV_FILLED);
                    CVUtils.CheckLastError();
                }
            }

            PInvoke.cvReleaseMemStorage(ref storage);
            CVUtils.CheckLastError();
            return(result);
        }
Пример #2
0
 public unsafe __CvSeqPtr(__CvSeq *ptr)
 {
     this.ptr = new IntPtr((void *)ptr);
 }