Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ExtractMrzRegion.cs
8using System;
9using System.Collections.Generic;
10
12{
16 public static partial class Utilities
17 {
24 {
25 Matrix<float> G = M.GaussianBlur(3);
26 Matrix<float> ForOcr = G = G.BlackHat((13 * M.Width + 208) / 415, (5 * M.Height + 300) / 600);
27 G = G.DetectEdgesSharrVertical(); // Detect vertical edges=detect horizontal changes
28 G.Abs();
29 G.Contrast();
30 G = G.Close((13 * M.Width + 208) / 415, (5 * M.Height + 300) / 600);
31 G.Threshold(G.OtsuThreshold());
32
33 ObjectMap ObjectMap = G.ObjectMap(0.5f);
35
36 Array.Sort(Objects, (o1, o2) => o1.MinY - o2.MinY);
37
38 List<ushort> Found = [];
39
40 foreach (ObjectInformation Object in Objects)
41 {
42 float Aspect = ((float)Object.Width) / Object.Height;
43 if (Aspect < 5)
44 continue;
45
46 float RelativeWidth = ((float)Object.Width) / G.Width;
47 if (RelativeWidth < 0.75f)
48 continue;
49
50 int i = (5 * Math.Max(M.Width, M.Height) + 300) / 600;
51 Point[] Reduced = Object.Contour.Reduce(i);
52 Point[] Reduced2 = Reduced.Reduce(i);
53 if (Reduced2.Length != 4)
54 continue;
55
56 Found.Add(Object.Nr);
57 }
58
59 if (Found.Count == 0)
60 return null;
61
62 Matrix<float> SubRegion = ForOcr.Region((ForOcr.Width - G.Width) / 2, (ForOcr.Height - G.Height) / 2, G.Width, G.Height);
63 return ObjectMap.Extract([.. Found], SubRegion);
64 }
65
72 {
73 Matrix<int> G = M.GaussianBlur(3);
74 Matrix<int> ForOcr = G = G.BlackHat((13 * M.Width + 208) / 415, (5 * M.Height + 300) / 600);
75 G = G.DetectEdgesSharrVertical(); // Detect vertical edges=detect horizontal changes
76 G.Abs();
77 G.Contrast();
78 G = G.Close((13 * M.Width + 208) / 415, (5 * M.Height + 300) / 600);
79 G.Threshold(G.OtsuThreshold());
80
81 ObjectMap ObjectMap = G.ObjectMap(0x800000);
83
84 Array.Sort(Objects, (o1, o2) => o1.MinY - o2.MinY);
85
86 List<ushort> Found = [];
87
88 foreach (ObjectInformation Object in Objects)
89 {
90 float Aspect = ((float)Object.Width) / Object.Height;
91 if (Aspect < 5)
92 continue;
93
94 float RelativeWidth = ((float)Object.Width) / G.Width;
95 if (RelativeWidth < 0.75f)
96 continue;
97
98 //int i = (5 * Math.Max(M.Width, M.Height) + 300) / 600;
99 //Point[] Reduced = Object.Contour.Reduce(i);
100 //Point[] Reduced2 = Reduced.Reduce(i);
101 //if (Reduced2.Length != 4)
102 // continue;
103
104 Found.Add(Object.Nr);
105 }
106
107 if (Found.Count == 0)
108 return null;
109
110 Matrix<int> SubRegion = ForOcr.Region((ForOcr.Width - G.Width) / 2, (ForOcr.Height - G.Height) / 2, G.Width, G.Height);
111 return ObjectMap.Extract([.. Found], SubRegion);
112 }
113 }
114}
Implements a Matrix, basic component for computations in Image Processing and Computer Vision.
Definition: Matrix.cs:12
int Height
Height of matrix (number of rows)
Definition: Matrix.cs:136
int Width
Width of matrix (number of columns)
Definition: Matrix.cs:120
Matrix< T > Region(int Left, int Top, int Width, int Height)
Returns a region of the matrix, as a new matrix.
Definition: Matrix.cs:314
Contains information about an object.
int MinY
Smallest Y-coordinate of bounding box
ushort Nr
Object number in image
Point[] Contour
Contour of the object.
Contains an object map of contents in an image.
Definition: ObjectMap.cs:11
ObjectInformation[] Objects
Objects found in map.
Definition: ObjectMap.cs:341
IMatrix Extract(params ushort[] Nrs)
Extracts one or more objects in the form of image from the underlying image. Only pixels pertaining t...
Definition: ObjectMap.cs:349
Static class for Object Operations, implemented as extensions.
static ? Matrix< float > ExtractMrzRegion(this Matrix< float > M)
Extracts the MRZ region of an image.
static ? Matrix< int > ExtractMrzRegion(this Matrix< int > M)
Extracts the MRZ region of an image.
Represents a point in an image.
Definition: Point.cs:7