Exemple #1
0
        public void TestORB()
        {
            ORBDetector orb = new ORBDetector(700);

            //String[] parameters = orb.GetParamNames();
            EmguAssert.IsTrue(TestFeature2DTracker(orb, orb), "Unable to find homography matrix");
        }
        public void TestDense()
        {
            DenseFeatureDetector detector  = new DenseFeatureDetector(1.0f, 1, 0.1f, 6, 0, true, false);
            SIFTDetector         extractor = new SIFTDetector();

            EmguAssert.IsTrue(TestFeature2DTracker(detector, extractor), "Unable to find homography matrix");
        }
Exemple #3
0
        public void TestQuaternionsSlerp1()
        {
            Random      r  = new Random();
            Quaternions q1 = new Quaternions();

            q1.AxisAngle = new MCvPoint3D64f(r.NextDouble(), r.NextDouble(), r.NextDouble());
            Quaternions q2 = new Quaternions();

            q2.AxisAngle = new MCvPoint3D64f(r.NextDouble(), r.NextDouble(), r.NextDouble());

            double epsilon = 1.0e-12;

            Quaternions q = q1.Slerp(q2, 0.0);

            EmguAssert.IsTrue(Math.Abs(q1.W - q.W) < epsilon);
            EmguAssert.IsTrue(Math.Abs(q1.X - q.X) < epsilon);
            EmguAssert.IsTrue(Math.Abs(q1.Y - q.Y) < epsilon);
            EmguAssert.IsTrue(Math.Abs(q1.Z - q.Z) < epsilon);

            q = q1.Slerp(q2, 1.0);
            EmguAssert.IsTrue(Math.Abs(q2.W - q.W) < epsilon);
            EmguAssert.IsTrue(Math.Abs(q2.X - q.X) < epsilon);
            EmguAssert.IsTrue(Math.Abs(q2.Y - q.Y) < epsilon);
            EmguAssert.IsTrue(Math.Abs(q2.Z - q.Z) < epsilon);
        }
Exemple #4
0
        public void TestGetRowCol()
        {
            Mat m = new Mat(new Size(2, 2), DepthType.Cv64F, 1);

            double[] value = new double[]
            {
                1, 2,
                3, 4
            };
            m.SetTo(value);

            Mat secondRow = m.Row(1);

            double[] secondRowValue = new double[2];
            secondRow.CopyTo(secondRowValue);
            EmguAssert.IsTrue(value[2] == secondRowValue[0]);
            EmguAssert.IsTrue(value[3] == secondRowValue[1]);

            Mat secondCol = m.Col(1);

            double[] secondColValue = new double[2];
            secondCol.CopyTo(secondColValue);
            EmguAssert.IsTrue(value[1] == secondColValue[0]);
            EmguAssert.IsTrue(value[3] == secondColValue[1]);
        }
Exemple #5
0
        public void TestQuaternion3()
        {
            Random      r  = new Random();
            Quaternions q1 = new Quaternions();

            q1.AxisAngle = new MCvPoint3D64f(r.NextDouble(), r.NextDouble(), r.NextDouble());

            Quaternions q2 = new Quaternions();

            q2.AxisAngle = q1.AxisAngle;

            double epsilon = 1.0e-8;

            EmguAssert.IsTrue(Math.Abs(q1.W - q2.W) < epsilon);
            EmguAssert.IsTrue(Math.Abs(q1.X - q2.X) < epsilon);
            EmguAssert.IsTrue(Math.Abs(q1.Y - q2.Y) < epsilon);
            EmguAssert.IsTrue(Math.Abs(q1.Z - q2.Z) < epsilon);

            RotationVector3D rVec = new RotationVector3D(new double[] { q1.AxisAngle.X, q1.AxisAngle.Y, q1.AxisAngle.Z });
            Mat             m1    = rVec.RotationMatrix;
            Matrix <double> m2    = new Matrix <double>(3, 3);

            q1.GetRotationMatrix(m2);
            Matrix <double> diff = new Matrix <double>(3, 3);

            CvInvoke.AbsDiff(m1, m2, diff);
            double norm = CvInvoke.Norm(diff, Emgu.CV.CvEnum.NormType.C);

            EmguAssert.IsTrue(norm < epsilon);

            Quaternions q4 = q1 * Quaternions.Empty;
            //EmguAssert.IsTrue(q4.Equals(q1));
        }
