public void RectangleTests()
        {
            int area      = 12;
            int perimeter = 14;

            Assert.AreEqual(area, Rec1.GetArea());
            Assert.AreEqual(perimeter, Rec1.GetPerimeter());

            area      = 20;
            perimeter = 18;

            Assert.AreEqual(area, Rec2.GetArea());
            Assert.AreEqual(perimeter, Rec2.GetPerimeter());

            area      = 50;
            perimeter = 30;

            Assert.AreEqual(area, Rec3.GetArea());
            Assert.AreEqual(perimeter, Rec3.GetPerimeter());

            area      = 24;
            perimeter = 20;

            Assert.AreEqual(area, Rec4.GetArea());
            Assert.AreEqual(perimeter, Rec4.GetPerimeter());

            area      = 63;
            perimeter = 32;

            Assert.AreEqual(area, Rec5.GetArea());
            Assert.AreEqual(perimeter, Rec5.GetPerimeter());
        }
Beispiel #2
0
        public void RectangleTests()
        {
            int area      = 12;
            int perimeter = 14;

            Assert.AreEqual(area, Rec1.GetArea());
            Assert.AreEqual(perimeter, Rec1.GetPerimeter());

            area      = 20;
            perimeter = 18;

            Assert.AreEqual(area, Rec2.GetArea());
            Assert.AreEqual(perimeter, Rec2.GetPerimeter());
        }
Beispiel #3
0
        public void CreateRecTest()
        {
            var mock = new Mock <IFaker>();

            mock.Setup(a => a.Create <Rec1>()).Returns(new Rec1());

            IFaker mockFaker = mock.Object;
            Rec2   expected  = null;
            Rec2   actual    = mockFaker.Create <Rec1>().A;

            if (expected == actual)
            {
                logger.Info("CreateRecTest compled succesfully: object are equal");
            }
            else
            {
                logger.Info("CreateRecTest compled not succesfully: object are't equal");
            }
            Assert.AreEqual(expected, actual);
        }
Beispiel #4
0
        private static void SampleSensorValues(object State)
        {
            measurementLed.High();
            try
            {
                lock (synchObject)
                {
                    DateTime Now = DateTime.Now;
                    Record   Rec, Rec2;

                    // Read sensors

                    temp  = (short)tmp102.ReadTemperatureRegister();
                    light = adc.ReadRegistersBinary() [0];

                    // Calculate average of last 10 measurements, to get smoother momentary values

                    sumTemp  -= tempAvgWindow [avgPos];
                    sumLight -= lightAvgWindow [avgPos];

                    tempAvgWindow [avgPos]  = temp;
                    lightAvgWindow [avgPos] = light;

                    sumTemp       += temp;
                    sumLight      += light;
                    motionDetected = motion.Value;

                    temperatureC = (sumTemp * 0.1 / 256.0);
                    lightPercent = (100.0 * 0.1 * sumLight) / 0x0fff;
                    avgPos       = (avgPos + 1) % 10;

                    // Update history

                    Rec = new Record(Now, temperatureC, lightPercent, motionDetected);                                  // Rank 0

                    perSecond.Add(Rec);
                    if (perSecond.Count > 1000)
                    {
                        perSecond.RemoveAt(0);
                    }

                    sumSeconds += Rec;
                    nrSeconds++;

                    if (Now.Second == 0)
                    {
                        Rec = sumSeconds / nrSeconds;                                   // Rank 1
                        perMinute.Add(Rec);
                        Rec.SaveNew();

                        if (perMinute.Count > 1000)
                        {
                            Rec2 = perMinute [0];
                            perMinute.RemoveAt(0);
                            Rec2.Delete();
                        }

                        sumMinutes += Rec;
                        nrMinutes++;

                        sumSeconds = null;
                        nrSeconds  = 0;

                        if (Now.Minute == 0)
                        {
                            Rec = sumMinutes / nrMinutes;
                            perHour.Add(Rec);
                            Rec.SaveNew();

                            if (perHour.Count > 1000)
                            {
                                Rec2 = perHour [0];
                                perHour.RemoveAt(0);
                                Rec2.Delete();
                            }

                            sumHours += Rec;
                            nrHours++;

                            sumMinutes = null;
                            nrMinutes  = 0;

                            if (Now.Hour == 0)
                            {
                                Rec = sumHours / nrHours;
                                perDay.Add(Rec);
                                Rec.SaveNew();

                                if (perDay.Count > 1000)
                                {
                                    Rec2 = perDay [0];
                                    perDay.RemoveAt(0);
                                    Rec2.Delete();
                                }

                                sumDays += Rec;
                                nrDays++;

                                sumHours = null;
                                nrHours  = 0;

                                if (Now.Day == 1)
                                {
                                    Rec = sumDays / nrDays;
                                    perMonth.Add(Rec);
                                    Rec.SaveNew();

                                    sumDays = null;
                                    nrDays  = 0;
                                }
                            }
                        }
                    }
                }

                errorLed.Low();
            } catch (Exception)
            {
                errorLed.High();
            } finally
            {
                measurementLed.Low();
            }
        }
