프로젝트

일반

사용자정보

개정판 38d69491

ID38d69491020d2a565b7158e53b39c70500b84548
상위 3276cb1c
하위 92c9cab8

김태성이(가) 약 일년 전에 추가함

issue #00000 ctrl+S입력시 텍스트박스 입력 완료 되도록 수정

Change-Id: Id4ab97a53ab61022f5a2ac4d5ae63cd14338c2a7

차이점 보기:

ImageComparer/Markus.ImageCompare/ImageCompareBase.cs
1 1
using OpenCvSharp;
2
using OpenCvSharp.Extensions;
2 3
using System;
3 4
using System.Collections.Generic;
4 5
using System.Drawing;
......
8 9
using System.Net;
9 10
using System.Runtime.InteropServices;
10 11
using System.Text;
12
using System.Threading;
11 13
using System.Threading.Tasks;
14
using static System.Net.Mime.MediaTypeNames;
12 15
using Point = System.Drawing.Point;
13 16
using Size = System.Drawing.Size;
14 17

  
......
46 49
            {
47 50
                SetStatus("Image Load", 0, CompareStatus.Loading);
48 51

  
52
                //Originalbitmap = To24Bpp(Originalbitmap, Originalbitmap.Size);
53
                //TargatBitmap = To24Bpp(TargatBitmap, Originalbitmap.Size);
54

  
49 55
                Originalbitmap = ChangeBitmapFormatAndSize(Originalbitmap, Originalbitmap.Size, PixelFormat.Format24bppRgb);
50 56
                TargatBitmap = ChangeBitmapFormatAndSize(TargatBitmap, Originalbitmap.Size, PixelFormat.Format24bppRgb);
51 57

  
52 58
                // 원본이미지의 크키와 Format24bppRgb로 타켓 이미지를 변경
53 59
                // 크기가 틀린 경우 비교시 바이트배열 오류 발생
60

  
54 61
                OriginalImageData = OpenCvSharp.Extensions.BitmapConverter.ToMat(Originalbitmap);
55 62
                TargatImageData = OpenCvSharp.Extensions.BitmapConverter.ToMat(TargatBitmap);
63
                var grayOriginal = new OpenCvSharp.Mat();
64
                var grayTargat = new OpenCvSharp.Mat();
56 65

  
57 66
                if (OriginalImageData.Size() != TargatImageData.Size())
58 67
                {
59 68
                    Cv2.Resize(TargatImageData, TargatImageData, OriginalImageData.Size());
60 69
                }
61
                
62
                Cv2.CvtColor(OriginalImageData, OriginalImageData, ColorConversionCodes.BGR2GRAY);
63
                Cv2.CvtColor(TargatImageData, TargatImageData, ColorConversionCodes.BGR2GRAY);
70
  
71
                Cv2.CvtColor(OriginalImageData, grayOriginal, ColorConversionCodes.BGR2GRAY);
72
                Cv2.CvtColor(TargatImageData, grayTargat, ColorConversionCodes.BGR2GRAY);
73
                //Cv2.ImShow("grayOriginal", grayOriginal);
74
                //Cv2.ImShow("grayTargat", grayTargat);
64 75

  
65
                Mat outputData = new Mat(TargatImageData.Size(), MatType.CV_8UC1);
76
                Mat outputData = new Mat(grayTargat.Size(), MatType.CV_8UC1);
66 77

  
67
                Cv2.Absdiff(OriginalImageData, TargatImageData, outputData);
78
                Cv2.Absdiff(grayOriginal, grayTargat, outputData);
68 79

  
69 80
                // 틀린부분을 반환
70 81
                Cv2.BitwiseNot(outputData, result);
82
                //Cv2.ImShow("result", result);
71 83
            }
72 84
            catch (Exception ex)
73 85
            {
......
80 92
            return result;
81 93
        }
82 94

  
83
        protected System.Drawing.Bitmap ChangeBitmapFormatAndSize(System.Drawing.Bitmap bitmap, Size newSize, PixelFormat pixelFormat)
95
        public System.Drawing.Bitmap ChangeBitmapFormatAndSize(System.Drawing.Bitmap bitmap, Size newSize, PixelFormat pixelFormat)