Exemple #6
0
        public void TestSURF()
        {
            SURF detector = new SURF(500);

            //ParamDef[] parameters = detector.GetParams();
            EmguAssert.IsTrue(TestFeature2DTracker(detector, detector), "Unable to find homography matrix");
        }
Exemple #7
0
        public void TestConvolutionAndLaplace()
        {
            Mat image = new Mat(new Size(300, 400), DepthType.Cv8U, 1);

            CvInvoke.Randu(image, new MCvScalar(0.0), new MCvScalar(255.0));
            Mat laplacian = new Mat();

            CvInvoke.Laplacian(image, laplacian, DepthType.Cv8U);

            float[,] k = { { 0,  1, 0 },
                           { 1, -4, 1 },
                           { 0,  1, 0 } };
            ConvolutionKernelF kernel = new ConvolutionKernelF(k);
            Mat convoluted            = new Mat(image.Size, DepthType.Cv8U, 1);

            CvInvoke.Filter2D(image, convoluted, kernel, kernel.Center);

            Mat absDiff = new Mat();

            CvInvoke.AbsDiff(laplacian, convoluted, absDiff);
            int nonZeroPixelCount = CvInvoke.CountNonZero(absDiff);

            EmguAssert.IsTrue(nonZeroPixelCount == 0);

            //Emgu.CV.UI.ImageViewer.Show(absDiff);
        }
Exemple #8
0
        public void TestLATCH()
        {
            SURF  surf  = new SURF(300);
            LATCH latch = new LATCH();

            EmguAssert.IsTrue(TestFeature2DTracker(surf, latch), "Unable to find homography matrix");
        }
Exemple #9
0
        public void TestDAISY()
        {
            SURF  surf  = new SURF(300);
            DAISY daisy = new DAISY();

            EmguAssert.IsTrue(TestFeature2DTracker(surf, daisy), "Unable to find homography matrix");
        }
Exemple #10
0
        public void TestConcate()
        {
            Matrix <float> mat = new Matrix <float>(30, 40);

            mat.SetRandUniform(new MCvScalar(0), new MCvScalar(255));

            Matrix <float> m1   = mat.GetSubRect(new Rectangle(0, 0, mat.Cols, 20));
            Matrix <float> m2   = mat.GetSubRect(new Rectangle(0, 20, mat.Cols, mat.Rows - 20));
            Matrix <float> mat2 = m1.ConcateVertical(m2);

            EmguAssert.IsTrue(mat.Equals(mat2));

            Matrix <float> m3   = mat.GetSubRect(new Rectangle(0, 0, 10, mat.Rows));
            Matrix <float> m4   = mat.GetSubRect(new Rectangle(10, 0, mat.Cols - 10, mat.Rows));
            Matrix <float> mat3 = m3.ConcateHorizontal(m4);

            EmguAssert.IsTrue(mat.Equals(mat3));

            Matrix <float> m5 = mat.GetRows(0, 5, 1);
            Matrix <float> m6 = mat.GetRows(5, 6, 1);
            Matrix <float> m7 = mat.GetRows(6, mat.Rows, 1);

            EmguAssert.IsTrue(mat.RemoveRows(5, 6).Equals(m5.ConcateVertical(m7)));
            EmguAssert.IsTrue(mat.RemoveRows(0, 1).Equals(mat.GetRows(1, mat.Rows, 1)));
            EmguAssert.IsTrue(mat.RemoveRows(mat.Rows - 1, mat.Rows).Equals(mat.GetRows(0, mat.Rows - 1, 1)));
        }
