示例#1
0
        /// <summary> ViewModelの値を構造体に代入 </summary>
        public static SetImageStruct GetSettingStruct(CamViewAreaDVModel data)
        {
            var setStruct = new SetImageStruct
            {
                HasToUndistort  = data.HasToUndistort,
                OutputWidth     = data.OutputWidth,
                OutputHeight    = data.OutputHeight,
                Threshold1      = data.Threshold1,
                Threshold2      = data.Threshold2,
                Threshold       = data.Threshold,
                RhoResolution   = data.RhoResolution,
                ThetaResolution = data.ThetaResolution,
                MinLineLength   = data.MinLineLength,
                MaxLineGap      = data.MaxLineGap,
                Torelance       = data.Torelance,
                LowerThetaLimit = data.LowerThetaLimit,
                HasToMask       = data.HasToMask,
                X1        = data.X1,
                Y1        = data.Y1,
                RecWidth  = data.RecWidth,
                RecHeight = data.RecHeight,
                KSizeX    = data.KSizeX,
                KSizeY    = data.KSizeY,
                SigmaX    = data.SigmaX,
                SigmaY    = data.SigmaY,
            };

            return(setStruct);
        }
示例#2
0
        /// <summary> ファイル保存用のクラスを生成する </summary>
        public static SettingsClass GetStructSettings(CamViewAreaDVModel data)
        {
            var tmp = new SettingsClass()
            {
                Info = new SettingClassInfo()
                {
                    HasToUndistort  = data.HasToUndistort,
                    OutputWidth     = data.OutputWidth,
                    OutputHeight    = data.OutputHeight,
                    Threshold1      = data.Threshold1,
                    Threshold2      = data.Threshold2,
                    Threshold       = data.Threshold,
                    RhoResolution   = data.RhoResolution,
                    ThetaResolution = data.ThetaResolution,
                    MinLineLength   = data.MinLineLength,
                    MaxLineGap      = data.MaxLineGap,
                    Torelance       = data.Torelance,
                    LowerThetaLimit = data.LowerThetaLimit,
                    HasToMask       = data.HasToMask,
                    X1                   = data.X1,
                    Y1                   = data.Y1,
                    RecWidth             = data.RecWidth,
                    RecHeight            = data.RecHeight,
                    KSizeX               = data.KSizeX,
                    KSizeY               = data.KSizeY,
                    SigmaX               = data.SigmaX,
                    SigmaY               = data.SigmaY,
                    SlopeAngleResolution = data.SlopeAngleResolution,
                    IntersectResolution  = data.IntersectResolution,
                    Point1X              = data.Point1X,
                    Point1Y              = data.Point1Y,
                    Point2X              = data.Point2X,
                    Point2Y              = data.Point2Y,
                    RefCornerPointX      = data.RefCornerPointX,
                    RefCornerPointY      = data.RefCornerPointY,
                    RefCornerAngle       = data.RefCornerAngle,
                    RefCornerPointX2     = data.RefCornerPointX2,
                    RefCornerPointY2     = data.RefCornerPointY2,
                    BirateralKernel      = data.BirateralKernel,
                    SigmaSpace           = data.SigmaSpace,
                    SigmaColer           = data.SigmaColer,
                    SearchLength         = data.SearchLength,
                    SearchLine           = data.SearchLine,
                    ChessCrossWidth      = data.ChessCrossWidth,
                    ChessCrossHeigth     = data.ChessCrossHeigth,
                    ChessSquareSize      = data.ChessSquareSize,
                    OffsetX              = data.OffsetX,
                    OffsetY              = data.OffsetY
                }
            };

            return(tmp);
        }
