xcd
2020-03-28 18a29824a66de5bdd26bb8d16f4b6b4380740120
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
using System;
using System.Collections;
using HalconDotNet;
 
 
namespace HalconTools
{
    
    /// <summary>
    /// This class contains the parameters that are used to
    /// create and detect the shape-based model. 
    /// Besides auxiliary methods to set and get the parameters, there 
    /// is a set of methods to handle the parameters for 'automatic' 
    /// determination.
    /// </summary>
    public class MatchingParam
    {
 
        // --------------- create model ---------------------
 
        /// <summary>
        /// Defines the maximum number of pyramid levels
        /// </summary>
        public int      mNumLevel;        
        /// <summary>
        /// Measure for local gray value differences between
        /// the object and the background and between 
        /// different parts of the object
        /// </summary>
        public int      mContrast; 
        /// <summary>
        /// Minimum scale of the model
        /// </summary>
        public double mMinScale;        
        /// <summary>
        /// Maximum scale of the model
        /// </summary>
        public double mMaxScale;        
        /// <summary>
        /// Step length within the selected range of scales
        /// </summary>
        public double mScaleStep;        
        /// <summary>
        /// Smallest rotation of the model
        /// </summary>
        public double mStartingAngle;    
        /// <summary>
        /// Extent of the rotation angles
        /// </summary>
        public double mAngleExtent;        
        /// <summary>
        /// Step length within the selected range of angles
        /// </summary>
        public double mAngleStep;        
        /// <summary>
        /// Used to separate the model from the noise in the image
        /// </summary>
        public int      mMinContrast;        
        /// <summary>
        /// Conditions determining how the model is supposed to be 
        /// recognized in the image
        /// </summary>
        public string mMetric;            
        /// <summary>
        /// Defines the kind of optimization and optionally the 
        /// kind of method used for generating the model
        /// </summary>
        public string mOptimization;    
 
 
        // -------------------- find model -----------------------
 
        /// <summary>
        /// Defines the score a potential match must have at least 
        /// to be accepted as an instance of the model in the image
        /// </summary>
        public double mMinScore;
        /// <summary>
        /// Number of instances of the model to be found
        /// </summary>
        public int      mNumMatches;
        /// <summary>
        /// 'Greediness' of the search heuristic (0 means safe but slow - 
        /// 1 means fast but matches may be missed).
        /// </summary>
        public double mGreediness;
        /// <summary>
        /// Defines fraction two instances may at most overlap in order
        /// to consider them as different instances, and hence
        /// to be returned separately
        /// </summary>
        public double mMaxOverlap;
        /// <summary>
        /// Determines whether the instances should be extracted with 
        /// subpixel accuracy
        /// </summary>
        public string mSubpixel;
        /// <summary>
        /// Determines the lowest pyramid level to which the 
        /// found matches are tracked. Mechanism is used to 
        /// speed up the matching.
        /// </summary>
        public int    mLastPyramidLevel;
 
        //----------------- optimize recognition speed ----------------
 
        /// <summary>
        /// Defines heuristic for evaluating the detection results
        /// </summary>
        public int      mRecogRateOpt; /* opt=0 => '=' und opt=1 => '>='*/
        /// <summary>
        /// Defines rate for the model recognition
        /// </summary>
        public int      mRecogRate;
        /// <summary>
        /// Defines mode to determine accuracy of recognition
        /// </summary>
        public string mRecogSpeedMode;
        /// <summary>
        /// Manual selection of number of matches to be found.
        /// </summary>
        public int      mRecogManualSel;
 
        // ---------------------- inspect vals -----------------------
 
