コード例 #1
0
ファイル: FileStorage.cs プロジェクト: qxp1011/opencvsharp
        /// <summary>
        /// 画像データのファイルストレージへの書き込み
        /// </summary>
        /// <param name="fileName">書きこむXML or YAMLファイル</param>
        private static void SampleFileStorageWriteImage(string fileName)
        {
            // cvWrite, cvWriteComment
            // IplImage構造体の情報をファイルに保存する

            // (1)画像を読み込む
            using (IplImage colorImg = new IplImage(Const.ImageLenna, LoadMode.Color))
            using (IplImage grayImg = new IplImage(colorImg.Size, BitDepth.U8, 1))
            {
                // (2)ROIの設定と二値化処理
                colorImg.CvtColor(grayImg, ColorConversion.BgrToGray);
                CvRect roi = new CvRect(0, 0, colorImg.Width / 2, colorImg.Height / 2);
                grayImg.SetROI(roi);
                colorImg.SetROI(roi);
                grayImg.Threshold(grayImg, 90, 255, ThresholdType.Binary);
                // (3)xmlファイルへの書き出し 
                using (CvFileStorage fs = new CvFileStorage(fileName, null, FileStorageMode.Write))
                {
                    fs.WriteComment("This is a comment line.", false);
                    fs.Write("color_img", colorImg);
                    fs.StartNextStream();
                    fs.Write("gray_img", grayImg);
                }
                // (4)書きこんだxmlファイルを開く
                //using (Process p = Process.Start(fileName)) {
                //    p.WaitForExit();
                //}                
            }
        }
コード例 #2
0
        /// <summary>
        /// 画像データのファイルストレージへの書き込み
        /// </summary>
        /// <param name="fileName">書きこむXML or YAMLファイル</param>
        private static void SampleFileStorageWriteImage(string fileName)
        {
            // cvWrite, cvWriteComment
            // IplImage構造体の情報をファイルに保存する

            // (1)画像を読み込む
            using (IplImage colorImg = new IplImage(Const.ImageLenna, LoadMode.Color))
                using (IplImage grayImg = new IplImage(colorImg.Size, BitDepth.U8, 1))
                {
                    // (2)ROIの設定と二値化処理
                    colorImg.CvtColor(grayImg, ColorConversion.BgrToGray);
                    CvRect roi = new CvRect(0, 0, colorImg.Width / 2, colorImg.Height / 2);
                    grayImg.SetROI(roi);
                    colorImg.SetROI(roi);
                    grayImg.Threshold(grayImg, 90, 255, ThresholdType.Binary);
                    // (3)xmlファイルへの書き出し
                    using (CvFileStorage fs = new CvFileStorage(fileName, null, FileStorageMode.Write))
                    {
                        fs.WriteComment("This is a comment line.", false);
                        fs.Write("color_img", colorImg);
                        fs.StartNextStream();
                        fs.Write("gray_img", grayImg);
                    }
                    // (4)書きこんだxmlファイルを開く
                    //using (Process p = Process.Start(fileName)) {
                    //    p.WaitForExit();
                    //}
                }
        }
コード例 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="fileName"></param>
        private static void SampleFileStorageWriteImage(string fileName)
        {
            // cvWrite, cvWriteComment

            using (IplImage colorImg = new IplImage(FilePath.Image.Lenna, LoadMode.Color))
                using (IplImage grayImg = new IplImage(colorImg.Size, BitDepth.U8, 1))
                {
                    colorImg.CvtColor(grayImg, ColorConversion.BgrToGray);
                    CvRect roi = new CvRect(0, 0, colorImg.Width / 2, colorImg.Height / 2);
                    grayImg.SetROI(roi);
                    colorImg.SetROI(roi);
                    grayImg.Threshold(grayImg, 90, 255, ThresholdType.Binary);

                    using (CvFileStorage fs = new CvFileStorage(fileName, null, FileStorageMode.Write))
                    {
                        fs.WriteComment("This is a comment line.", false);
                        fs.Write("color_img", colorImg);
                        fs.StartNextStream();
                        fs.Write("gray_img", grayImg);
                    }
                }
        }
コード例 #4
0
ファイル: FileStorage.cs プロジェクト: 0sv/opencvsharp
        /// <summary>
        /// 
        /// </summary>
        /// <param name="fileName"></param>
        private static void SampleFileStorageWriteImage(string fileName)
        {
            // cvWrite, cvWriteComment

            using (IplImage colorImg = new IplImage(FilePath.Image.Lenna, LoadMode.Color))
            using (IplImage grayImg = new IplImage(colorImg.Size, BitDepth.U8, 1))
            {
                colorImg.CvtColor(grayImg, ColorConversion.BgrToGray);
                CvRect roi = new CvRect(0, 0, colorImg.Width / 2, colorImg.Height / 2);
                grayImg.SetROI(roi);
                colorImg.SetROI(roi);
                grayImg.Threshold(grayImg, 90, 255, ThresholdType.Binary);

                using (CvFileStorage fs = new CvFileStorage(fileName, null, FileStorageMode.Write))
                {
                    fs.WriteComment("This is a comment line.", false);
                    fs.Write("color_img", colorImg);
                    fs.StartNextStream();
                    fs.Write("gray_img", grayImg);
                }
            }
        }