Ask Your Question
1

Recognising an ID card and calculating its width and height

asked 2014-07-22 05:47:06 -0600

Joshy gravatar image

​Hi all,

This my first time posting to this mailing list, so if I am doing something wrong, please say so kindly...

My aim is to correctly segment a simple photograph of a person holding up an ID card, recognise the card, and then calculate its width and height in mm, using OpenCV.

So far, I thought I should:

  • convert the colour image to a gray-scale image
  • apply a Gaussian Blur filter of 5x5 to remove noise
  • find the vertical edges of the card by using a Sobel filter
  • apply a threshold filter to obtain a binary image with a threshold value obtained through Otsu's method

This is as far as I have got so far, but the results are not looking good... Is this the way to go?

int main( int argc, const char** argv )
{
   Mat img = imread( argv[1] );

   if ( !img.data )
   {
      cout << "No image exists!" << endl;
      return 1;
   }

   Mat gray;
   cvtColor( img, gray, CV_BGR2GRAY );

   blur( gray, gray, Size(5,5) );

   Mat sobled;
   Sobel( gray, sobled, CV_8U, 1, 0, 3, 1, 0 );

   Mat threshed;
   threshold( sobled, threshed, 0, 255, CV_THRESH_OTSU+CV_THRESH_BINARY );

   imshow( "Threshold Image", sobled );
   waitKey( 0 );
   system( "pause" );
}
edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
3

answered 2014-07-22 06:26:09 -0600

I saw this paper/algorithm some time ago. It was about detecting markers for augmented reality applications. I think you could adapt this algorithm in order to detect cards, because detecting a card is more ore less like detecting a marker in an image.

So I recommend you to read this paper:

Marker Detection for Augmented Reality Applications

Blog and source code

Algorithm:

  1. Divide image in regions
  2. Detect edgels in regions
  3. Find segments in regions
  4. Merge segments to lines
  5. Extend lines along edges
  6. Keep lines with corners
  7. Find markers (cards)

Hope this helps

edit flag offensive delete link more

Question Tools

3 followers

Stats

Asked: 2014-07-22 05:47:06 -0600

Seen: 5,677 times

Last updated: Jul 22 '14