Exemple #11
0
        public void TestQuaternionsSlerp3()
        {
            Random      r  = new Random();
            Quaternions q1 = new Quaternions();

            q1.AxisAngle = new MCvPoint3D64f(0.0, 30.0 / 180 * Math.PI, 0.0);
            Quaternions q2 = new Quaternions();

            q2.AxisAngle = new MCvPoint3D64f(0.0, 40.0 / 180 * Math.PI, 0.0);

            double epsilon = 1.0e-12;
            double x = 0, y = 0, z = 0;

            Quaternions q = q1.Slerp(q2, 0.5);

            q.GetEuler(ref x, ref y, ref z);
            double deltaDegree = Math.Abs(y / Math.PI * 180.0 - 35.0);

            EmguAssert.IsTrue(deltaDegree <= epsilon);

            q = q1.Slerp(q2, 0.8);
            q.GetEuler(ref x, ref y, ref z);
            deltaDegree = Math.Abs(y / Math.PI * 180.0 - 38.0);
            EmguAssert.IsTrue(deltaDegree <= epsilon);

            q = q1.Slerp(q2, 0.15);
            q.GetEuler(ref x, ref y, ref z);
            deltaDegree = Math.Abs(y / Math.PI * 180.0 - 31.5);
            EmguAssert.IsTrue(deltaDegree <= epsilon);
        }
Exemple #12
0
        public void TestQuaternionsSlerp5()
        {
            Random      r  = new Random();
            Quaternions q1 = new Quaternions();

            q1.AxisAngle = new MCvPoint3D64f(0.0, 355.0 / 180 * Math.PI, 0.0);
            Quaternions q2 = new Quaternions();

            q2.AxisAngle = new MCvPoint3D64f(0.0, 5.0 / 180 * Math.PI, 0.0);

            double epsilon = 1.0e-12;
            double x = 0, y = 0, z = 0;

            Quaternions q = q1.Slerp(q2, 0.5);

            q.GetEuler(ref x, ref y, ref z);
            EmguAssert.IsFalse(double.IsNaN(x));
            EmguAssert.IsFalse(double.IsNaN(y));
            EmguAssert.IsFalse(double.IsNaN(z));
            double deltaDegree = Math.Abs(y / Math.PI * 180.0 - 0.0);

            EmguAssert.IsTrue(deltaDegree <= epsilon);

            q = q2.Slerp(q1, 0.5);
            q.GetEuler(ref x, ref y, ref z);
            EmguAssert.IsFalse(double.IsNaN(x));
            EmguAssert.IsFalse(double.IsNaN(y));
            EmguAssert.IsFalse(double.IsNaN(z));
            deltaDegree = Math.Abs(y / Math.PI * 180.0 - 0.0);
            EmguAssert.IsTrue(deltaDegree <= epsilon);
        }
Exemple #13
0
        public void TestBOWKmeansTrainer()
        {
            Image <Gray, byte> box      = EmguAssert.LoadImage <Gray, byte>("box.png");
            Feature2D          detector = new KAZE();
            VectorOfKeyPoint   kpts     = new VectorOfKeyPoint();
            Mat descriptors             = new Mat();

            detector.DetectAndCompute(box, null, kpts, descriptors, false);

            BOWKMeansTrainer trainer = new BOWKMeansTrainer(100, new MCvTermCriteria(), 3, CvEnum.KMeansInitType.PPCenters);

            trainer.Add(descriptors);
            Mat vocabulary = new Mat();

            trainer.Cluster(vocabulary);

            BFMatcher matcher = new BFMatcher(DistanceType.L2);

            BOWImgDescriptorExtractor extractor = new BOWImgDescriptorExtractor(detector, matcher);

            extractor.SetVocabulary(vocabulary);

            Mat descriptors2 = new Mat();

            extractor.Compute(box, kpts, descriptors2);
        }
Exemple #14
0
        public void TestAkaze()
        {
            AKAZE detector = new AKAZE();

            //ParamDef[] parameters = detector.GetParams();
            EmguAssert.IsTrue(TestFeature2DTracker(detector, detector), "Unable to find homography matrix");
        }
Exemple #15
0
        public void TestQuaternionEulerAngleAndRotate()
        {
            double      epsilon = 1.0e-12;
            Random      r = new Random();
            Quaternions q1 = new Quaternions();
            double      roll1 = r.NextDouble(), pitch1 = r.NextDouble(), yaw1 = r.NextDouble();
            double      roll2 = 0, pitch2 = 0, yaw2 = 0;

            q1.SetEuler(roll1, pitch1, yaw1);
            q1.GetEuler(ref roll2, ref pitch2, ref yaw2);
            EmguAssert.IsTrue(Math.Abs(roll1 - roll2) < epsilon);
            EmguAssert.IsTrue(Math.Abs(pitch1 - pitch2) < epsilon);
            EmguAssert.IsTrue(Math.Abs(yaw1 - yaw2) < epsilon);

            Quaternions q2 = new Quaternions();

            q2.SetEuler(r.NextDouble(), r.NextDouble(), r.NextDouble());

            MCvPoint3D64f p = new MCvPoint3D64f(r.NextDouble() * 10, r.NextDouble() * 10, r.NextDouble() * 10);

            MCvPoint3D64f delta = (q1 * q2).RotatePoint(p) - q1.RotatePoint(q2.RotatePoint(p));

            EmguAssert.IsTrue(delta.X < epsilon);
            EmguAssert.IsTrue(delta.Y < epsilon);
            EmguAssert.IsTrue(delta.Z < epsilon);
        }
Exemple #16
0
        public void TestBOWKmeansTrainer2()
        {
            Image <Gray, byte> box    = EmguAssert.LoadImage <Gray, byte>("box.png");
            Brisk            detector = new Brisk(30, 3, 1.0f);
            VectorOfKeyPoint kpts     = new VectorOfKeyPoint();
            Mat descriptors           = new Mat();

            detector.DetectAndCompute(box, null, kpts, descriptors, false);
            Mat descriptorsF = new Mat();

            descriptors.ConvertTo(descriptorsF, CvEnum.DepthType.Cv32F);
            //Matrix<float> descriptorsF = descriptors.Convert<float>();
            BOWKMeansTrainer trainer = new BOWKMeansTrainer(100, new MCvTermCriteria(), 3, CvEnum.KMeansInitType.PPCenters);

            trainer.Add(descriptorsF);
            Mat vocabulary = new Mat();

            trainer.Cluster(vocabulary);

            BFMatcher matcher = new BFMatcher(DistanceType.L2);

            BOWImgDescriptorExtractor extractor = new BOWImgDescriptorExtractor(detector, matcher);
            Mat vocabularyByte = new Mat();

            vocabulary.ConvertTo(vocabularyByte, CvEnum.DepthType.Cv8U);
            extractor.SetVocabulary(vocabularyByte);

            Mat descriptors2 = new Mat();

            extractor.Compute(box, kpts, descriptors2);
        }
Exemple #17
0
        public void TestData()
        {
            Byte[,] data = new Byte[20, 30];
            Random r = new Random();

            Byte[] bytes = new Byte[data.Length];
            r.NextBytes(bytes);
            for (int i = 0; i < data.GetLength(0); i++)
            {
                for (int j = 0; j < data.GetLength(1); j++)
                {
                    data[i, j] = bytes[i * data.GetLength(1) + j];
                }
            }

            Matrix <Byte> m = new Matrix <byte>(data);

            Byte[,] data2 = m.Data;

            for (int i = 0; i < data.GetLength(0); i++)
            {
                for (int j = 0; j < data.GetLength(1); j++)
                {
                    EmguAssert.AreEqual(data[i, j], data2[i, j]);
                    EmguAssert.AreEqual(data[i, j], m[i, j]);
                }
            }
        }
Exemple #18
0
        public void TestCudaUploadDownload()
        {
            if (!CudaInvoke.HasCuda)
            {
                return;
            }

            Mat m = new Mat(new Size(480, 320), DepthType.Cv8U, 3);

            CvInvoke.Randu(m, new MCvScalar(), new MCvScalar(255, 255, 255));

            #region test for async download & upload
            Stream stream = new Stream();
            GpuMat gm1    = new GpuMat();
            gm1.Upload(m, stream);

            Mat m2 = new Mat();
            gm1.Download(m2, stream);

            stream.WaitForCompletion();
            EmguAssert.IsTrue(m.Equals(m2));
            #endregion

            #region test for blocking download & upload
            GpuMat gm2 = new GpuMat();
            gm2.Upload(m);
            Mat m3 = new Mat();
            gm2.Download(m3);
            EmguAssert.IsTrue(m.Equals(m3));
            #endregion
        }
Exemple #19
0
        public void TestChessboardCalibration()
        {
            Size patternSize = new Size(9, 6);

            Image <Gray, Byte> chessboardImage = EmguAssert.LoadImage <Gray, byte>("left01.jpg");

            Util.VectorOfPointF corners = new Util.VectorOfPointF();
            bool patternWasFound        = CvInvoke.FindChessboardCorners(chessboardImage, patternSize, corners);

            chessboardImage.FindCornerSubPix(
                new PointF[][] { corners.ToArray() },
                new Size(10, 10),
                new Size(-1, -1),
                new MCvTermCriteria(0.05));

            MCvPoint3D32f[]           objectPts = CalcChessboardCorners(patternSize, 1.0f);
            IntrinsicCameraParameters intrisic  = new IntrinsicCameraParameters(8);

            ExtrinsicCameraParameters[] extrinsic;
            double error = CameraCalibration.CalibrateCamera(new MCvPoint3D32f[][] { objectPts }, new PointF[][] { corners.ToArray() },
                                                             chessboardImage.Size, intrisic, CvEnum.CalibType.Default, new MCvTermCriteria(30, 1.0e-10), out extrinsic);

            CvInvoke.DrawChessboardCorners(chessboardImage, patternSize, corners, patternWasFound);
            //CameraCalibration.DrawChessboardCorners(chessboardImage, patternSize, corners);
            Image <Gray, Byte> undistorted = intrisic.Undistort(chessboardImage);
            //UI.ImageViewer.Show(undistorted, String.Format("Reprojection error: {0}", error));
        }
Exemple #20
0
        public void TestSimpleBlobDetector()
        {
            Mat box = EmguAssert.LoadMat("box.png");
            SimpleBlobDetectorParams p        = new SimpleBlobDetectorParams();
            SimpleBlobDetector       detector = new SimpleBlobDetector(p);

            MKeyPoint[] keypoints = detector.Detect(box);
        }
Exemple #21
0
        public void TestQuaternionsSize()
        {
#if NETFX_CORE
            EmguAssert.AreEqual(4 * Marshal.SizeOf <double>(), Marshal.SizeOf <Quaternions>());
#else
            EmguAssert.AreEqual(4 * Marshal.SizeOf(typeof(double)), Marshal.SizeOf(typeof(Quaternions)));
#endif
        }
