コード例 #1
0
ファイル: Undistort.cs プロジェクト: cleoag/opencvsharp
        public Undistort()
        {
            // cvUndistort2
            // キャリブレーションデータを利用して,歪みを補正する

            // (1)補正対象となる画像の読み込み
            using (IplImage srcImg = new IplImage(Const.ImageDistortion, LoadMode.Color))
                using (IplImage dstImg = srcImg.Clone())
                {
                    // (2)パラメータファイルの読み込み
                    CvMat intrinsic, distortion;
                    using (CvFileStorage fs = new CvFileStorage(Const.XmlCamera, null, FileStorageMode.Read))
                    {
                        CvFileNode param = fs.GetFileNodeByName(null, "intrinsic");
                        intrinsic  = fs.Read <CvMat>(param);
                        param      = fs.GetFileNodeByName(null, "distortion");
                        distortion = fs.Read <CvMat>(param);
                    }

                    // (3)歪み補正
                    Cv.Undistort2(srcImg, dstImg, intrinsic, distortion);

                    // (4)画像を表示,キーが押されたときに終了
                    using (CvWindow w1 = new CvWindow("Distortion", WindowMode.AutoSize, srcImg))
                        using (CvWindow w2 = new CvWindow("Undistortion", WindowMode.AutoSize, dstImg))
                        {
                            CvWindow.WaitKey(0);
                        }

                    intrinsic.Dispose();
                    distortion.Dispose();
                }
        }
コード例 #2
0
        /// <summary>
        /// Returns pointer to the underlying C FileStorage structure
        /// </summary>
        /// <returns></returns>
        public CvFileNode ToLegacy()
        {
            IntPtr p   = NativeMethods.core_FileNode_toLegacy(ptr);
            var    ret = new CvFileNode(p);

            return(ret);
        }
コード例 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="fileName"></param>
        private static void SampleFileStorageReadSeq(string fileName)
        {
            // cvGetHashedKey, cvGetFileNode

            using (CvFileStorage fs = new CvFileStorage("sequence.yml", null, FileStorageMode.Read))
            {
                CvStringHashNode xKey   = fs.GetHashedKey("x", true);
                CvStringHashNode yKey   = fs.GetHashedKey("y", true);
                CvFileNode       points = fs.GetFileNodeByName(null, "points");

                if ((points.Tag & NodeType.Seq) != 0)
                {
                    CvSeq       seq    = points.DataSeq;
                    int         total  = seq.Total;
                    CvSeqReader reader = new CvSeqReader();
                    seq.StartRead(reader, false);
                    for (int i = 0; i < total; i++)
                    {
                        CvFileNode pt = CvFileNode.FromPtr(reader.Ptr);
                        int        x  = fs.ReadIntByName(pt, "x", 0);
                        int        y  = fs.ReadIntByName(pt, "y", 0);

                        Cv.NEXT_SEQ_ELEM(seq.ElemSize, reader);
                        Console.WriteLine("{0}: ({1}, {2})", i, x, y);
                    }
                }
            }
            Console.ReadKey();
        }
コード例 #4
0
        public Undistort()
        {
            using (IplImage srcImg = new IplImage(FilePath.Image.Distortion, LoadMode.Color))
                using (IplImage dstImg = srcImg.Clone())
                {
                    CvMat intrinsic, distortion;
                    using (CvFileStorage fs = new CvFileStorage(FilePath.Text.Camera, null, FileStorageMode.Read))
                    {
                        CvFileNode param = fs.GetFileNodeByName(null, "intrinsic");
                        intrinsic  = fs.Read <CvMat>(param);
                        param      = fs.GetFileNodeByName(null, "distortion");
                        distortion = fs.Read <CvMat>(param);
                    }

                    Cv.Undistort2(srcImg, dstImg, intrinsic, distortion);

                    using (new CvWindow("Distortion", WindowMode.AutoSize, srcImg))
                        using (new CvWindow("Undistortion", WindowMode.AutoSize, dstImg))
                        {
                            CvWindow.WaitKey(0);
                        }

                    intrinsic.Dispose();
                    distortion.Dispose();
                }
        }
コード例 #5
0
ファイル: FileNode.cs プロジェクト: 0sv/opencvsharp
 /// <summary>
 /// The full constructor wrapping CvFileNode structure.
 /// </summary>
 /// <param name="fs"></param>
 /// <param name="node"></param>
 public FileNode(CvFileStorage fs, CvFileNode node)
 {
     if (fs == null)
         throw new ArgumentNullException("fs");
     if (node == null)
         throw new ArgumentNullException("node");
     NativeMethods.core_FileNode_new2(fs.CvPtr, node.CvPtr);
 }