84 96
        {
85
            Bitmap result = bitmap;
86

  
87
            if (pixelFormat != bitmap.PixelFormat)
88
            {
89
                Point originPoint = new Point(0, 0);
90
                Rectangle rect = new Rectangle(originPoint, bitmap.Size);
91
                result = bitmap.Clone(rect, pixelFormat);
92
            }
93

  
94
            if (bitmap.Size != newSize)
95
            {
96
                result = new Bitmap(newSize.Width, newSize.Height);
97

  
98
                using (Graphics g = Graphics.FromImage(result))
99
                {
100
                    g.DrawImage(bitmap, 0, 0, newSize.Width, newSize.Height);
101
                    g.Dispose();
102
                }
103
            }
97
            Bitmap result;
98
            
99
            result = new Bitmap(newSize.Width, newSize.Height, pixelFormat);
100
            Graphics g = Graphics.FromImage(result);
101
            g.DrawImage(bitmap, new Rectangle(0, 0, newSize.Width, newSize.Height), 0, 0, newSize.Width, newSize.Height, GraphicsUnit.Pixel);
102
            //g.DrawImage(bitmap, 0, 0, newSize.Width, newSize.Height);
103
            g.Save();
104
            g.Dispose();
104 105

  
105 106
            return result;
106 107
        }
......
130 131

  
131 132
            OpenCvSharp.Point testpoint = new OpenCvSharp.Point();
132 133
           
133
            Cv2.Threshold(data, data, 0, 30,ThresholdTypes.BinaryInv);
134
            Cv2.Threshold(data, data, 0, 255, ThresholdTypes.Binary | ThresholdTypes.Otsu);
134 135

  
135 136
            Cv2.FindContours(data, out contours, out hierarchy,RetrievalModes.List,ContourApproximationModes.ApproxNone, testpoint);
136 137

  
137 138
            SetStatus("Comparison", 0, CompareStatus.Comparison);
138 139
            contoursLongCount = contours.Sum(x => x.Count());
139

  
140
            
140 141
            var rects = contours.AsParallel()
141 142
                                .Select(points => GetRectList(points, block))
142 143
                                .SelectMany(x => x);
143 144

  
144 145
            results.AddRange(rects);
145
             
146
            
147
            System.Diagnostics.Debug.WriteLine(new TimeSpan(stopwatch.ElapsedTicks));
148

  
146 149
            return results;
147 150
        }
151
        private List<System.Windows.Rect> GetRectList(OpenCvSharp.Point[] points, Size block)
152
        {
153
            List<System.Windows.Rect> result = new List<System.Windows.Rect>();
154

  
155
            Parallel.ForEach(points, point =>
156
            {
157
                var rect = new System.Windows.Rect
158
                {
159
                    X = point.X - block.Width / 2,
160
                    Y = point.Y - block.Height / 2,
161
                    Width = block.Width,
162
                    Height = block.Height
163
                };
164

  
165
                lock (result)
166
                {
167
                    if (!result.Any(r => r.IntersectsWith(rect)))
168
                    {
169
                        result.Add(rect);
170
                    }
171
                }
172

  
173
                //ComparisonCount++;
174

  
175
                //Interlocked.Increment(ref ComparisonCount);
176

  
177
                //SetStatus("Comparison", ComparisonCount / contoursLongCount * 100, CompareStatus.Comparison);
178
            });
179

  
180
            return result;
181
        }
148 182

  
149
        private List<System.Windows.Rect> GetRectList(OpenCvSharp.Point[] points,Size block)
183
        private List<System.Windows.Rect> GetRectList_old(OpenCvSharp.Point[] points,Size block)
150 184
        {
151 185
            List<System.Windows.Rect> result = new List<System.Windows.Rect>();
152 186

  
......
167 201

  
168 202
                ComparisonCount++;
169 203

  
170
                SetStatus("Comparison", ComparisonCount/contoursLongCount*100, CompareStatus.Comparison);
204
                //SetStatus("Comparison", ComparisonCount/contoursLongCount*100, CompareStatus.Comparison);
171 205
            }
172 206

  
173 207
            return result;

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)