Exemple #22
0
        public void TestOclKernel()
        {
            if (CvInvoke.HaveOpenCL && CvInvoke.UseOpenCL)
            {
                Ocl.Device defaultDevice = Ocl.Device.Default;

                Mat img     = EmguAssert.LoadMat("lena.jpg");
                Mat imgGray = new Mat();
                CvInvoke.CvtColor(img, imgGray, ColorConversion.Bgr2Gray);
                Mat imgFloat = new Mat();
                imgGray.ConvertTo(imgFloat, DepthType.Cv32F, 1.0 / 255);
                UMat umat    = imgFloat.GetUMat(AccessType.Read, UMat.Usage.AllocateDeviceMemory);
                UMat umatDst = new UMat();
                umatDst.Create(umat.Rows, umat.Cols, DepthType.Cv32F, umat.NumberOfChannels, UMat.Usage.AllocateDeviceMemory);

                String buildOpts = String.Format("-D dstT={0}", Ocl.OclInvoke.TypeToString(umat.Depth));

                String sourceStr = @"
__constant sampler_t samplerLN = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_LINEAR;
__kernel void shift(const image2d_t src, float shift_x, float shift_y, __global uchar* dst, int dst_step, int dst_offset, int dst_rows, int dst_cols)
{
   int x = get_global_id(0);
   int y = get_global_id(1);
   if (x >= dst_cols) return;
   int dst_index = mad24(y, dst_step, mad24(x, (int)sizeof(dstT), dst_offset));
   __global dstT *dstf = (__global dstT *)(dst + dst_index);
   float2 coord = (float2)((float)x+0.5f+shift_x, (float)y+0.5f+shift_y);
   dstf[0] = (dstT)read_imagef(src, samplerLN, coord).x;
}";

                using (CvString errorMsg = new CvString())
                    using (Ocl.ProgramSource ps = new Ocl.ProgramSource(sourceStr))
                        using (Ocl.Kernel kernel = new Ocl.Kernel())
                            using (Ocl.Image2D image2d = new Ocl.Image2D(umat))
                                using (Ocl.KernelArg ka = new Ocl.KernelArg(Ocl.KernelArg.Flags.ReadWrite, umatDst))
                                {
                                    float shiftX = 100.5f;
                                    float shiftY = -50.0f;

                                    bool success = kernel.Create("shift", ps, buildOpts, errorMsg);
                                    EmguAssert.IsTrue(success, errorMsg.ToString());
                                    int idx = 0;
                                    idx = kernel.Set(idx, image2d);
                                    idx = kernel.Set(idx, ref shiftX);
                                    idx = kernel.Set(idx, ref shiftY);
                                    idx = kernel.Set(idx, ka);
                                    IntPtr[] globalThreads = new IntPtr[] { new IntPtr(umat.Cols), new IntPtr(umat.Rows), new IntPtr(1) };
                                    success = kernel.Run(globalThreads, null, true);
                                    EmguAssert.IsTrue(success, "Failed to run the kernel");
                                    using (Mat matDst = umatDst.GetMat(AccessType.Read))
                                        using (Mat saveMat = new Mat())
                                        {
                                            matDst.ConvertTo(saveMat, DepthType.Cv8U, 255.0);
                                            saveMat.Save("tmp.jpg");
                                        }
                                }
            }
        }
Exemple #23
0
        public void TestFAST()
        {
            FastDetector fast = new FastDetector(10, true);
            //GridAdaptedFeatureDetector fastGrid = new GridAdaptedFeatureDetector(fast, 2000, 4, 4);
            BriefDescriptorExtractor brief = new BriefDescriptorExtractor(32);

            //ParamDef[] parameters = fastGrid.GetParams();
            EmguAssert.IsTrue(TestFeature2DTracker(fast, brief), "Unable to find homography matrix");
        }
Exemple #24
0
        public void TestFreak()
        {
            FastDetector fast  = new FastDetector(10, true);
            Freak        freak = new Freak(true, true, 22.0f, 4);

            //ParamDef[] parameters = freak.GetParams();
            //int nOctaves = freak.GetInt("nbOctave");
            EmguAssert.IsTrue(TestFeature2DTracker(fast, freak), "Unable to find homography matrix");
        }
Exemple #25
0
        public void TestArrToMat()
        {
            Matrix <float> m   = new Matrix <float>(320, 240);
            Mat            mat = new Mat();

            m.Mat.CopyTo(mat);
            EmguAssert.IsTrue(m.Mat.Depth == DepthType.Cv32F);
            EmguAssert.IsTrue(mat.Depth == DepthType.Cv32F);
        }
