Created
December 23, 2014 17:45
-
-
Save TheB1ackSheep/dde35eb870f34883ecfb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void RecDetection(Image<Gray, Byte> img, Image<Bgr, Byte> showRecOnImg, int areaV) | |
{ | |
Image<Gray, Byte> imgForContour = new Image<Gray, byte>(img.Width, img.Height); | |
CvInvoke.cvCopy(img, imgForContour, System.IntPtr.Zero); | |
IntPtr storage = CvInvoke.cvCreateMemStorage(0); | |
IntPtr contour = new IntPtr(); | |
CvInvoke.cvFindContours( | |
imgForContour, | |
storage, | |
ref contour, | |
System.Runtime.InteropServices.Marshal.SizeOf(typeof(MCvContour)), | |
Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_EXTERNAL, | |
Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_NONE, | |
new Point(0, 0)); | |
Seq<Point> seq = new Seq<Point>(contour, null); | |
for (; seq != null && seq.Ptr.ToInt64() != 0; seq = seq.HNext) | |
{ | |
Rectangle bndRec = CvInvoke.cvBoundingRect(seq, 2); | |
double areaC = CvInvoke.cvContourArea(seq, MCvSlice.WholeSeq, 1) * -1; | |
if (areaC > areaV) | |
{ | |
CvInvoke.cvRectangle(showRecOnImg, new Point(bndRec.X, bndRec.Y), | |
new Point(bndRec.X + bndRec.Width, bndRec.Y + bndRec.Height), | |
new MCvScalar(0, 0, 255), 1, LINE_TYPE.CV_AA, 0); | |
} | |
} | |
pbSrc.Image = showRecOnImg.ToBitmap(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment