In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how C++ OpenCV realizes offline ID card recognition. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
The main technology of OpenCV ID card offline recognition technology is to find the ID card number area through OpenCV, and then get the ID card number by digitally identifying the screenshot of this area through OCR. Local ORC uses tess-two to complete. Tesseract is the OCR engine implemented by C++, which is not very convenient to use in Android. We need to encapsulate JavaAPI in order to call in the Android platform. However, tess-two has done these things for us. By integrating tess-two, we can easily complete character recognition.
General thinking
Image preprocessing
1. Lossless compression
The first problem to be dealt with is that the size of the picture is different, because the pixel of each device or the size of each picture itself is different, and the processing process will be different, so the first problem to be solved is the unity of size. First, the picture is processed into an image of the same size by lossless compression. According to the empirical value (or this is a general method of dealing with documents), the image is first processed to a size of 640 × 400.
2. Graying
Now most color images use RGB color mode. When processing the image, we have to deal with the three components of RGB respectively. In fact, RGB can not reflect the morphological characteristics of the image, but only allocates the color from the optical principle. Image graying processing can be used as a pre-processing step of image processing to prepare for upper-level operations such as image segmentation, image recognition and image analysis.
In fact, you can think about it carefully, if you are dealing with a RGB image, a pixel needs to process three values at the same time, and only one value needs to be processed after graying. If it is a comparison, a RGB pixel has 256x256x256 possibilities, but if it is to compare the pixels of a grayscale image, there are only 256possibilities, with a speed increase of 65536 times, so very often, it is converted to a grayscale image before doing other image processing.
The image graying processing includes component method, maximum method, average method and weighted average method, among which the weighted average method is widely used. Because the human eye is the most sensitive to green and the least sensitive to blue, a more reasonable grayscale image can be obtained by weighted averaging the three components of RGB according to the following formula:
3. Image binarization
After the color picture is grayed out above, the obtained grayscale image is binarized. For binarization, its purpose is to classify the background of the target user and prepare for the subsequent lane recognition. The most commonly used method for binarization of grayscale image is the threshold method, which makes use of the difference between the target and the background in the image, sets the image to two different levels, and selects an appropriate threshold to determine whether a pixel is the target or the background. in order to get a binary image. For example, binarization of an image with a threshold of 100:
F (I, j) =\ left {\ begin {array} {cc} 0, & (\ text {gray})
< = 100) \ 255, & (\text { gray }>End {array}\ right.
4. Expansion and corrosion
Expansion and erosion are the most basic morphological operations in image processing, and morphological operations are a series of image processing operations based on shape. OpenCV provides a fast and convenient function for image morphological transformation. It is mainly used to eliminate noise, segment independent image elements, connect adjacent elements in the image, find obvious maximum or minimum regions in the image, and find out the gradient of the image.
Simply understand, expansion is the operation of finding the local maximum. Corrosion is the operation of finding a local minimum. When dealing with ID cards, we want to connect digital areas such as ID card numbers together, that is, to connect adjacent elements in the image, so we need to use expansion processing, just like the yeast powder of steamed bread. It can be the elements we want to expand and glue together.
5. Contour detection and image segmentation
Through the expansion operation of the image, the ID card number area has been connected together. At present, what we need to do is to detect the outline of the area, which can be done by using Laplace operator. OpenCV also provides findContours function to do contour detection.
So how to divide the ID card number area? In fact, there is a very simple idea, because the ID card number is a string of numbers that do not wrap lines, the aspect ratio is usually greater than 9:1, and it is on the last line. If there are other parts whose aspect ratio is greater than 9:1 but not at the end, then it cannot be considered as an ID card number, only the coordinates are the bottom, and the aspect ratio meets the condition that is greater than 9:1.
Main code
VS2022 + OpenCV4.5.4
# include # define DEFAULT_CARD_WIDTH 640#define DEFAULT_CARD_HEIGHT 400#define FIX_IDCARD_SIZE Size (DEFAULT_CARD_WIDTH, DEFAULT_CARD_HEIGHT) # define FIX_TEMPLATE_SIZE Size (153,28) using namespace std;using namespace cv;int main () {std::cout
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.