Exemple #26
0
        public void TestChessboardCalibration()
        {
            Size patternSize = new Size(9, 6);

            Image <Gray, Byte> chessboardImage = EmguAssert.LoadImage <Gray, byte>("left01.jpg");

            Util.VectorOfPointF corners = new Util.VectorOfPointF();
            bool patternWasFound        = CvInvoke.FindChessboardCorners(chessboardImage, patternSize, corners);

            chessboardImage.FindCornerSubPix(
                new PointF[][] { corners.ToArray() },
                new Size(10, 10),
                new Size(-1, -1),
                new MCvTermCriteria(0.05));

            MCvPoint3D32f[] objectPts = CalcChessboardCorners(patternSize, 1.0f);

            using (VectorOfVectorOfPoint3D32F ptsVec = new VectorOfVectorOfPoint3D32F(new MCvPoint3D32f[][] { objectPts }))
                using (VectorOfVectorOfPointF imgPtsVec = new VectorOfVectorOfPointF(corners))
                    using (Mat cameraMatrix = new Mat())
                        using (Mat distortionCoeff = new Mat())
                            using (VectorOfMat rotations = new VectorOfMat())
                                using (VectorOfMat translations = new VectorOfMat())
                                {
                                    Mat             calMat  = CvInvoke.InitCameraMatrix2D(ptsVec, imgPtsVec, chessboardImage.Size, 0);
                                    Matrix <double> calMatF = new Matrix <double>(calMat.Rows, calMat.Cols, calMat.NumberOfChannels);
                                    calMat.CopyTo(calMatF);
                                    double error = CvInvoke.CalibrateCamera(ptsVec, imgPtsVec, chessboardImage.Size, cameraMatrix,
                                                                            distortionCoeff,
                                                                            rotations, translations, CalibType.Default, new MCvTermCriteria(30, 1.0e-10));
                                    using (Mat rotation = new Mat())
                                        using (Mat translation = new Mat())
                                            using (VectorOfPoint3D32F vpObject = new VectorOfPoint3D32F(objectPts))
                                            {
                                                CvInvoke.SolvePnPRansac(
                                                    vpObject,
                                                    corners,
                                                    cameraMatrix,
                                                    distortionCoeff,
                                                    rotation,
                                                    translation,
                                                    true);
                                            }

                                    CvInvoke.DrawChessboardCorners(chessboardImage, patternSize, corners, patternWasFound);
                                    using (Mat undistorted = new Mat())
                                    {
                                        CvInvoke.Undistort(chessboardImage, undistorted, cameraMatrix, distortionCoeff);
                                        String title = String.Format("Reprojection error: {0}", error);
                                        //CvInvoke.NamedWindow(title);
                                        //CvInvoke.Imshow(title, undistorted);
                                        //CvInvoke.WaitKey();
                                        //UI.ImageViewer.Show(undistorted, String.Format("Reprojection error: {0}", error));
                                    }
                                }
        }
Exemple #27
0
        public async Task TestPedestrianDetector()
        {
            using (Mat m = EmguAssert.LoadMat("pedestrian"))
                using (Emgu.CV.Models.PedestrianDetector detector = new PedestrianDetector())
                {
                    await detector.Init(DownloadManager_OnDownloadProgressChanged);

                    String text = detector.ProcessAndRender(m, m);
                }
        }
Exemple #28
0
        public async Task TestWeChatQRCode()
        {
            using (Mat m = EmguAssert.LoadMat("link_github_ocv.jpg"))
                using (Emgu.CV.Models.WeChatQRCodeDetector detector = new WeChatQRCodeDetector())
                {
                    await detector.Init(DownloadManager_OnDownloadProgressChanged);

                    String text = detector.ProcessAndRender(m, m);
                }
        }
