I want to detect a credit card sized card in image. The card can be any card eg identity card, member card. Currently, I am thinking to use Canny Edge, Hough Line and Hough Circle to detect the card. But the process will be tedious when I want to combine all the information of Hough Line and Hough Circle to locate the card. Some people suggest threshold and findContour but the color of card can be similar to the background which make this method difficult to achieve the desired result. Is there any kernel and method which can help me to detect the card?
I think, your problem is similar to document scanner. You can refer to this link
Find edges in the image using Canny edge detector (lower and higher thresholds can be set as 0.66*meanIntensity and 1.33*meanIntensity) and do a morphological close operation.
Edge image after performing close
Find the contours in the image using findContours
filterout unwanted contours (I used contourArea to filter contours)
using approxPolyDP approximate the contours to 7 or more points. (I used 0.005 * perimeter as the parameter here)
If you want to find accurate edges, fit lines between the points and get the 4 biggest lines.Find their intersection (since the card may or may not contain curved edges)
You'll end up with the card endpoints which can be used further for homography or to determine the region.
vertices of the card
Edit Edited the answer to include the steps to obtain the vertices of the card and results are updated.
There are two sub-problems here -
For first part, you can try out several methods to extract rectangular region in the image and see which suits your need.
Coming to the second point, you cannot find out the size of an object in an image unless you have any reference(known) sized object in the image. If the image was captured from a closer distance, the card will seem larger and if taken from far, the card will seem smaller. So while capturing, you will have to enforce some restrictions like you can ask the user to capture image along with some standard ruler. You can also ask the user to capture image on an A4 sheet with all the sheet edges visible. Since, you know the size of the A4 sheet, you'll be able to estimate the size of the card.
Apart from above methods, if you have enough data set of such images, you can use Haar Classifiers or Neural Network/Deep Learning based methods to do this with much better accuracy.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With