        /// <summary>
        /// Is equal to the value of the parameter mNumMatches
        /// </summary>
        public int mInspectMaxNoMatch;
        /// <summary>
        /// List of parameters to be determined automatically
        /// </summary>
        public ArrayList paramAuto;
        
 
        /// <summary>
        /// Constant defining the auto-mode for the parameter NumLevels
        /// </summary>
        public const string AUTO_NUM_LEVEL        = "num_levels";
        /// <summary>
        /// Constant defining the auto-mode for the parameter Contrast
        /// </summary>
        public const string AUTO_CONTRAST        = "contrast"; 
        /// <summary>
        /// Constant defining the auto-mode for the parameter ScaleStep
        /// </summary>
        public const string AUTO_SCALE_STEP        = "scale_step";
        /// <summary>
        /// Constant defining the auto-mode for the parameter AngleStep
        /// </summary>
        public const string AUTO_ANGLE_STEP        = "angle_step";
        /// <summary>
        /// Constant defining the auto-mode for the parameter MinContrast
        /// </summary>
        public const string AUTO_MIN_CONTRAST    = "min_contrast";
        /// <summary>
        /// Constant defining the auto-mode for the parameter Optimization
        /// </summary>
        public const string AUTO_OPTIMIZATION    = "optimization";
        
        /// <summary>
        /// Constant indicating an update for the button representation of
        /// AngleStart.
        /// </summary>
        public const string BUTTON_ANGLE_START    = "angle_start";
        /// <summary>
        /// Constant indicating an update for the button representation of
        /// AngleExtent.
        /// </summary>
        public const string BUTTON_ANGLE_EXTENT    = "angle_extent";
        /// <summary>
        /// Constant indicating an update for the button representation of
        /// ScaleMin.
        /// </summary>
        public const string BUTTON_SCALE_MIN    = "scale_min";
        /// <summary>
        /// Constant indicating an update for the button representation of
        /// ScaleMax.
        /// </summary>
        public const string BUTTON_SCALE_MAX    = "scale_max";
        /// <summary>
        /// Constant indicating an update for the button representation of
        /// Metric.
        /// </summary>
        public const string BUTTON_METRIC        = "metric";
        /// <summary>
        /// Constant indicating an update for the button representation of
        /// MinScore.
        /// </summary>
        public const string BUTTON_MINSCORE        = "min_score";
        /// <summary>
        /// Constant indicating an update for the button representation of
        /// Greediness.
        /// </summary>
        public const string BUTTON_GREEDINESS    = "greediness";
 
        /// <summary>
        /// Constant defining the number of instances to be detected:
        /// Find number of models specified by the user
        /// </summary>
        public const string RECOGM_MANUALSELECT    = "RecognFindSpecifiedNumber";
        /// <summary>
        /// Constant defining the number of instances to be detected:
        /// Find at least one model instance per image
        /// </summary>
        public const string RECOGM_ATLEASTONE    = "RecognAtLeast";
        /// <summary>
        /// Constant defining the number of instances to be detected:
        /// Find maximum number of model instances per image
        /// </summary>
        public const string RECOGM_MAXNUMBER    = "RecognFindMaximum";
        
        /// <summary>
        /// Constant indicating a change of ScaleStep for
        /// its GUI component representation 
        /// </summary>
        public const string RANGE_SCALE_STEP    = "RangeScaleStep";
        /// <summary>
        /// Constant indicating a change of AngleStep for
        /// its GUI component representation 
        /// </summary>
        public const string RANGE_ANGLE_STEP    = "RangeAngleStep";
        
        /// <summary>
        /// Constant indicating an error regarding the parameter set. 
        /// It is forwarded for HALCON errors that occur during the
        /// creation of the shape-based model or detection of instances 
        /// of the model
        /// </summary>
        public const string H_ERR_MESSAGE        = "Halcon Error";
 
 
        /// <summary>Constructor</summary>
        public MatchingParam()
        {
            paramAuto = new ArrayList(10);
        }
        
        /*******************************************************************/
        /*    Setter-methods for the set of values, that can be determined 
         *    automatically. If a parameter gets assigned a new value
         *    it can be only caused by user interaction, which means, the
         *    auto-modus for these particular parameters needs to be 
         *    canceled, to avoid further automatic adjustment              
        /*******************************************************************/
  