示例#3
0
        /// <summary> XMLファイルを読み込んで設定更新  </summary>
        /// <param name="data"></param>
        /// <param name="fileName"></param>
        public static void ReadParamFromXml(string fileName)
        {
            var data       = new CamViewAreaDVModel();
            var serializer = new XmlSerializer(typeof(SettingsClass));

            using (var sr = new StreamReader(fileName, new UTF8Encoding(false)))
            {
                var ans = (SettingsClass)serializer.Deserialize(sr);
                data.HasToUndistort  = ans.Info.HasToUndistort;
                data.OutputWidth     = ans.Info.OutputWidth;
                data.OutputHeight    = ans.Info.OutputHeight;
                data.Threshold1      = ans.Info.Threshold1;
                data.Threshold2      = ans.Info.Threshold2;
                data.RhoResolution   = ans.Info.RhoResolution;
                data.ThetaResolution = ans.Info.ThetaResolution;
                data.Threshold       = ans.Info.Threshold;
                data.MinLineLength   = ans.Info.MinLineLength;
                data.MaxLineGap      = ans.Info.MaxLineGap;
                data.Torelance       = ans.Info.Torelance;
                data.LowerThetaLimit = ans.Info.LowerThetaLimit;
                data.HasToMask       = ans.Info.HasToMask;
                data.X1                   = ans.Info.X1;
                data.Y1                   = ans.Info.Y1;
                data.RecWidth             = ans.Info.RecWidth;
                data.RecHeight            = ans.Info.RecHeight;
                data.KSizeX               = ans.Info.KSizeX;
                data.KSizeY               = ans.Info.KSizeY;
                data.SigmaX               = ans.Info.SigmaX;
                data.SigmaY               = ans.Info.SigmaY;
                data.SlopeAngleResolution = ans.Info.SlopeAngleResolution;
                data.IntersectResolution  = ans.Info.IntersectResolution;
                data.Point1X              = ans.Info.Point1X;
                data.Point1Y              = ans.Info.Point1Y;
                data.Point2X              = ans.Info.Point2X;
                data.Point2Y              = ans.Info.Point2Y;
                data.RefCornerPointX      = ans.Info.RefCornerPointX;
                data.RefCornerPointY      = ans.Info.RefCornerPointY;
                data.RefCornerAngle       = ans.Info.RefCornerAngle;
                data.RefCornerPointX2     = ans.Info.RefCornerPointX2;
                data.RefCornerPointY2     = ans.Info.RefCornerPointY2;
                data.BirateralKernel      = ans.Info.BirateralKernel;
                data.SigmaSpace           = ans.Info.SigmaSpace;
                data.SigmaColer           = ans.Info.SigmaColer;
                data.SearchLength         = ans.Info.SearchLength;
                data.SearchLine           = ans.Info.SearchLine;
                data.ChessCrossWidth      = ans.Info.ChessCrossWidth;
                data.ChessCrossHeigth     = ans.Info.ChessCrossHeigth;
                data.ChessSquareSize      = ans.Info.ChessSquareSize;
                data.OffsetX              = ans.Info.OffsetX;
                data.OffsetY              = ans.Info.OffsetY;
            }
        }
示例#4
0
        /// <summary> 設定読込ボタン(xml) </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_LoadSettingFromXml_Click(object sender, RoutedEventArgs e)
        {
            //書き込むファイルを指定
            var saveFileDialog = new SaveFileDialog();

            saveFileDialog.Filter = "XMLファイル(.xml)|*.xml|All Files (*.*)|*.*";
            saveFileDialog.Title  = "設定保存";
            saveFileDialog.ShowDialog();

            if (saveFileDialog.FileName == "")
            {
                return;
            }

            CamViewAreaDVModel.ReadParamFromXml(saveFileDialog.FileName);
        }
