예제 #1
0
        private bool RecDetection(Image <Gray, Byte> img, Image <Bgr, Byte> showRecOnImg, int areaV, int camID)
        {
            bool checkdetection = false;
            Image <Gray, Byte> imgForContour = new Image <Gray, byte>(img.Width, img.Height);

            CvInvoke.cvCopy(img, imgForContour, System.IntPtr.Zero);

            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);

            if (seq.Ptr.ToInt64() == 0 && camID == 1)
            {
                //KalmanFilter(camID);
                ResetBot();
            }



            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)
                {
                    if (camID == 0)
                    {
                        centroid0           = new Point(bndRec.X + bndRec.Width / 2, bndRec.Y + bndRec.Height / 2);
                        Camera0XPosBox.Text = centroid0.ToString();
                        //DesiredY.Text = (((240-centroid0.Y)-120+28)*82/240).ToString();
                    }
                    else if (camID == 1)
                    {
                        centroid1 = new Point(bndRec.X + bndRec.Width / 2, bndRec.Y + bndRec.Height / 2);
                        //try
                        //{
                        //    List<float> estimatedvelocities = UpdateKalmanFilter((float)((double)sw.ElapsedMilliseconds / 1000.0), (float)centroid1.Y, 0);
                        //    centroid1 = new Point((int)estimatedvelocities[0], (int)estimatedvelocities[1]);
                        //}
                        //catch { }

                        Camera1XPosBox.Text = centroid1.ToString();
                        //DesiredX.Text = (((240-centroid1.Y)-130) * 83 / 240 *35 / 45).ToString();
                    }
                    checkdetection = true;
                    CvInvoke.cvCircle(showRecOnImg, new Point(bndRec.X + bndRec.Width / 2, bndRec.Y + bndRec.Height / 2), (int)((bndRec.Width / 2 + bndRec.Height / 2) / 2), new MCvScalar(0, 255, 0), 4, LINE_TYPE.CV_AA, 0);
                    if (startlog == true)
                    {
                        if (camID == 0)
                        {
                            Cam0TextBox.AppendText(Math.Round((double)sw.ElapsedMilliseconds / 1000.0, 2) + "\t" + (bndRec.X + bndRec.Width / 2) + "\t" + (bndRec.Y + bndRec.Height / 2) + "\n");
                        }
                        else if (camID == 1)
                        {
                            Cam1TextBox.AppendText(Math.Round((double)sw.ElapsedMilliseconds / 1000.0, 2) + "\t" + (bndRec.X + bndRec.Width / 2) + "\t" + (bndRec.Y + bndRec.Height / 2) + "\n");
                        }
                    }
                }
            }
            return(checkdetection);
        }
예제 #2
0
 private void ClearLogButton_Click(object sender, EventArgs e)
 {
     Cam1TextBox.Clear();
     Cam0TextBox.Clear();
 }