        /// <summary>
        /// Sets the parameter <c>NumLevel</c> to the supplied value;
        /// if the parameter has been in auto-mode, cancel this option
        /// </summary>
        public void setNumLevel(double val)
        {
            mNumLevel = (int)val;
            if(paramAuto.Contains(AUTO_NUM_LEVEL))
                paramAuto.Remove(AUTO_NUM_LEVEL);
        }
    
        /// <summary>
        /// Sets the parameter <c>Contrast</c> to the supplied value;
        /// if the parameter has been in auto-mode, cancel this option
        /// </summary>
        public void setContrast(int val)
        {
            mContrast = val;
 
            if(paramAuto.Contains(AUTO_CONTRAST))
                paramAuto.Remove(AUTO_CONTRAST);
        }
    
        /// <summary>
        /// Sets the parameter <c>MinScale</c> to the supplied value;
        /// if the parameter has been in auto-mode, cancel this option
        /// </summary>
        public void setMinScale(double val)
        {
            mMinScale = val;
        }
    
        /// <summary>
        /// Sets the parameter <c>MaxScale</c> to the supplied value;
        /// if the parameter has been in auto-mode, cancel this option
        /// </summary>
        public void setMaxScale(double val)
        {
            mMaxScale = val;
        }
        
        /// <summary>
        /// Sets the parameter <c>ScaleStep</c> to the supplied value;
        /// if the parameter has been in auto-mode, cancel this option
        /// </summary>
        public void setScaleStep(double val)
        {
            mScaleStep = val;
 
            if(paramAuto.Contains(AUTO_SCALE_STEP))
                paramAuto.Remove(AUTO_SCALE_STEP);
 
        }
        
        /// <summary>
        /// Sets the parameter <c>AngleStep</c> to the supplied value;
        /// if the parameter has been in auto-mode, cancel this option
        /// </summary>
        public void setAngleStep(double val)
        {
            mAngleStep = val;
 
            if(paramAuto.Contains(AUTO_ANGLE_STEP))
                paramAuto.Remove(AUTO_ANGLE_STEP);
        }
    
        /// <summary>
        /// Sets the parameter <c>MinContrast</c> to the supplied value;
        /// if the parameter has been in auto-mode, cancel this option
        /// </summary>
        public void setMinContrast(int val)
        {
            mMinContrast = val;
 
            if(paramAuto.Contains(AUTO_MIN_CONTRAST))
                paramAuto.Remove(AUTO_MIN_CONTRAST);
        }
 
        /// <summary>
        /// Sets the parameter <c>Optimization</c> to the supplied value;
        /// if the parameter has been in auto-mode, cancel this option
        /// </summary>
        /// <param name="val"></param>
        public void setOptimization(string val)
        {
            mOptimization = val;
 
            if(paramAuto.Contains(AUTO_OPTIMIZATION))
                paramAuto.Remove(AUTO_OPTIMIZATION);
        }        
 
        
        /*******************************************************************/
        /*        Setter-methods for the other values                      */
        /*******************************************************************/
 
        /// <summary>
        /// Sets the parameter <c>StartingAngle</c> to the supplied value
        /// </summary>
        public void setStartingAngle(double val)
        {
            mStartingAngle = val;
        }
        
        /// <summary>
        /// Sets the parameter <c>AngleExtent</c> to the supplied value
        /// </summary>
        public void setAngleExtent(double val)
        {
            mAngleExtent = val;
        }
    
        /// <summary>
        /// Sets the parameter <c>Metric</c> to the supplied value
        /// </summary>
        public void setMetric(string val)
        {
            mMetric = val;
        }
        
        /// <summary>
        /// Sets the parameter <c>MinScore</c> to the supplied value
        /// </summary>
        public void setMinScore(double val)
        {
            mMinScore = val;
        }
        