コード例 #6
0
 /// <summary>
 /// The full constructor wrapping CvFileNode structure.
 /// </summary>
 /// <param name="fs"></param>
 /// <param name="node"></param>
 public FileNode(CvFileStorage fs, CvFileNode node)
 {
     if (fs == null)
     {
         throw new ArgumentNullException(nameof(fs));
     }
     if (node == null)
     {
         throw new ArgumentNullException(nameof(node));
     }
     NativeMethods.core_FileNode_new2(fs.CvPtr, node.CvPtr);
 }
コード例 #7
0
ファイル: CvRTrees.cs プロジェクト: inohiroki/opencvsharp
        /// <summary>
        /// ファイルストレージからモデルを読み込む
        /// </summary>
        /// <param name="fs"></param>
        /// <param name="node"></param>
#else
        /// <summary>
        /// Reads the model from file storage
        /// </summary>
        /// <param name="fs"></param>
        /// <param name="node"></param>
#endif
        public override void Read(CvFileStorage fs, CvFileNode node)
        {
            if (fs == null)
            {
                throw new ArgumentNullException("fs");
            }
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }
            NativeMethods.ml_CvRTrees_read(ptr, fs.CvPtr, node.CvPtr);
        }
コード例 #8
0
ファイル: CvBoost.cs プロジェクト: simonmssu/opencvsharp
        /// <summary>
        /// ファイルストレージからモデルを読み込む
        /// </summary>
        /// <param name="storage"></param>
        /// <param name="node"></param>
#else
        /// <summary>
        /// Reads the model from file storage
        /// </summary>
        /// <param name="storage"></param>
        /// <param name="node"></param>
#endif
        public override void Read(CvFileStorage storage, CvFileNode node)
        {
            if (storage == null)
            {
                throw new ArgumentNullException("storage");
            }
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            NativeMethods.ml_CvBoost_read(ptr, storage.CvPtr, node.CvPtr);
        }
コード例 #9
0
        /// <summary>
        /// ファイルストレージからモデルを読み込む
        /// </summary>
        /// <param name="storage"></param>
        /// <param name="node"></param>
#else
        /// <summary>
        /// Reads the model from file storage
        /// </summary>
        /// <param name="storage"></param>
        /// <param name="node"></param>
#endif
        public override void Read(CvFileStorage storage, CvFileNode node)
        {
            if (storage == null)
            {
                throw new ArgumentNullException(nameof(storage));
            }
            if (node == null)
            {
                throw new ArgumentNullException(nameof(node));
            }

            NativeMethods.ml_CvNormalBayesClassifier_read(ptr, storage.CvPtr, node.CvPtr);
        }
コード例 #10
0
ファイル: CvANN_MLP.cs プロジェクト: shimat/opencvsharp_2410
        /// <summary>
        /// ファイルストレージからモデルを読み込む
        /// </summary>
        /// <param name="fs"></param>
        /// <param name="node"></param>
#else
        /// <summary>
        /// Reads the model from file storage
        /// </summary>
        /// <param name="fs"></param>
        /// <param name="node"></param>
#endif
        public override void Read(CvFileStorage fs, CvFileNode node)
        {
            if (fs == null)
            {
                throw new ArgumentNullException(nameof(fs));
            }
            if (node == null)
            {
                throw new ArgumentNullException(nameof(node));
            }

            NativeMethods.ml_CvANN_MLP_read(ptr, fs.CvPtr, node.CvPtr);
        }
コード例 #11
0
ファイル: CvStatModel.cs プロジェクト: simonmssu/opencvsharp
        /// <summary>
        /// ファイルストレージからモデルを読み込む
        /// </summary>
        /// <param name="storage"></param>
        /// <param name="node"></param>
#else
        /// <summary>
        /// Reads the model from file storage
        /// </summary>
        /// <param name="storage"></param>
        /// <param name="node"></param>
#endif
        public virtual void Read(CvFileStorage storage, CvFileNode node)
        {
            if (disposed)
            {
                throw new ObjectDisposedException("CvStatModel");
            }
            if (storage == null)
            {
                throw new ArgumentNullException("storage");
            }
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }
            NativeMethods.ml_CvStatModel_read(ptr, storage.CvPtr, node.CvPtr);
        }