示例#5
0
        /// <summary> 撮像開始ボタン </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_CamCapture_Click(object sender, RoutedEventArgs e)
        {
            //撮影用パラメータの送信と応答受信
            //キャプチャ番号を取得
            var capNum = (int)Decimal_CapPositon.Value;

            //撮影用パラメータ設定
            if (CheckBox_AutoSettingRead.IsChecked == true)
            {
                //チェックボックスにチェックがある場合はcapNumに対応したファイルを読み込み反映する
                var capParam = paramHangerDir + $@"\Cam001_pos_011_plate_{capNum:D3}_param.xml";
                if (!File.Exists(capParam))
                {
                    //撮影用パラメータが存在しない場合
                    MessageBox.Show($"撮影用パラメータ\n{capParam}\nがありません.作成後、プログラムを再起動してください", "File Missing Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                else
                {
                    CamViewAreaDVModel.ReadParamFromXml(capParam);
                }
            }

            //ヘッダー:判定部
            var cmdSendStr = "StructAll";

            //送信用構造体(パラメータ)取得
            var camSettng = SetImageStruct.GetSettingStruct(new CamViewAreaDVModel());

            //送信用バイト配列取得(ヘッダー+送信用構造体)
            var cmdSendStrBt = SetImageStruct.StructToByte(cmdSendStr, camSettng);

            //撮影用パラメータ送信
            SendData(namedPipe, cmdSendStrBt);

            //応答受信
            if (RecvData(namedPipe)[0] != "StructerReceived")
            {
                Trace.WriteLine($"構造体(撮影パラメータ)の送受信に失敗しました", "Error");
                Environment.Exit(2);
            }

            //撮影位置番号と撮像開始信号の送信と応答受信
            //ヘッダー:判定部
            var cmdSendCapStr = string.Format(string.Format(CheckBox_CamUse.IsChecked == false ? $"Capture,{capNum:D3}" : $"OfflineImage,{capNum:D3}"));
            var cmdSendCapBt  = Encoding.UTF8.GetBytes(cmdSendCapStr);

            //撮影位置番号と撮像開始信号送信
            SendData(namedPipe, cmdSendCapBt);

            //応答受信
            if (RecvData(namedPipe)[0] != "SucceedCapture")
            {
                Trace.WriteLine($"撮像中にエラーが発生しました", "Error");
                Environment.Exit(3);
            }

            //撮影位置番号と測定結果要請の送信と応答受信及びに測定結果表示
            //ヘッダー:判定部
            var cmdGetResultStr = "GetMeasureData";

            //送信用バイト配列取得(ヘッダー+送信用構造体)
            var cmdGetResultBt = SetImageStruct.StructToByte(cmdGetResultStr, camSettng);

            //撮影位置番号と定結果要請送信
            SendData(namedPipe, cmdGetResultBt);

            //応答受信
            var resultStrAr = RecvData(namedPipe);

            //richTextに表示
            var paragraph   = new Paragraph();
            var recDetaSize = 0;

            try
            {
                recDetaSize = int.Parse(resultStrAr[1]);
            }
            catch (ArgumentNullException ane)
            {
                Trace.WriteLine("結果受信中にエラーが発生しました", "Error");
                Environment.Exit(4);
            }

            if (recDetaSize == resultStrAr[3].Length)
            {
                var resultStr = resultStrAr[0] + "[" + resultStrAr[2] + "]" + "Coordinates" + "[" + resultStrAr[3] + "]";
                paragraph.Inlines.Add(resultStr);
                RichTextBox_Result.Document.Blocks.Add(paragraph);
            }
            else
            {
                Trace.WriteLine("受信した結果のサイズ情報に誤りがあります", "Error");
                Environment.Exit(5);
            }

            //撮影位置番号と編集画像の要請と画像の受信
            //ヘッダー:判定部
            var cmdGetImgStr = "GetImage";

            //送信用バイト配列取得(ヘッダー+送信用構造体)
            var cmdGetImgBt = SetImageStruct.StructToByte(cmdGetImgStr, camSettng);

            //撮影位置番号と定結果要請送信
            SendData(namedPipe, cmdGetImgBt);

            //受信用のバッファサイズ取得
            var imgBytes = new byte[namedPipe.InBufferSize];
            var rCnt     = namedPipe.Read(imgBytes, 0, imgBytes.Length); //受信

            //Byte->画像変換
            var imgStrAr = RecvData(namedPipe);
            var imgStr   = string.Empty;
            var imgSize  = 0;
            var imgWidth = 0;
            var imgHeigh = 0;

            try
            {
                imgStr   = imgStrAr[0];
                imgSize  = int.Parse(imgStrAr[1]);
                imgWidth = int.Parse(imgStrAr[2]);
                imgHeigh = int.Parse(imgStrAr[3]);
            }
            catch (Exception ex)
            {
                Trace.WriteLine("画像の変換中にエラーが発生しました", "Error");
                Environment.Exit(6);
            }

            //byte->画像生成->Xamlに表示
            if (imgStr == "Image")
            {
                var imgRawBtAr = new byte[imgSize];
                Buffer.BlockCopy(imgBytes, rCnt - imgSize, imgRawBtAr, 0, imgSize); //bmp rawを取得する

                var bitmapImg = new BitmapImage();

                var bmp = ByteArrayToImage(imgRawBtAr, imgWidth, imgHeigh);
                var ms  = new MemoryStream();
                bmp.Save(ms, ImageFormat.Bmp);
                ms.Position = 0;
                bitmapImg.BeginInit();
                bitmapImg.CacheOption  = BitmapCacheOption.OnLoad;
                bitmapImg.StreamSource = ms;
                bitmapImg.EndInit();
                bitmapImg.Freeze();

                ImageView.Source = bitmapImg;
            }
            else
            {
                Trace.WriteLine($"撮像に失敗しました.", "Error");
                Environment.Exit(7);
            }
        }