        /// <summary>
        /// Sets  the parameter <c>NumMatches</c> to the supplied value
        /// </summary>
        public void setNumMatches(int val)
        {
            mNumMatches = val;
        }
 
        
        /// <summary>
        /// Sets the parameter <c>Greediness</c> to the supplied value
        /// </summary>
        public void setGreediness(double val)
        {
            mGreediness = val;
        }
 
        /// <summary>
        /// Sets the parameter <c>MaxOverlap</c> to the supplied value
        /// </summary>
        public void setMaxOverlap(double val)
        {
            mMaxOverlap = val;
        }
 
        /// <summary>
        /// Sets the parameter <c>Subpixel</c> to the supplied value
        /// </summary>
        public void setSubPixel(string val)
        {
            mSubpixel = val;
        }
 
        /// <summary>
        /// Sets the parameter <c>LastPyramidLevel</c> to the supplied value
        /// </summary>
        public void setLastPyramLevel(int val)
        {
            mLastPyramidLevel = val;
        }
 
        /*******************************************************************/
        /*******************************************************************/
        /*******************************************************************/
 
        /// <summary>
        /// Sets the parameter defining the options for the recognition rate
        /// to the supplied value
        /// </summary>
        public void setRecogRateOption(int val)
        {
            mRecogRateOpt = val;
        }
 
        /// <summary>
        /// Sets the parameter defining the rate for the recognition to the
        /// supplied value.
        /// </summary>
        public void setRecogitionRate(int val)
        {
            mRecogRate = val;
        }
 
        /// <summary>
        /// Sets the parameter to define the mode of accuracy
        /// </summary>
        public void setRecogSpeedMode(string val)
        {
            mRecogSpeedMode = val;
        }
 
        /// <summary>
        /// Sets the number of matches to be recognized to the supplied value.
        /// </summary>
        public void setRecogManualSelection(int val)
        {
            mRecogManualSel = val;
        }
 
        /// <summary>
        /// Sets the parameter <c>NumMatches</c> to the supplied value.
        /// </summary>
        public void setInspectMaxNoMatchValue(int val)
        {
            mInspectMaxNoMatch = val;
        }
 
 
        /*******************************************************************/
        /*******************************************************************/           
        
 
        /// <summary>
        /// Checks if the parameter referenced by <c>mode</c> is 
        /// in the auto-mode list, i.e., that it is determined automatically
        /// </summary>
        /// <param name="mode">
        /// Constant starting with AUTO_*, describing one of the parameters
        /// for the auto-mode.
        /// </param>
        public bool isAuto(string mode)
        {
            bool isAuto = false;
 
            switch (mode)
            {
                case AUTO_ANGLE_STEP: 
                    isAuto = paramAuto.Contains(AUTO_ANGLE_STEP);
                    break;
                case AUTO_CONTRAST: 
                    isAuto = paramAuto.Contains(AUTO_CONTRAST);
                    break;
                case AUTO_MIN_CONTRAST: 
                    isAuto = paramAuto.Contains(AUTO_MIN_CONTRAST);
                    break;
                case AUTO_NUM_LEVEL: 
                    isAuto = paramAuto.Contains(AUTO_NUM_LEVEL);
                    break;
                case AUTO_OPTIMIZATION: 
                    isAuto = paramAuto.Contains(AUTO_OPTIMIZATION);
                    break;
                case AUTO_SCALE_STEP: 
                    isAuto = paramAuto.Contains(AUTO_SCALE_STEP);
                    break;
                default: break;
            }
            
            return isAuto;
        }
 
        /// <summary>
        /// Checks if any parameter is registered for automatic 
        /// determination. If not, the call for automatic
        /// determination can be skipped
        /// </summary>
        public bool isOnAuto()
        {
            if( paramAuto.Count > 0 )
                return true;
            else 
                return false;
        }
 