コード例 #12
0
ファイル: CvDTree.cs プロジェクト: shimat/opencvsharp_2410
        /// <summary>
        /// ファイルストレージからモデルを読み込む
        /// </summary>
        /// <param name="fs"></param>
        /// <param name="node"></param>
        /// <param name="data"></param>
#else
        /// <summary>
        /// Reads the model from file storage
        /// </summary>
        /// <param name="fs"></param>
        /// <param name="node"></param>
        /// <param name="data"></param>
#endif
        public virtual void Read(CvFileStorage fs, CvFileNode node, CvDTreeTrainData data)
        {
            if (fs == null)
            {
                throw new ArgumentNullException(nameof(fs));
            }
            if (node == null)
            {
                throw new ArgumentNullException(nameof(node));
            }
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            NativeMethods.ml_CvDTree_read(ptr, fs.CvPtr, node.CvPtr, data.CvPtr);
        }
コード例 #13
0
ファイル: CvForestTree.cs プロジェクト: inohiroki/opencvsharp
        /// <summary>
        ///
        /// </summary>
        /// <param name="fs"></param>
        /// <param name="node"></param>
        /// <param name="forest"></param>
        /// <param name="data"></param>
#else
        /// <summary>
        ///
        /// </summary>
        /// <param name="fs"></param>
        /// <param name="node"></param>
        /// <param name="forest"></param>
        /// <param name="data"></param>
#endif
        public virtual void Read(CvFileStorage fs, CvFileNode node, CvRTrees forest, CvDTreeTrainData data)
        {
            if (fs == null)
            {
                throw new ArgumentNullException("fs");
            }
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }
            if (forest == null)
            {
                throw new ArgumentNullException("forest");
            }
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            NativeMethods.ml_CvForestTree_read(
                ptr, fs.CvPtr, node.CvPtr, forest.CvPtr, data.CvPtr);
        }
コード例 #14
0
ファイル: CvBoostTree.cs プロジェクト: cleoag/opencvsharp
        /// <summary>
        ///
        /// </summary>
        /// <param name="fs"></param>
        /// <param name="node"></param>
        /// <param name="ensemble"></param>
        /// <param name="data"></param>
#else
        /// <summary>
        ///
        /// </summary>
        /// <param name="fs"></param>
        /// <param name="node"></param>
        /// <param name="ensemble"></param>
        /// <param name="data"></param>
#endif
        public virtual void Read(CvFileStorage fs, CvFileNode node, CvBoost ensemble, CvDTreeTrainData data)
        {
            if (fs == null)
            {
                throw new ArgumentNullException("fs");
            }
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }
            if (ensemble == null)
            {
                throw new ArgumentNullException("ensemble");
            }
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            NativeMethods.ml_CvBoostTree_read(
                ptr, fs.CvPtr, node.CvPtr, ensemble.CvPtr, data.CvPtr);
        }
コード例 #15
0
ファイル: CvBoostTree.cs プロジェクト: 0sv/opencvsharp
        /// <summary>
        /// 
        /// </summary>
        /// <param name="fs"></param>		
        /// <param name="node"></param>
		/// <param name="ensemble"></param>
		/// <param name="data"></param>
#else
		/// <summary>
        /// 
        /// </summary>
        /// <param name="fs"></param>		
        /// <param name="node"></param>
		/// <param name="ensemble"></param>
		/// <param name="data"></param>
#endif
		public virtual void Read(CvFileStorage fs, CvFileNode node, CvBoost ensemble, CvDTreeTrainData data)
        {
			if (fs == null)
                throw new ArgumentNullException("fs");
            if (node == null)
                throw new ArgumentNullException("node");
			if (ensemble == null)
                throw new ArgumentNullException("ensemble");
			if (data == null)
                throw new ArgumentNullException("data");

            NativeMethods.ml_CvBoostTree_read(
                ptr, fs.CvPtr, node.CvPtr, ensemble.CvPtr, data.CvPtr);
        }
コード例 #16
0
ファイル: CvSVM.cs プロジェクト: neoxeo/opencvsharp
        /// <summary>
        /// ファイルストレージからモデルを読み込む
        /// </summary>
        /// <param name="storage"></param>
        /// <param name="node"></param>
#else
		/// <summary>
        /// Reads the model from file storage
        /// </summary>
        /// <param name="storage"></param>
        /// <param name="node"></param>
#endif
		public override void Read(CvFileStorage storage, CvFileNode node) 
        {
            if (storage == null)
                throw new ArgumentNullException("storage");
            if (node == null)
                throw new ArgumentNullException("node");

            MLInvoke.CvSVM_read(ptr, storage.CvPtr, node.CvPtr);
        }