Exemple #29
0
        public void TestQuaternions1()
        {
            Quaternions q       = new Quaternions();
            double      epsilon = 1.0e-10;

            Matrix <double> point = new Matrix <double>(3, 1);

            point.SetRandNormal(new MCvScalar(), new MCvScalar(20));
            using (Matrix <double> pt1 = new Matrix <double>(3, 1))
                using (Matrix <double> pt2 = new Matrix <double>(3, 1))
                    using (Matrix <double> pt3 = new Matrix <double>(3, 1))
                    {
                        double x1 = 1.0, y1 = 0.2, z1 = 0.1;
                        double x2 = 0.0, y2 = 0.0, z2 = 0.0;

                        q.SetEuler(x1, y1, z1);
                        q.GetEuler(ref x2, ref y2, ref z2);

                        EmguAssert.IsTrue(
                            Math.Abs(x2 - x1) < epsilon &&
                            Math.Abs(y2 - y1) < epsilon &&
                            Math.Abs(z2 - z1) < epsilon);

                        q.RotatePoints(point, pt1);

                        Matrix <double> rMat = new Matrix <double>(3, 3);
                        q.GetRotationMatrix(rMat);
                        CvInvoke.Gemm(rMat, point, 1.0, null, 0.0, pt2, Emgu.CV.CvEnum.GemmType.Default);

                        CvInvoke.AbsDiff(pt1, pt2, pt3);

                        EmguAssert.IsTrue(
                            pt3[0, 0] < epsilon &&
                            pt3[1, 0] < epsilon &&
                            pt3[2, 0] < epsilon);
                    }

            double rotationAngle = 0.2;

            q.SetEuler(rotationAngle, 0.0, 0.0);
            EmguAssert.IsTrue(Math.Abs(q.RotationAngle - rotationAngle) < epsilon);
            q.SetEuler(0.0, rotationAngle, 0.0);
            EmguAssert.IsTrue(Math.Abs(q.RotationAngle - rotationAngle) < epsilon);
            q.SetEuler(0.0, 0.0, rotationAngle);
            EmguAssert.IsTrue(Math.Abs(q.RotationAngle - rotationAngle) < epsilon);

            q = q * q;
            EmguAssert.IsTrue(Math.Abs(q.RotationAngle / 2.0 - rotationAngle) < epsilon);

            q.SetEuler(0.2, 0.1, 0.05);
            double t = q.RotationAngle;

            q = q * q;
            EmguAssert.IsTrue(Math.Abs(q.RotationAngle / 2.0 - t) < epsilon);
        }
Exemple #30
0
        public void TestOclPyr()
        {
            if (!CvInvoke.HaveOpenCL)
            {
                return;
            }

            Image <Gray, Byte> img = new Image <Gray, byte>(640, 480);

            //add some randome noise to the image
            img.SetRandUniform(new MCvScalar(), new MCvScalar(255, 255, 255));
            Image <Gray, Byte> down = img.PyrDown();

            //Emgu.CV.UI.ImageViewer.Show(down);

            Image <Gray, Byte> up = down.PyrUp();

            UMat gImg  = img.ToUMat();
            UMat gDown = new UMat();
            UMat gUp   = new UMat();

            CvInvoke.PyrDown(gImg, gDown);
            CvInvoke.PyrUp(gDown, gUp);

            CvInvoke.AbsDiff(down, gDown.ToImage <Gray, Byte>(), down);
            CvInvoke.AbsDiff(up, gUp.ToImage <Gray, Byte>(), up);
            double[] minVals, maxVals;
            Point[]  minLocs, maxLocs;
            down.MinMax(out minVals, out maxVals, out minLocs, out maxLocs);
            double maxVal = 0.0;

            for (int i = 0; i < maxVals.Length; i++)
            {
                if (maxVals[i] > maxVal)
                {
                    maxVal = maxVals[i];
                }
            }
            Trace.WriteLine(String.Format("Max diff: {0}", maxVal));
            EmguAssert.IsTrue(maxVal <= 1.0);
            //Assert.LessOrEqual(maxVal, 1.0);

            up.MinMax(out minVals, out maxVals, out minLocs, out maxLocs);
            maxVal = 0.0;
            for (int i = 0; i < maxVals.Length; i++)
            {
                if (maxVals[i] > maxVal)
                {
                    maxVal = maxVals[i];
                }
            }
            Trace.WriteLine(String.Format("Max diff: {0}", maxVal));
            EmguAssert.IsTrue(maxVal <= 1.0);
            //Assert.LessOrEqual(maxVal, 1.0);
        }