/// <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(); //} } }
/// <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); } } }