0

I have these kind of photos as attached file. I Would like to extract exact position of ID card inside image. Is it possible using OpenCV? I tried following (code is in opencv4nodejs, but I can work with python also:

const src = cv.imread('./970f5b45-9f24-41d5-91f0-ef3f8b9d8914.jpeg');
    
let src2 = src.cvtColor(cv.COLOR_BGR2GRAY)
let dst = src2.adaptiveThreshold(255, cv.ADAPTIVE_THRESH_GAUSSIAN_C, cv.THRESH_BINARY, 12, 2);
let dst2 = dst.morphologyEx(cv.MORPH_OPEN)

After that I have binarized file, and then I applied contours finding using:

    contours = dst.findContours(cv.RETR_TREE,cv.CHAIN_APPROX_SIMPLE)

But result is thousants of really small countours, nothing I can work with. Is possible to somehow extract specific position of card in image? Best would be if I can extract x/y positions of corners, so I can follow/normalize card then. Or if there is another technique in nodejs/python, Iˇm free to learn.

Example image

Kristián Stroka
  • 698
  • 1
  • 8
  • 23
  • hate to say it but "ID card detection" has been discussed countless times (meaning you should google for this). your approach can't be made to work. I generally recommend feature matching. – Christoph Rackwitz May 21 '22 at 18:14
  • You are going to need a lot more than simple thresholding and morphology. – stateMachine May 22 '22 at 06:25
  • I understand, that way is long to find a goal :) ... that is why Iˇm going step by step ... at first i would like to recognize position of ID in photo, that is what Iˇm looking for first :/ – Kristián Stroka May 22 '22 at 07:59
  • HI, @KristiánStroka, did you manage to finish this? Could you have a look at [this SO](https://stackoverflow.com/questions/73076340/extract-rectangular-shape-id-card-area-from-an-image)? – bit_scientist Jul 26 '22 at 04:32
  • Yes I did, but solution was much much much more complicated than just using opencv ... I did train neural network using pytorch, where I train it to find ID cards in images and after that I can annotate images using cv2 and contours ... Iˇm using semantic segmentation which is good in it – Kristián Stroka Jul 28 '22 at 12:08

0 Answers0