Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Recognising an ID card and calculating its width and height

​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" );
}