NGMsoftware

NGMsoftware
로그인 회원가입
  • 커뮤니티
  • 질문과 답변
  • 커뮤니티

    지식인! 질문에 답변을 달면 포인트가 지급됩니다.

    질문과 답변

    지식인! 질문에 답변을 달면 포인트가 지급됩니다.

    질문에 대한 답변을 3일안에 채택하지 않으면, 자동으로 첫번째 답변자가 채택되고 포인트는 100점이 차감됩니다.

    커스텀 모듈 코드가 어디가 문제인지 전혀 감이 안잡힙니다...... image. saver (경로)를......

    페이지 정보

    본문

       [Category("Action")]
            [DisplayName("이미지 찾을 범위")]
            [Description("찾아라 이미지를 그리고 발견되길.")]
            [Browsable(true)]

            [ComVisible(true)]
            [TypeConverter(typeof(RectangleConverter))]

            public Rectangle Search { get; set; }
            public override bool? Execute(NGM.Interface.IMainView mainView, NGM.Interface.IPlayer player)
            {
                Rectangle rect;
                bool isSame;
                string[] imageFullNames = { ImageFullName1};
                string[] trueIDs = { Image1TrueID};
                int index = 0;
                
                foreach (string imageFullName in imageFullNames)
                {
                    if (string.IsNullOrEmpty(imageFullName))
                    {
                        index++;
                        continue;
                    }

                    string fullName = Path.Combine((mainView.OptionConfig as NGM.Models.Configuration.OptionConfigModel)
                        .ImageDirectory, imageFullName);

                    if (!File.Exists(fullName))
                    {
                        if (mainView != null && mainView.ShowConditionOutput)
                            player.WriteOutput($"{mainView.ResxMessage.GetString("FileNotFound")}{Environment.NewLine}{mainView.ResxCaption.GetString("FilePath")}: {imageFullName}");

                        index++;
                        continue;
                    }

                    NGM.Models.ImageModel imageModel;
                    using (Stream file = File.Open(fullName, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        BinaryFormatter bf = new BinaryFormatter();
                        imageModel = (NGM.Models.ImageModel)bf.Deserialize(file);
                    }

                    //   sourceImage = (Image)imageModel.Image;
                    //   sourceImage = NGM.Utility.ImageManager.OpenCV.Binary(sourceImage, true, imageModel.BinaryThreshold);
                    //   sourceImage = NGM.Utility.ImageManager.OpenCV.BrightnessContrast(sourceImage, imageModel.Brightness, imageModel.Contrast);

                    Image sourceImage = null;
                    Image targetImage = null;
                    //불러온 이미지는 투명픽셀 적용(반전)
                    sourceImage = NGM.Utility.ImageManager.OpenCV.TransparentPixel(imageModel.Image, imageModel.TransparentColors, imageModel.TransparentValue, imageModel.TransparentRange,true);
                    
                    //찾아야될 영역 안에 있는 이미지는 투명픽셀적용 명도 및 대비적용 이진화 적용
                    if (player.MainHandle == IntPtr.Zero)
                        targetImage = NGM.Utility.ScreenCaptureManager.ScreenShot.GetActiveImage(Search , player);
                    else
                        targetImage = NGM.Utility.ScreenCaptureManager.ScreenShot.GetInactiveImage(player, Rectangle.Empty, Rectangle.Empty, Rectangle.Empty, false);
                    
                        targetImage = NGM.Utility.ImageManager.OpenCV. TransparentPixel(targetImage, imageModel.TransparentColors, imageModel.TransparentValue, imageModel.TransparentRange, true);
                        targetImage = NGM.Utility.ImageManager.OpenCV.Binary(targetImage, false, imageModel.BinaryThreshold);
                        targetImage = NGM.Utility.ImageManager.OpenCV.BrightnessContrast(targetImage, imageModel.Brightness, imageModel.Contrast);
                    
                    //비교하기 공차 10
                    rect = NGM.Utility.ImageManager.ImageCondition.IsSearch(sourceImage, targetImage, 10, false) ;
                    isSame = !rect.IsEmpty;

                    if (isSame)
                    {
                        base.TrueID = trueIDs[index];
                        this.SearchRectangle = rect;
                        this.SearchPoint = new Point(rect.X + rect.Width / 2, rect.Y + rect.Height / 2);

                        return true;
                    }

                    #region 리소스 해제
                    if (sourceImage != null)
                    {
                        sourceImage.Dispose();
                        sourceImage = null;
                    }

                    if (targetImage != null)
                    {
                        targetImage.Dispose();
                        targetImage = null;
                    }

                    if (imageModel != null)
                    {
                        if (imageModel.Image != null)
                        {
                            imageModel.Image.Dispose();
                            imageModel.Image = null;
                        }

                        imageModel = null;
                    }
                    #endregion

                    index++;
                }

                base.FalseID = ImageAllFalseID;
                return false;
            }
        }

     

    어디부분이 문제인지 모르겠습니다

    [ComVisible(true)]

    [TypeConverter(typeof(RectangleConverter))]

    이걸 넣너도 빌드가 되고 안넣어도 빌드가 됩니다 이미지 영역을 지정하기위해 new Rectangle() 이걸 타겟 이미지에 있는 Search  이부분에 넣으면 저 앞에 있는 건 어디서 값을 가져오는지 항목을 만들어야 하는데 항목을 만들 속성을 만들면 저게 어떻게 들어가게 해야할지 몰라서 좌표를 받아오게 만들었는데 어느부분을 잘못했는지 도저히 봐도 모르겠네요 ㅠㅠ 

     

    참조를 보면서 하고 있는데 정말 모르겠습니다 ㅠㅠ

    • 네이버 공유하기
    • 페이스북 공유하기
    • 트위터 공유하기
    • 카카오스토리 공유하기
    추천0 비추천0

    댓글목록

      채택답변
    profile_image

    엔지엠소프트웨어님의 댓글

    엔지엠소프트웨어 쪽지보내기 메일보내기 홈페이지 자기소개 아이디로 검색 전체게시물 작성일 Date

    질문의 내용을 모르겠네요...
    하시고 싶은 요점만 올려주시면^^;
    음... 일단 내용으로 봐서는 영역 선택 콘트롤이 필요하신건가요?