Innovative, future-proof software solutions

Innovative, future-proof software solutions

Innovative, future-proof Assessments solutions

Innovative, future-proof Cloud Consulting solutions

Innovative, future-proof Industry types

Innovative, future-proof Products & Offerings
Gray scale image
As we need to detect the borders of ID cards, we can assume that it be rectangular. Going by this assumption there can be 2 ways of detecting borders and both can be used in conjunction.
Id card with outer boundary
ID card border detection
In this approach instead of finding lines, we will find objects at outer most location using FindContours. Contours are the curves joining continuous points with same color and intensity. As we have already applied Canny edge detection, all the objects are marked as lines, thus best suited for FindContours. Its always recommended to use FindContours on binary image.
using (VectorOfVectorOfPoint contours = new VectorOfVectorOfPoint())
{
CvInvoke.FindContours(cannyEdges, contours, null, RetrType.List, ChainApproxMethod.ChainApproxSimple);
.
.
}
Once we get the list of contours, we can filter the contours based on the area to further filter out noise.
for (int i = 0; i < count; i++)
{
using (VectorOfPoint contour = contours[i])
{
using (VectorOfPoint approxContour = new VectorOfPoint())
{
CvInvoke.ApproxPolyDP(contour, approxContour, CvInvoke.ArcLength(contour, true) * 0.05, true);
if (CvInvoke.ContourArea(approxContour, false) < MIN_CONTOUR_AREA) //only consider contours with area greater than 250
continue;
}
var newRect = CvInvoke.MinAreaRect(contour);
var newRectVerices = newRect.GetVertices();
pts[0].X = pts[0].X < newRectVerices[0].X ? pts[0].X : newRectVerices[0].X; pts[0].Y = pts[0].Y > newRectVerices[0].Y ? pts[0].Y : newRectVerices[0].Y;
pts[1].X = pts[1].X < newRectVerices[1].X ? pts[1].X : newRectVerices[1].X;
pts[1].Y = pts[1].Y < newRectVerices[1].Y ? pts[1].Y : newRectVerices[1].Y; pts[2].X = pts[2].X > newRectVerices[2].X ? pts[2].X : newRectVerices[2].X;
pts[2].Y = pts[2].Y < newRectVerices[2].Y ? pts[2].Y : newRectVerices[2].Y; pts[3].X = pts[3].X > newRectVerices[3].X ? pts[3].X : newRectVerices[3].X;
pts[3].Y = pts[3].Y > newRectVerices[3].Y ? pts[3].Y : newRectVerices[3].Y;
}
}
outline = CvInvoke.MinAreaRect(pts);
Using this approach, we can get coordinates of most outer points of the image using which we can create a border.
Once border gets rightly detected, we can accordingly crop the image along the border and thus get a processed image containing only the ID card. If ID card is skewed i.e. rotated by some angle, border will also be rotated by the same angle and since we are creating object of RotatedRectangle it also contains the angle. So, when we crop the image using the rotatedRectangle it removes that angle from the image as well.
var processed = preProcessedImg.Copy(boundary);
Since EmguCV is compatible to be used in Xamarin, Border detection can be used in creating Apps like CamScanner which detects the border and thus allow user to crop the unnecessary part from the image.
Thanks for taking time to read the post. Please let us know if you have any comments or get in touch for any further details you need by dropping us a message here
No posts found.
Connect with Us Today through the Details Below or Fill
Out the Form for a Prompt Response
Guaranteed response within 8 business hours.
We can handle projects of all complexities.
Startups to Fortune 500, we have worked with all.
Top 1% industry talent to ensure your digital success.