コード例 #17
0
ファイル: CvStatModel.cs プロジェクト: MJunak/opencvsharp
        /// <summary>
        /// ファイルストレージからモデルを読み込む
        /// </summary>
        /// <param name="storage"></param>
        /// <param name="node"></param>
#else
		/// <summary>
        /// Reads the model from file storage
        /// </summary>
        /// <param name="storage"></param>
        /// <param name="node"></param>
#endif
        public virtual void Read(CvFileStorage storage, CvFileNode node)
        {
            // OPENCV_ERROR( CV_StsNotImplemented, "CvStatModel::read", "" );
            throw new NotImplementedException();
        }
コード例 #18
0
ファイル: CvRTrees.cs プロジェクト: neoxeo/opencvsharp
        /// <summary>
        /// ファイルストレージからモデルを読み込む
        /// </summary>
        /// <param name="fs"></param>
        /// <param name="node"></param>
#else
		/// <summary>
        /// Reads the model from file storage
        /// </summary>
        /// <param name="fs"></param>
        /// <param name="node"></param>
#endif
		public override void Read(CvFileStorage fs, CvFileNode node) 
        {
            if (fs == null)
                throw new ArgumentNullException("fs");
            if (node == null)
                throw new ArgumentNullException("node");
            MLInvoke.CvRTrees_read(ptr, fs.CvPtr, node.CvPtr);
        }
コード例 #19
0
        /// <summary>
        /// マップのシーケンスのファイルストレージからの読み込み
        /// </summary>
        /// <param name="fileName">書きこむXML or YAMLファイル</param>
        private static void SampleFileStorageReadSeq(string fileName)
        {
            // cvGetHashedKey, cvGetFileNode
            // 二つのエントリを持つマップのシーケンスをファイルから読み込む

            // (1)ファイルストレージのオープン,ハッシュドキーの計算,シーケンスノードの取得
            using (CvFileStorage fs = new CvFileStorage("sequence.yml", null, FileStorageMode.Read))
            {
                CvStringHashNode xKey   = fs.GetHashedKey("x", true);
                CvStringHashNode yKey   = fs.GetHashedKey("y", true);
                CvFileNode       points = fs.GetFileNodeByName(null, "points");
                // (2)シーケンスリーダを初期化,各ノードを順次取得
                if ((points.Tag & NodeType.Seq) != 0)
                {
                    CvSeq       seq    = points.DataSeq;
                    int         total  = seq.Total;
                    CvSeqReader reader = new CvSeqReader();
                    seq.StartRead(reader, false);
                    for (int i = 0; i < total; i++)
                    {
                        CvFileNode pt = CvFileNode.FromPtr(reader.Ptr);
                        // (3)高速バージョン

                        /*
                         * CvFileNode xnode = fs.GetFileNode(pt, x_key, false);
                         * CvFileNode ynode = fs.GetFileNode(pt, y_key, false);
                         * Debug.Assert(
                         *  xnode != null &&
                         *  (xnode.Tag & NodeType.Integer) != 0 &&
                         *  ynode != null &&
                         *  (ynode.Tag & NodeType.Integer) != 0
                         * );
                         * int x = xnode.DataI;
                         * int i = ynode.DataI;
                         * //*/
                        // (4)低速バージョン.x_keyとy_keyを使わない

                        /*
                         * CvFileNode xnode = fs.GetFileNodeByName(pt, "x");
                         * CvFileNode ynode = fs.GetFileNodeByName(pt, "i");
                         * Debug.Assert(
                         *  xnode != null &&
                         *  (xnode.Tag & NodeType.Integer) != 0 &&
                         *  ynode != null &&
                         *  (ynode.Tag & NodeType.Integer) != 0
                         * );
                         * int x = xnode.DataI;
                         * int i = ynode.DataI;
                         * //*/
                        // (5)さらに低速だが,使いやすいバージョン
                        ///*
                        int x = fs.ReadIntByName(pt, "x", 0);
                        int y = fs.ReadIntByName(pt, "y", 0);
                        //*/
                        // (6)データを表示し,次のシーケンスノードを取得
                        Cv.NEXT_SEQ_ELEM(seq.ElemSize, reader);
                        Console.WriteLine("{0}: ({1}, {2})", i, x, y);
                    }
                }
            }
            Console.ReadKey();
        }