        /// <summary>
        /// Adds the parameter <c>val</c> to the list of parameters that 
        /// will be determined automatically before the application.
        /// </summary>
        /// <param name="val">
        /// Constant starting with AUTO_*, describing one of the parameters
        /// for the auto-mode.
        /// </param>
        /// <returns>
        /// Indicates whether the variable is already in auto-mode or
        /// was added to the auto-list successfully.
        /// </returns>
        public bool setAuto(string val)
        {
            string mode = "";
 
            switch (val)
            {
                case AUTO_ANGLE_STEP: 
                    if(!paramAuto.Contains(AUTO_ANGLE_STEP))
                        mode = AUTO_ANGLE_STEP;
                    break;
                case AUTO_CONTRAST: 
                    if(!paramAuto.Contains(AUTO_CONTRAST))
                        mode = AUTO_CONTRAST;
                    break;
                case AUTO_MIN_CONTRAST: 
                    if(!paramAuto.Contains(AUTO_MIN_CONTRAST))
                        mode = AUTO_MIN_CONTRAST;
                    break;
                case AUTO_NUM_LEVEL: 
                    if(!paramAuto.Contains(AUTO_NUM_LEVEL))
                        mode = AUTO_NUM_LEVEL;
                    break;
                case AUTO_OPTIMIZATION: 
                    if(!paramAuto.Contains(AUTO_OPTIMIZATION))
                        mode = AUTO_OPTIMIZATION;
                    break;
                case AUTO_SCALE_STEP: 
                    if(!paramAuto.Contains(AUTO_SCALE_STEP))
                        mode = AUTO_SCALE_STEP;
                    break;
                default: break;
            }
            
            if(mode == "")
                return false;
            
            paramAuto.Add(mode);
            return true;
        }
 
        /// <summary>
        /// Removes the parameter <c>val</c> from the list of parameters that 
        /// will be determined automatically.
        /// </summary>
        /// <param name="val">
        /// Constant starting with AUTO_*, describing one of the parameters for
        /// the auto-mode.
        /// </param>
        /// <returns>
        /// Indicates if the variable was removed from the 
        /// auto-list successfully.
        /// </returns>
        public bool removeAuto(string val)
        {
            string mode = "";
 
            switch (val)
            {
                case AUTO_ANGLE_STEP: 
                    if(paramAuto.Contains(AUTO_ANGLE_STEP))
                        mode = AUTO_ANGLE_STEP;
                    break;
                case AUTO_CONTRAST: 
                    if(paramAuto.Contains(AUTO_CONTRAST))
                        mode = AUTO_CONTRAST;
                    break;
                case AUTO_MIN_CONTRAST: 
                    if(paramAuto.Contains(AUTO_MIN_CONTRAST))
                        mode = AUTO_MIN_CONTRAST;
                    break;
                case AUTO_NUM_LEVEL: 
                    if(paramAuto.Contains(AUTO_NUM_LEVEL))
                        mode = AUTO_NUM_LEVEL;
                    break;
                case AUTO_OPTIMIZATION: 
                    if(paramAuto.Contains(AUTO_OPTIMIZATION))
                        mode = AUTO_OPTIMIZATION;
                    break;
                case AUTO_SCALE_STEP: 
                    if(paramAuto.Contains(AUTO_SCALE_STEP))
                        mode = AUTO_SCALE_STEP;
                    break;
                default: break;
            }
            
            if(mode == "")
                return false;
            
            paramAuto.Remove(mode);
            return true;
        }
 
        /// <summary>
        /// Gets the names of the parameters to be determined
        /// automatically
        /// </summary>
        /// <returns>
        /// List of parameter names being in auto-mode.
        /// </returns>
        public string [] getAutoParList()
        {
            int count = paramAuto.Count;
            string [] paramList = new string[count];
 
            for(int i=0; i<count; i++)
                paramList[i] = (string)paramAuto[i]; 
        
            return paramList;
        }
 
    }//end of class
}//end of namespace