Beispiel #5
0
        bool patternRightFound;       // True if chessboard found in image
        #endregion

        /**********************************************************
        * Calculates calibration transformatons and saves them.
        **********************************************************/
        public void Calibration()
        {
            string imagesPath = calibrationPath.Text;

            if (imageCalibration != true)
            {
                try
                {
                    FileStorage fs = new FileStorage(calibrationPath.Text, FileStorage.Mode.Read);
                    fs["rmapx1"].ReadMat(rmapx1);
                    fs["rmapy1"].ReadMat(rmapy1);
                    fs["rmapx2"].ReadMat(rmapx2);
                    fs["rmapy2"].ReadMat(rmapy2);

                    string rec1Str = fs["Rec1"].ReadString();
                    string rec2Str = fs["Rec2"].ReadString();

                    int idx1 = rec1Str.IndexOf('=');
                    int idx2 = rec1Str.IndexOf(',');
                    int x    = Convert.ToInt32(rec1Str.Substring(idx1 + 1, idx2 - idx1 - 1));
                    idx1 = rec1Str.IndexOf('=', idx2);
                    idx2 = rec1Str.IndexOf(',', idx1);
                    int y = Convert.ToInt32(rec1Str.Substring(idx1 + 1, idx2 - idx1 - 1));
                    idx1 = rec1Str.IndexOf('=', idx2);
                    idx2 = rec1Str.IndexOf(',', idx1);
                    int w = Convert.ToInt32(rec1Str.Substring(idx1 + 1, idx2 - idx1 - 1));
                    idx1 = rec1Str.IndexOf('=', idx2);
                    idx2 = rec1Str.Length;
                    int h = Convert.ToInt32(rec1Str.Substring(idx1 + 1, idx2 - idx1 - 1));

                    Rec1 = new Rectangle(x, y, w, h);

                    idx1 = rec2Str.IndexOf('=');
                    idx2 = rec2Str.IndexOf(',');
                    x    = Convert.ToInt32(rec2Str.Substring(idx1 + 1, idx2 - idx1 - 1));
                    idx1 = rec2Str.IndexOf('=', idx2);
                    idx2 = rec2Str.IndexOf(',', idx1);
                    y    = Convert.ToInt32(rec2Str.Substring(idx1 + 1, idx2 - idx1 - 1));
                    idx1 = rec2Str.IndexOf('=', idx2);
                    idx2 = rec2Str.IndexOf(',', idx1);
                    w    = Convert.ToInt32(rec2Str.Substring(idx1 + 1, idx2 - idx1 - 1));
                    idx1 = rec2Str.IndexOf('=', idx2);
                    idx2 = rec2Str.Length;
                    h    = Convert.ToInt32(rec2Str.Substring(idx1 + 1, idx2 - idx1 - 1));

                    Rec2 = new Rectangle(x, y, w, h);

                    MessageBox.Show("Transformation maps loaded successfully");
                }
                catch (Exception)
                {
                    MessageBox.Show("Error: Problem loading Transformation maps");
                    Environment.Exit(1);
                }
            }
            if (imageCalibration == true)
            {
                for (int i = 0; i < bufferLength * 2; i++)
                {
                    chessFrameL = CvInvoke.Imread(imagesPath + "\\camera1\\image_" + i.ToString() + ".jpg");
                    chessFrameR = CvInvoke.Imread(imagesPath + "\\camera2\\image_" + i.ToString() + ".jpg");

                    patternLeftFound  = CvInvoke.FindChessboardCorners(chessFrameL, patternSize, cornersVecLeft, CalibCbType.NormalizeImage | CalibCbType.AdaptiveThresh);
                    patternRightFound = CvInvoke.FindChessboardCorners(chessFrameR, patternSize, cornersVecRight, CalibCbType.NormalizeImage | CalibCbType.AdaptiveThresh);

                    if (patternLeftFound && patternRightFound)
                    {
                        CvInvoke.CvtColor(chessFrameL, grayLeft, ColorConversion.Bgr2Gray);
                        CvInvoke.CvtColor(chessFrameR, grayRight, ColorConversion.Bgr2Gray);

                        CvInvoke.DrawChessboardCorners(chessFrameL, patternSize, cornersVecLeft, patternLeftFound);
                        CvInvoke.DrawChessboardCorners(chessFrameR, patternSize, cornersVecRight, patternRightFound);

                        CvInvoke.Imshow("Calibration image left", chessFrameL);
                        CvInvoke.Imshow("Calibration image right", chessFrameR);
                        //chessFrameL.Save(desktop + "\\Left_" + i + ".jpg");
                        //chessFrameR.Save(desktop + "\\Right" + i + ".jpg");

                        CvInvoke.WaitKey(10);

                        imagePoints1[bufferSavepoint] = cornersVecLeft.ToArray();
                        imagePoints2[bufferSavepoint] = cornersVecRight.ToArray();
                        bufferSavepoint++;
                        if (bufferSavepoint == bufferLength)
                        {
                            break;
                        }
                    }
                }
                CvInvoke.DestroyAllWindows();
                //fill the MCvPoint3D32f with correct mesurments
                for (int k = 0; k < bufferLength; k++)
                {
                    //Fill our objects list with the real world mesurments for the intrinsic calculations
                    List <MCvPoint3D32f> object_list = new List <MCvPoint3D32f>();
                    for (int i = 0; i < height; i++)
                    {
                        for (int j = 0; j < width; j++)
                        {
                            object_list.Add(new MCvPoint3D32f(j * 20.0F, i * 20.0F, 0.0F));
                        }
                    }
                    cornersObjectPoints[k] = object_list.ToArray();
                }

                CvInvoke.CalibrateCamera(cornersObjectPoints, imagePoints1, chessFrameL.Size, camMat1, dist1, CalibType.Default, new MCvTermCriteria(200, 1e-5), out rvecs, out tvecs);
                CvInvoke.CalibrateCamera(cornersObjectPoints, imagePoints2, chessFrameL.Size, camMat2, dist2, CalibType.Default, new MCvTermCriteria(200, 1e-5), out rvecs, out tvecs);

                CvInvoke.StereoCalibrate(cornersObjectPoints, imagePoints1, imagePoints2, camMat1, dist1, camMat2, dist2, chessFrameL.Size,
                                         R, T, essential, fundamental, CalibType.FixAspectRatio | CalibType.ZeroTangentDist | CalibType.SameFocalLength | CalibType.RationalModel | CalibType.UseIntrinsicGuess | CalibType.FixK3 | CalibType.FixK4 | CalibType.FixK5, new MCvTermCriteria(100, 1e-5));

                CvInvoke.StereoRectify(camMat1, dist1, camMat2, dist2, chessFrameL.Size, R, T, R1, R2, P1, P2, Q, StereoRectifyType.CalibZeroDisparity, 0,
                                       chessFrameL.Size, ref Rec1, ref Rec2);

                // Create transformation maps
                CvInvoke.InitUndistortRectifyMap(camMat1, dist1, R1, P1, chessFrameL.Size, DepthType.Cv32F, rmapx1, rmapy1);
                CvInvoke.InitUndistortRectifyMap(camMat2, dist2, R2, P2, chessFrameL.Size, DepthType.Cv32F, rmapx2, rmapy2);
                MessageBox.Show("Calibration has ended\n Connect to TELLO access point");
                try
                {
                    FileStorage fs = new FileStorage(calibrationPath.Text + "\\calibMaps.xml", FileStorage.Mode.Write);
                    fs.Write(rmapx1, "rmapx1");
                    fs.Write(rmapy1, "rmapy1");
                    fs.Write(rmapx2, "rmapx2");
                    fs.Write(rmapy2, "rmapy2");
                    fs.Write(Rec1.ToString(), "Rec1");
                    fs.Write(Rec2.ToString(), "Rec2");
                    MessageBox.Show("Transformation maps saved successfully");
                }
                catch (Exception)
                {
                    MessageBox.Show("Error: Problem saving Transformation maps");
                    Environment.Exit(1);
                }
            }
        }
        private static void SampleSensorValues(object State)
        {
            measurementLed.High();
            try
            {
                lock (synchObject)
                {
                    DateTime Now = DateTime.Now;
                    Record   Rec, Rec2;

                    // Read sensors

                    temp  = (short)tmp102.ReadTemperatureRegister();
                    light = adc.ReadRegistersBinary() [0];

                    // Calculate average of last 10 measurements, to get smoother momentary values

                    sumTemp  -= tempAvgWindow [avgPos];
                    sumLight -= lightAvgWindow [avgPos];

                    tempAvgWindow [avgPos]  = temp;
                    lightAvgWindow [avgPos] = light;

                    sumTemp       += temp;
                    sumLight      += light;
                    motionDetected = motion.Value;

                    temperatureC = (sumTemp * 0.1 / 256.0);
                    lightPercent = (100.0 * 0.1 * sumLight) / 0x0fff;
                    avgPos       = (avgPos + 1) % 10;

                    // Update history

                    Rec = new Record(Now, temperatureC, lightPercent, motionDetected);                                  // Rank 0

                    perSecond.Add(Rec);
                    if (perSecond.Count > 1000)
                    {
                        perSecond.RemoveAt(0);
                    }

                    sumSeconds += Rec;
                    nrSeconds++;

                    if (Now.Second == 0)
                    {
                        Rec = sumSeconds / nrSeconds;                                   // Rank 1
                        perMinute.Add(Rec);
                        Rec.SaveNew();

                        if (perMinute.Count > 1000)
                        {
                            Rec2 = perMinute [0];
                            perMinute.RemoveAt(0);
                            Rec2.Delete();
                        }

                        sumMinutes += Rec;
                        nrMinutes++;

                        sumSeconds = null;
                        nrSeconds  = 0;

                        if (Now.Minute == 0)
                        {
                            Rec = sumMinutes / nrMinutes;
                            perHour.Add(Rec);
                            Rec.SaveNew();

                            if (perHour.Count > 1000)
                            {
                                Rec2 = perHour [0];
                                perHour.RemoveAt(0);
                                Rec2.Delete();
                            }

                            sumHours += Rec;
                            nrHours++;

                            sumMinutes = null;
                            nrMinutes  = 0;

                            if (Now.Hour == 0)
                            {
                                Rec = sumHours / nrHours;
                                perDay.Add(Rec);
                                Rec.SaveNew();

                                if (perDay.Count > 1000)
                                {
                                    Rec2 = perDay [0];
                                    perDay.RemoveAt(0);
                                    Rec2.Delete();
                                }

                                sumDays += Rec;
                                nrDays++;

                                sumHours = null;
                                nrHours  = 0;

                                if (Now.Day == 1)
                                {
                                    Rec = sumDays / nrDays;
                                    perMonth.Add(Rec);
                                    Rec.SaveNew();

                                    sumDays = null;
                                    nrDays  = 0;
                                }
                            }
                        }
                    }

                    // Check pending events

                    PendingEvent Event;
                    int          i = 0;
                    int          c = pendingEvents.Count;

                    while (i < c)
                    {
                        Event = pendingEvents [i];

                        if (Event.Trigger(temperatureC, lightPercent, motionDetected))
                        {
                            pendingEvents.RemoveAt(i);
                            c--;

                            HttpGetSensorData(Event.Response, Event.ContentType, Event.ExportModule, new ReadoutRequest(ReadoutType.MomentaryValues));
                            Event.Response.SendResponse();                              // Flags the end of the response, and transmission of all to the recipient.
                        }
                        else
                        {
                            i++;
                        }
                    }
                }

                errorLed.Low();
            } catch (Exception)
            {
                errorLed.High();
            } finally
            {
                measurementLed.Low();
                RemoveOldSessions();
            }
        }