コード例 #20
0
ファイル: CvForestTree.cs プロジェクト: neoxeo/opencvsharp
        /// <summary>
        /// 
        /// </summary>
        /// <param name="fs"></param>
        /// <param name="node"></param>
        /// <param name="forest"></param>
        /// <param name="data"></param>
#else
        /// <summary>
        /// 
        /// </summary>
        /// <param name="fs"></param>
        /// <param name="node"></param>
        /// <param name="forest"></param>
        /// <param name="data"></param>
#endif
        public virtual void Read(CvFileStorage fs, CvFileNode node, CvRTrees forest, CvDTreeTrainData data)
        {
            if (fs == null)
                throw new ArgumentNullException("fs");
            if (node == null)
                throw new ArgumentNullException("node");
            if (forest == null)
                throw new ArgumentNullException("forest");
            if (data == null)
                throw new ArgumentNullException("data");

            MLInvoke.CvForestTree_read(ptr, fs.CvPtr, node.CvPtr, forest.CvPtr, data.CvPtr);
        }
コード例 #21
0
ファイル: CvBoost.cs プロジェクト: kaorun55/opencvsharp
        /// <summary>
        /// ファイルストレージからモデルを読み込む
        /// </summary>
        /// <param name="storage"></param>
        /// <param name="node"></param>
#else
		/// <summary>
        /// Reads the model from file storage
        /// </summary>
        /// <param name="storage"></param>
        /// <param name="node"></param>
#endif
        public override void Read(CvFileStorage storage, CvFileNode node) 
        {
            if (storage == null)
                throw new ArgumentNullException("storage");
            if (node == null)
                throw new ArgumentNullException("node");

            NativeMethods.ml_CvBoost_read(ptr, storage.CvPtr, node.CvPtr);
        }
コード例 #22
0
ファイル: CvStatModel.cs プロジェクト: kaorun55/opencvsharp
        /// <summary>
        /// ファイルストレージからモデルを読み込む
        /// </summary>
        /// <param name="storage"></param>
        /// <param name="node"></param>
#else
		/// <summary>
        /// Reads the model from file storage
        /// </summary>
        /// <param name="storage"></param>
        /// <param name="node"></param>
#endif
        public virtual void Read(CvFileStorage storage, CvFileNode node)
        {
            if (disposed)
                throw new ObjectDisposedException("CvStatModel");
            if (storage == null)
                throw new ArgumentNullException("storage");
            if (node == null)
                throw new ArgumentNullException("node");
            NativeMethods.ml_CvStatModel_read(ptr, storage.CvPtr, node.CvPtr);
        }
コード例 #23
0
ファイル: CvANN_MLP.cs プロジェクト: kaorun55/opencvsharp
        /// <summary>
        /// ファイルストレージからモデルを読み込む
        /// </summary>
        /// <param name="fs"></param>
        /// <param name="node"></param>
#else
		/// <summary>
        /// Reads the model from file storage
        /// </summary>
        /// <param name="fs"></param>
        /// <param name="node"></param>
#endif
		public override void Read(CvFileStorage fs, CvFileNode node)
        {
            if (fs == null)
                throw new ArgumentNullException("fs");
            if (node == null)
                throw new ArgumentNullException("node");

            NativeMethods.ml_CvANN_MLP_read(ptr, fs.CvPtr, node.CvPtr);
        }
コード例 #24
0
ファイル: CvStatModel.cs プロジェクト: neoxeo/opencvsharp
        /// <summary>
        /// ファイルストレージからモデルを読み込む
        /// </summary>
        /// <param name="storage"></param>
        /// <param name="node"></param>
#else
		/// <summary>
        /// Reads the model from file storage
        /// </summary>
        /// <param name="storage"></param>
        /// <param name="node"></param>
#endif
        public virtual void Read(CvFileStorage storage, CvFileNode node)
        {
            if (storage == null)
                throw new ArgumentNullException("storage");
            if (node == null)
                throw new ArgumentNullException("node");
            MLInvoke.CvStatModel_read(ptr, storage.CvPtr, node.CvPtr);
        }
コード例 #25
0
        /// <summary>
        /// ファイルストレージからモデルを読み込む
        /// </summary>
        /// <param name="storage"></param>
        /// <param name="node"></param>
#else
        /// <summary>
        /// Reads the model from file storage
        /// </summary>
        /// <param name="storage"></param>
        /// <param name="node"></param>
#endif
        public virtual void Read(CvFileStorage storage, CvFileNode node)
        {
            // OPENCV_ERROR( CV_StsNotImplemented, "CvStatModel::read", "" );
            throw new NotImplementedException();
        }