Template matching method and device under complex lighting conditions
By acquiring template images and matching region information under complex lighting conditions, and performing lighting detection and enhancement processing, the problems of long template matching time and poor robustness are solved, achieving efficient and accurate material feature localization.
Patent Information
- Application Number
- CN202310235299.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-13
- Publication Date
- 2025-11-07
- Estimated Expiration
- 2043-03-13
AI Technical Summary
Existing template matching methods are time-consuming under complex lighting conditions and are easily affected by external environmental factors, making it difficult to meet the robustness requirements of real-time production.
By acquiring template images and matching region information, illumination detection and enhancement processing are performed. Template matching is only performed within the matching region. Illumination conditions are optimized using illumination prediction models and particle swarm optimization algorithms to improve matching accuracy and efficiency.
It effectively reduces invalid searches and calculations, improves the robustness and real-time performance of template matching, reduces dependence on lighting changes, and improves matching accuracy.
Smart Images

Figure CN116188826B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of image processing, in particular to a template matching method and device under complex lighting conditions. BACKGROUND
[0002] In the production process of products, the characteristics of many materials need to be detected and positioned. In the industrial scene, template matching is used to match the images of the materials of the products collected under different shooting conditions to achieve the purpose of positioning the characteristics of the materials. The key to realizing feature positioning by template matching is matching accuracy, which directly affects subsequent image processing and application work.
[0003] The existing template matching method compares the target image and the template image pixel by pixel, calculates the similarity by comparing the mean or variance of the target image and the template image, and positions the similar area. The operation process is relatively simple. However, the existing template matching method belongs to an infinite search process, and it is not targeted for the target. When facing the matching of high-resolution images, there are a large number of invalid search processes and invalid matching calculations, which are extremely time-consuming. In addition, in actual application, the environment of the production workshop is relatively complex. When facing the influence of complex background and light change, the gray value distribution on the surface of the material is uneven, which greatly reduces the matching accuracy and makes it difficult to obtain good matching results. The robustness is poor and cannot meet the requirements of real-time production. SUMMARY
[0004] Therefore, the technical problem to be solved by the present application is to overcome the problems of long matching time and easy interference by external environmental factors of the existing template matching method, so as to provide a template matching method and device under complex lighting conditions.
[0005] To solve the above problems, the embodiment of the present application provides a template matching method under complex lighting conditions, comprising:
[0006] An original material image is obtained, and after preprocessing, a to-be-matched material image is obtained;
[0007] A template image, a template light threshold and matching area information are obtained from a material database;
[0008] A matching area is drawn on the to-be-matched material image according to the matching area information, and a to-be-matched area image is obtained;
[0009] The to-be-matched area image is subjected to light detection according to the template light threshold;
[0010] When the light detection is unqualified, the to-be-matched area image is subjected to light enhancement processing, and a reconstructed area image is obtained;
[0011] Template matching the template image with the post-reconstruction region image to obtain a matching result to complete material feature positioning.
[0012] Optionally, before the template image, the template light threshold and the matching region information are obtained from the material database, the method further comprises:
[0013] An image of a material marking region is acquired by a camera system to obtain a first image;
[0014] After the first image is cropped, a second image is obtained;
[0015] According to the standard light intensity, it is detected whether the second image is valid;
[0016] If the second image is valid, a template image is obtained after feature point marking of the second image;
[0017] The light intensity of the template image is determined as the template light threshold, and the top-left pixel coordinates and the width and height of the region frame corresponding to the template image are determined as the matching region information;
[0018] The template image, the template light threshold and the matching region information are stored in the material database.
[0019] Optionally, the light detection of the region image to be matched according to the template light threshold comprises:
[0020] After the region image to be matched is cut into a plurality of image blocks, the gray values of the image blocks are obtained;
[0021] The gray values of the image blocks are input into a light prediction model to obtain the corresponding light intensity;
[0022] The weight coefficients of the image blocks are obtained, and the light intensity of the region image to be matched is obtained in combination with the corresponding light intensity;
[0023] It is detected whether the light intensity of the region image to be matched is less than the template light threshold;
[0024] If it is less than, it is determined that the light detection is unqualified; otherwise, it is determined that the light detection is qualified.
[0025] Optionally, the weight coefficients of the image blocks are obtained, comprising:
[0026] The position coordinates of the image blocks in the region image to be matched are obtained;
[0027] The weight coefficients of the image blocks are obtained according to the position coordinates and the size of the image blocks.
[0028] Optionally, the illumination enhancement processing on the to-be-matched region image to obtain a reconstructed region image comprises:
[0029] Edge detection is performed on the to-be-matched region image to extract edge information;
[0030] Region segmentation is performed on the to-be-matched region image according to the edge information to obtain a dark region and a bright region;
[0031] Based on the pixel illuminance of the dark region and the bright region, distribution of the dark region in the bright region is analyzed, the least brightness deviation between the dark region and the bright region is searched through a particle swarm algorithm, and the dark region is subjected to illumination enhancement;
[0032] According to the bright region and the dark region subjected to illumination enhancement, a reconstructed region image is obtained.
[0033] Optionally, the region segmentation on the to-be-matched region image according to the edge information to obtain a dark region and a bright region comprises:
[0034] After the edge information is subjected to dilation and corrosion processing, all edge information is traversed through a connected region algorithm, and the largest area contour is screened out to be determined as a material contour;
[0035] Edge detection and connected region analysis are performed again on the image containing the material contour to obtain the largest area contour to be determined as a bright region contour;
[0036] According to the bright region contour, the image containing the material contour is segmented into a dark region and a bright region.
[0037] Optionally, the obtaining of the original material image, after pre-processing, to obtain a to-be-matched material image comprises:
[0038] An image of a material under complex illumination conditions is acquired through a camera system to obtain an original material image;
[0039] The original material image is subjected to grayscale processing to obtain a grayscale image;
[0040] The grayscale image is subjected to denoising through a Gaussian filter to obtain a noise-free image;
[0041] The noise-free image is subjected to binarization processing according to a preset threshold to obtain a to-be-matched material image.
[0042] Optionally, after the illumination detection on the to-be-matched region image according to the template illumination threshold, the method comprises:
[0043] When the illumination detection is qualified, template matching is performed between the template image and the region image to be matched to obtain a matching result, so as to complete the material feature positioning.
[0044] In addition, the embodiment of the present application further provides a template matching device under complex illumination conditions, comprising:
[0045] A material image acquisition module is configured to acquire an original material image and obtain a material image to be matched after pre-processing;
[0046] A template image reading module is configured to acquire a template image, a template illumination threshold and matching region information from a material database;
[0047] A matching region drawing module is configured to draw a matching region on the material image to be matched according to the matching region information to obtain a region image to be matched;
[0048] An illumination detection module is configured to perform illumination detection on the region image to be matched according to the template illumination threshold;
[0049] An illumination enhancement module is configured to perform illumination enhancement processing on the region image to be matched to obtain a reconstructed region image when the illumination detection is unqualified;
[0050] A template matching module is configured to perform template matching between the template image and the reconstructed region image to obtain a matching result, so as to complete the material feature positioning.
[0051] Optionally, the template matching module is further configured to perform template matching between the template image and the region image to be matched to obtain a matching result, so as to complete the material feature positioning when the illumination detection is qualified.
[0052] The template matching method and device under complex illumination conditions provided by the embodiment of the present application have the following beneficial effects:
[0053] 1) The matching region is drawn on the material image to be matched through the matching region information, template matching is only needed in the matching region, complex background interference and matching errors caused by similar features can be avoided, and a large number of invalid search processes and invalid matching calculations are reduced for the region image to be matched with qualified illumination detection;
[0054] 2) For the region image to be matched with unqualified illumination detection, the illumination enhancement processing calibrates the uneven illumination and large brightness change of the material surface image, weakens the influence of illumination change on matching accuracy, solves the problem that the traditional template matching method has high dependence on illumination conditions, and improves the robustness, that is, improves the real-time performance and accuracy of template matching. BRIEF DESCRIPTION OF DRAWINGS
[0055] In order to more clearly illustrate the technical solutions of the present application, the specific embodiments or prior art technical solutions will be described below. It is obvious that the drawings described below are some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative effort.
[0056] Figure 1 An application environment diagram of the template matching method under complex lighting conditions provided by the embodiment of the present application is shown.
[0057] Figure 2 A flowchart of the template matching method under complex lighting conditions provided by the embodiment of the present application is shown.
[0058] Figure 3 A structural schematic diagram of the template matching device under complex lighting conditions provided by the embodiment of the present application is shown. DETAILED DESCRIPTION
[0059] The exemplary embodiments will be described in detail herein below with reference to the drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of apparatuses and methods consistent with some aspects of the present application as detailed in the appended claims.
[0060] In order to illustrate the technical solutions of the present application, specific embodiments will be described below.
[0061] The template matching method under complex lighting conditions provided by the embodiment of the present application can be applied in the application environment as shown in Figure 1 , wherein the client and the camera system communicate with the server; the client includes computer devices such as desktop computers, notebook computers, mobile personal computers, personal digital assistants (PDA), etc.; the camera system is used to collect material images; and the server can be implemented by an independent server or a server cluster composed of multiple servers.
[0062] As shown in Figure 2 , a flowchart of the template matching method under complex lighting conditions provided by the embodiment of the present application is shown, wherein the template matching method under complex lighting conditions is applied in Figure 1The server is connected to a corresponding material database by a computer device to obtain a template image in the material database. The computer device can also be connected to a corresponding client, which is operated by a user. The user can send an image acquisition instruction to the server through the client to control the camera system to acquire a material image. As shown in Figure 2 The template matching method under complex lighting conditions specifically includes the following steps:
[0063] S10, an original material image is acquired, and a preprocessed material image is obtained.
[0064] In step S10, at least one original material image is acquired by collecting the material under different shooting conditions, and a preprocessed material image is obtained after the original material image is preprocessed. Different shooting conditions include different times, angles, and lighting conditions. Preprocessing includes grayscale, filtering, and binarization.
[0065] As a preferred embodiment, step S10 can include the following steps:
[0066] S101, an original material image is acquired by collecting the material under complex lighting conditions through a camera system;
[0067] S102, a grayscale image is obtained by performing grayscale processing on the original material image;
[0068] S103, a noise-free image is obtained by performing noise reduction on the grayscale image through a Gaussian filter;
[0069] S104, a preprocessed material image is obtained by performing binarization processing on the noise-free image according to a preset threshold.
[0070] In this embodiment, the server receives an image acquisition instruction sent from the client, starts the camera system, shoots the material under complex lighting conditions, and obtains an original material image. After grayscale processing, noise reduction, and binarization processing, a preprocessed material image is obtained. It can be understood that the original material image is preprocessed to effectively remove interference under strong light conditions.
[0071] S20, a template image, a template lighting threshold, and matching region information are obtained from a material database.
[0072] In step S20, the material database stores at least one template image, a template light threshold corresponding to the template image, and matching region information. Optionally, the number of template images in the material database is set according to the number of selected features on the material; the template image is a pre-acquired grayscale image containing feature point markers; the template light threshold is set according to the light intensity of the template image; and the matching region information includes the top-left pixel coordinates of the matching region frame and the width and height of the matching region frame.
[0073] As a preference, step S20 includes the following steps:
[0074] S201, acquiring a first image by image acquisition of a material marker region through a camera system;
[0075] S202, obtaining a second image after cropping the first image;
[0076] S203, detecting whether the second image is valid according to a standard light intensity;
[0077] S204, if the second image is valid, obtaining a template image after feature point marking of the second image;
[0078] S205, determining the light intensity of the template image as a template light threshold, and determining the top-left pixel coordinates and the width and height of the region frame corresponding to the template image as matching region information;
[0079] S206, storing the template image, the template light threshold, and the matching region information to a material database.
[0080] S207, if the second image is invalid, returning to step S201 to re-acquire the first image.
[0081] In this embodiment, the standard light intensity is set according to requirements.
[0082] Specifically, a material marker region containing four calibration points and a center point is first set, and the material marker region is photographed by a pre-set photographing mode to obtain a first image. Optionally, the pre-set photographing mode is to first photograph the material marker region directly above the center point at a height of 1 meter, and then photograph the material marker region at an angle of 45 degrees around the material marker region.
[0083] After the first image is obtained, the first image is cropped to obtain a second image, and the gray values of each pixel point in the second image are analyzed and processed by a pre-trained light prediction model to obtain the light intensity of the second image. Optionally, the light prediction model is a commonly used deep neural network.
[0084] Then, it is detected whether the light intensity of the second image is greater than or equal to the standard light intensity. If yes, it is determined that the second image is valid. After feature point extraction and feature point marking of the second image, a template image containing the feature marking points is obtained and stored in the material database. Meanwhile, the light intensity of the template image is taken as a template light threshold value, and the top-left pixel coordinates and width and height of the matching region frame are taken as matching region information and are stored in the material database in association. If no, it is determined that the second image is invalid, and the corresponding first image is re-collected.
[0085] It can be understood that, by clipping and effective detection of the first image, the embodiment can realize acquisition of an effective template image.
[0086] S30, a matching region is drawn on the to-be-matched material image according to the matching region information, to obtain a to-be-matched region image.
[0087] Specifically, a matching region is established on the to-be-matched material image according to the top-left pixel coordinates and width and height of the matching region frame contained in the matching region information, so as to complete drawing of the matching region. In subsequent steps, only the matching region is processed and matched, which can not only exclude interference items, but also reduce a large number of invalid search processes and invalid matching calculations.
[0088] S40, light detection is performed on the to-be-matched region image according to the template light threshold value.
[0089] In step S40, the light intensity of the to-be-matched region image is first acquired, and then it is detected whether the light intensity of the to-be-matched region image is less than the template light threshold value. If yes, it is determined that the light detection is unqualified. At this time, step S50 of light enhancement processing can be entered to solve the problem of uneven light of the to-be-matched region image. Otherwise, it is determined that the light detection is qualified. At this time, step S70 of template matching can be entered.
[0090] As a preferred, the step S40 comprises the following steps:
[0091] S401, after the to-be-matched region image is divided into a plurality of image blocks, the gray values of the image blocks are acquired;
[0092] S402, the gray values of the image blocks are input into a light prediction model to obtain corresponding light intensities;
[0093] S403, weight coefficients of the image blocks are acquired, and the light intensities of the image blocks are combined to obtain the light intensity of the to-be-matched region image.
[0094] S404, it is detected whether the light intensity of the to-be-matched region image is less than the template light threshold value;
[0095] S405, if less, then determine that the illumination detection is unqualified; otherwise, determine that the illumination detection is qualified.
[0096] Further, the step S403 of obtaining the weight coefficient of each image block can include the following steps:
[0097] First, obtain the position coordinates of the image block in the image of the to-be-matched region ; then, obtain the weight coefficient of the image block according to the position coordinates and the size of the image block . The weight coefficient of the image block can be represented as:
[0098] ,
[0099] In the above formula, w is the weight coefficient of the image block, w x and w y are the weight coefficients of the image block in the first direction and the second direction respectively, and can be represented as:
[0100] , .
[0101] In the process of illumination detection, first, the image of the to-be-matched region obtained by the preprocessing in step S10 is divided into blocks to obtain N image blocks, the number of image blocks N is set according to requirements, and N≥1.
[0102] After the division, the pixel gray value in each image block is analyzed and processed by the illumination prediction model obtained by pre-training to obtain the illumination intensity of each image block; then, the illumination intensity of the image of the to-be-matched region is calculated according to the weight coefficient and the illumination intensity of each image block, and the calculation formula can be:
[0103] ,
[0104] In the above formula, I is the illumination intensity of the image of the to-be-matched region, w n is the weight coefficient of the n th image block, and I n is the illumination intensity of the n th image block.
[0105] After obtaining the illumination intensity of the region image to be matched, if the illumination intensity of the region image to be matched is less than the template illumination threshold, it is determined that the illumination detection is unqualified, and if the illumination intensity of the region image to be matched is greater than or equal to the template illumination threshold, it is determined that the illumination detection is qualified.
[0106] It can be understood that, by using the weight coefficient of the image block and the illumination intensity predicted by the illumination prediction model to predict the illumination intensity of the region image to be matched, the accuracy of image illumination analysis can be improved, and thus the reliability of the illumination detection result can be ensured.
[0107] S50, when the illumination detection is unqualified, performing illumination enhancement processing on the region image to be matched to obtain a reconstructed region image.
[0108] In this embodiment, the existing low-illumination image enhancement network, such as the convolutional neural network RetinexNet, can be used to implement the illumination enhancement of the region image to be matched. The convolutional neural network RetinexNet is divided into two parts, a Decom-Net network for image decomposition and an Enhance-NET network for illumination adjustment. The implementation process of the convolutional neural network RetinexNet includes three stages of image decomposition, brightness adjustment and image reconstruction. In the image decomposition stage, the Decom-Net network decomposes the input image into a reflectance image and an illumination image, and the weights of the two parts are shared. In the brightness adjustment stage, an Enhance-NET based on a coding and decoding structure is used to enhance the illumination of the illumination image, and a denoising operation is performed on the reflectance image. In the image reconstruction stage, the illumination-enhanced illumination image and the denoised reflectance image are combined to form a final enhanced image, and a reconstructed region image is obtained.
[0109] Since the low-illumination image enhancement network needs a computer with high hardware configuration to support its training and testing, resulting in increased cost, in order to reduce the hardware cost, in another embodiment, the edge features of the image are extracted for image segmentation, and the particle swarm algorithm is used to search for the minimum brightness deviation of the dark area and the bright area, so as to perform illumination enhancement according to the minimum brightness deviation. At this time, the step S50 of performing illumination enhancement processing on the region image to be matched to obtain a reconstructed region image specifically includes the following steps:
[0110] S501, performing edge detection on the region image to be matched to extract edge information.
[0111] In step S501, the Sobel edge detection algorithm can be used to extract the edge information of the region image to be matched. The extraction process of the edge information can be represented as:
[0112] ,
[0113] wherein, is the extracted edge information, is the input region image to be matched, , are respectively a horizontal direction convolution kernel and a vertical direction convolution kernel in a Sobel edge detection algorithm, and can be expressed as:
[0114] , .
[0115] S502, regionally segmenting the region image to be matched according to the edge information to obtain a dark region and a bright region.
[0116] As a preference, the step S502 can include the following steps:
[0117] S5021, after dilating and eroding the edge information, traversing all the edge information through a connected region algorithm to screen out a largest-area contour to determine as a material contour;
[0118] S5022, performing edge detection and connected region analysis again on the image containing the material contour to obtain a largest-area contour to determine as a bright region contour;
[0119] S5023, segmenting the image containing the material contour into the dark region and the bright region according to the bright region contour.
[0120] In the process of region segmentation, first, after dilating and eroding the edge information extracted in the step S501, the connected region algorithm is adopted to analyze the connection between the edge information to determine which edge information belongs to the same object, so as to connect them to form a connected region contour, and then the largest-area connected region contour is screened out as the material contour.
[0121] Then, the edge detection and the connected region analysis are repeatedly performed with the material contour, and the largest-area connected region contour is screened out as the bright region contour. At this time, if the bright region contour is represented as , and the image containing the material contour is represented as , the bright region can be expressed as:
[0122] ,
[0123] The dark region can be expressed as:
[0124] ,
[0125] Thus, the segmentation of the bright region and the dark region is completed.
[0126] S503, based on the pixel illuminance of the dark area and the bright area, analyzing the distribution of the dark area in the bright area, searching the minimum brightness deviation between the dark area and the bright area through a particle swarm algorithm, and performing illumination enhancement on the dark area.
[0127] In step S503, first, according to the pixel illuminance of each region in the region image to be matched, the minimum brightness difference between the dark region and the bright region in the image is automatically obtained by using the particle swarm algorithm. More specifically, in the particle swarm algorithm, each region in the region image to be matched is taken as a particle, and the position and speed of each particle are randomly initialized. Next, in each iteration, the state of each particle is updated according to the current position and speed of each particle. In the process of updating the state, by comparing the brightness difference between different particles, it can be determined which particles are in the dark region and which particles are in the bright region. Next, according to this information, the minimum brightness deviation between the dark region and the bright region is calculated.
[0128] Then, according to the minimum brightness deviation between the dark region and the bright region, the dark region is enhanced by illumination, and the calculation formula can be represented as:
[0129]
[0130] wherein, is the dark region enhanced by illumination, is the mean value of the dark region, is the standard deviation of the bright region, is the standard deviation of the dark region, is the brightness deviation.
[0131] S504, according to the bright area and the dark area enhanced by illumination, obtaining the reconstructed region image.
[0132] That is, according to the dark region enhanced by illumination and the bright region, the region image is reconstructed to obtain the reconstructed region image with good illumination.
[0133] It can be understood that, in this embodiment, the dark region segmentation can be realized by edge detection and connected region analysis, and further the minimum brightness deviation between the dark region and the bright region is searched through the particle swarm algorithm, and the dark region is enhanced by illumination according to the minimum brightness deviation, which reduces the calculation amount and is beneficial to improve the processing efficiency of illumination enhancement. In addition, compared with illumination enhancement through low-light image enhancement network, in actual material processing, the computer device does not need high hardware configuration, and good effect can be achieved to meet the production needs.
[0134] In an optional embodiment, after the step S50, the method further comprises:
[0135] The counter associated with the light enhancement processing is started, and the step S40 of detecting light for the reconstructed region image is returned. If the light detection is qualified, the step S60 is entered. Otherwise, the step S50 of re-performing the light enhancement processing is entered, and when the value of the counter reaches a preset threshold, it is determined that the matching fails, and the material image is re-acquired. Optionally, the preset threshold is set to 3 times.
[0136] It can be understood that, by using the counter, the region image to be matched can be prevented from being trapped in the light enhancement processing stage, and the matching failure can be found in time.
[0137] S60, template matching is performed between the template image and the reconstructed region image to obtain a matching result, so as to complete the material feature positioning.
[0138] In the step S60, the matching result is the coordinate position of the matching region.
[0139] As preferred, the step S60 includes the following steps:
[0140] S601, sliding search is performed in the reconstructed region image by using the template image, and a matching degree matrix is generated according to the matching degree between each covered region and the template;
[0141] S602, the minimum matching degree is obtained from the matching degree matrix, and the matching result is obtained according to the position coordinates of the covered region corresponding to the minimum matching degree.
[0142] In the embodiment, the template image obtained in the step S20 is The reconstructed region image obtained in the step S60 is Sliding search is performed in the reconstructed region image by using the template image, and the region of the reconstructed region image covered by the template image is taken as a covered region sub-image The matching degree between each covered region sub-image and the template image is calculated, so as to obtain the matching degree matrix. The matching degree may be expressed as:
[0143] ,
[0144] wherein, is the position serial number of the top-left point of the covered region sub-image on the reconstructed region image; is the size of the template image; is the size of the reconstructed region image; is the coordinate of the pixel point, and , To reconstruct the similarity of the post area image and the template image on the pixel point.
[0145] After obtaining the matching degree matrix, the minimum matching degree is obtained from the matching degree matrix , and the matching result is obtained according to the position coordinates of the covered area subgraph corresponding to the minimum matching degree, so as to complete the material feature positioning task.
[0146] Further, as Figure 2 shown, after step S40, the template matching method under complex lighting conditions further comprises the following steps:
[0147] S70, when the light detection is qualified, the template image is matched with the to-be-matched area image to obtain a matching result, so as to complete the material feature positioning.
[0148] In summary, the template matching method under complex lighting conditions provided by the embodiment of the application has the following beneficial effects:
[0149] 1) By matching the area information on the to-be-matched material image, the matching area is drawn, and only the template matching in the matching area is required, which can avoid the matching errors caused by complex background interference and similar features, and at the same time, for the to-be-matched area image qualified by light detection, a large number of invalid search processes and invalid matching calculations are reduced.
[0150] 2) For the to-be-matched area image unqualified by light detection, the light enhancement processing is used to calibrate the uneven light and large brightness change of the material surface image, which weakens the influence of light change on the matching accuracy, solves the problem that the traditional template matching method is highly dependent on the light condition, and improves the robustness, that is, improves the real-time and accuracy of the template matching.
[0151] In addition, as Figure 3 shown, the embodiment of the application further provides a structural diagram of a template matching device under complex lighting conditions, which comprises:
[0152] A material image acquisition module 110 is used to acquire an original material image, and obtain a to-be-matched material image after preprocessing.
[0153] A template image reading module 120 is used to acquire a template image, a template light threshold and matching area information from a material database.
[0154] A matching area drawing module 130 is used to draw a matching area on the to-be-matched material image according to the matching area information, and obtain a to-be-matched area image.
[0155] The illumination detection module 140 is configured to perform illumination detection on the region image to be matched according to the template illumination threshold value.
[0156] The illumination enhancement module 150 is configured to perform illumination enhancement processing on the region image to be matched when the illumination detection is unqualified, to obtain a reconstructed region image.
[0157] The template matching module 160 is configured to perform template matching between the template image and the reconstructed region image, to obtain a matching result, so as to complete the material feature positioning.
[0158] In some optional embodiments, the template matching module is further configured to, when the illumination detection is qualified, perform template matching between the template image and the region image to be matched, to obtain a matching result, so as to complete the material feature positioning.
[0159] In some optional embodiments, the material image acquisition module 110 comprises:
[0160] The original image acquisition submodule is configured to acquire an original material image by performing image acquisition on the material under complex illumination conditions through a camera system.
[0161] The grayscale submodule is configured to perform grayscale processing on the original material image, to obtain a grayscale image.
[0162] The denoising submodule is configured to perform denoising on the grayscale image through a Gaussian filter, to obtain a noise-free image.
[0163] The binarization module is configured to perform binarization processing on the noise-free image according to a preset threshold value, to obtain a material image to be matched.
[0164] In some optional embodiments, the template matching device under complex illumination conditions further comprises:
[0165] The first image acquisition module is configured to acquire a first image by performing image acquisition on a material mark region through a camera system.
[0166] The image cropping submodule is configured to acquire a second image after cropping the first image.
[0167] The image validity detection module is configured to detect whether the second image is valid according to a standard illumination intensity.
[0168] The information processing module is configured to, if the second image is valid, determine the second image as a template image and perform feature point marking; determine the illumination intensity of the template image as a template illumination threshold value, and determine the top-left pixel coordinates and the width and height of the region frame corresponding to the template image as matching region information.
[0169] A database construction module is configured to store the template image, the template illumination threshold and the matching region information into a material database.
[0170] In some optional embodiments, the illumination detection module 140 comprises:
[0171] An image segmentation submodule is configured to obtain the gray value of each image block after cutting the image of the region to be matched into a plurality of image blocks.
[0172] An image block illumination prediction submodule is configured to input the gray value of each image block into an illumination prediction model to obtain the corresponding illumination intensity.
[0173] A region image illumination processing submodule is configured to obtain the weight coefficient of each image block and combine the corresponding illumination intensity to obtain the illumination intensity of the image of the region to be matched.
[0174] An illumination detection submodule is configured to detect whether the illumination intensity of the image of the region to be matched is less than the template illumination threshold. If yes, it is determined that the illumination detection is unqualified; otherwise, it is determined that the illumination detection is qualified.
[0175] In an optional embodiment, the region image illumination processing submodule comprises:
[0176] An image block weight coefficient obtaining unit is configured to obtain the position coordinates of the image block in the image of the region to be matched; and obtain the weight coefficient of the image block according to the position coordinates and size of the image block.
[0177] In an optional embodiment, the illumination enhancement module 150 comprises:
[0178] An edge detection submodule is configured to perform edge detection on the image of the region to be matched to extract edge information.
[0179] A region segmentation submodule is configured to perform region segmentation on the image of the region to be matched according to the edge information to obtain a dark region and a bright region.
[0180] An illumination enhancement submodule is configured to analyze the distribution of the dark region in the bright region based on the pixel luminance of the dark region and the bright region, search for the minimum brightness deviation between the dark region and the bright region by using a particle swarm algorithm, and perform illumination enhancement on the dark region.
[0181] A region image reconstruction submodule is configured to obtain a reconstructed region image according to the bright region and the dark region after illumination enhancement.
[0182] In an optional embodiment, the region segmentation submodule comprises:
[0183] The connected region analysis unit traverses all the edge information through a connected region algorithm after dilating and eroding the edge information, and screens out the largest area contour as the material contour;
[0184] The bright area determination unit is used for performing edge detection and connected region analysis on the image containing the material contour again, and determining the largest area contour as the bright area contour;
[0185] The dark area segmentation unit is used for segmenting the image containing the material contour into the dark area and the bright area according to the bright area contour.
[0186] The template matching device under complex illumination conditions provided by the embodiment of the present application is used for implementing the template matching method under complex illumination conditions, and has the beneficial effects of the method embodiments, which will not be described herein.
[0187] It should be noted that, in the description of the present application, the terms "first", "second", etc. are only used for the purpose of description, and cannot be understood as indicating or implying relative importance. In addition, in the description of the present application, unless otherwise specified, the meaning of "a plurality of" is at least two.
[0188] The above is only the preferred embodiment of the present application, and does not limit the present application in any form. Although the present application has been disclosed as above with the preferred embodiment, it is not intended to limit the present application. Any person skilled in the art can make some changes or modifications to the above disclosed technical content without departing from the scope of the technical solution of the present application, and any equivalent embodiments with equivalent changes are equivalent. Any brief introduction, modification, equivalent change and modification of the above embodiments made according to the technical essence of the present application, which does not depart from the technical solution of the present application, still belongs to the scope of the technical solution of the present application.
Claims
1. A method of template matching under complex lighting conditions, characterized by, The method comprises the following steps: An original material image is acquired, and after preprocessing, a to-be-matched material image is obtained; A template image, a template light threshold and matching area information are acquired from a material database; A matching area is drawn on the to-be-matched material image according to the matching area information, and a to-be-matched area image is obtained; Light detection is performed on the to-be-matched area image according to the template light threshold; When the light detection is unqualified, light enhancement processing is performed on the to-be-matched area image, and a reconstructed area image is obtained; Template matching is performed between the template image and the reconstructed area image, and a matching result is obtained, so as to complete material feature positioning; The light enhancement processing on the to-be-matched area image to obtain the reconstructed area image comprises the following steps: Edge detection is performed on the to-be-matched area image to extract edge information; Region segmentation is performed on the to-be-matched area image according to the edge information, and a dark area and a bright area are obtained; Based on the pixel illuminance of the dark area and the bright area, the distribution of the dark area in the bright area is analyzed, the minimum brightness deviation between the dark area and the bright area is searched through a particle swarm algorithm, and the dark area is subjected to light enhancement; According to the bright area and the dark area subjected to light enhancement, a reconstructed area image is obtained; The region segmentation on the to-be-matched area image according to the edge information to obtain the dark area and the bright area comprises the following steps: After dilation and corrosion processing of the edge information, all edge information is traversed through a connected region algorithm, and the largest area contour is selected as a material contour; Edge detection and connected region analysis are performed again on the image containing the material contour, and the largest area contour is selected as a bright area contour; According to the bright area contour, the image containing the material contour is segmented into a dark area and a bright area.
2. The template matching method under complex lighting conditions according to claim 1, characterized in that, Before the acquisition of the template image, the template light threshold and the matching area information from the material database, the method further comprises the following steps: An image of a material marking area is acquired through a camera system, and a first image is obtained; After cropping the first image, a second image is obtained; Whether the second image is valid is detected according to a standard light intensity; If the second image is valid, a template image is obtained after feature point marking of the second image; The light intensity of the template image is determined as the template light threshold, and the top-left pixel coordinates and the width and height of the region frame corresponding to the template image are determined as the matching area information; The template image, the template light threshold and the matching area information are stored in a material database.
3. The template matching method under complex lighting conditions according to claim 1, characterized in that, The light detection on the to-be-matched area image according to the template light threshold comprises the following steps: After the to-be-matched area image is divided into a plurality of image blocks, the gray values of the image blocks are acquired; The gray values of the image blocks are input into a light prediction model, and corresponding light intensities are obtained; The weight coefficients of the image blocks are acquired, and the light intensities of the to-be-matched area image are obtained in combination with the corresponding light intensities; Whether the light intensity of the to-be-matched area image is less than the template light threshold is detected. If less, it is determined that the illumination detection is unqualified; otherwise, it is determined that the illumination detection is qualified.
4. The template matching method under complex lighting conditions according to claim 3, characterized in that, The weight coefficient of each image block is obtained, including: The position coordinates of the image block in the to-be-matched region image are obtained; The weight coefficient of the image block is obtained according to the position coordinates and size of the image block.
5. The template matching method under complex lighting conditions according to claim 1, characterized in that, The original material image is obtained, and the to-be-matched material image is obtained after preprocessing, including: An original material image is obtained by a camera system for image acquisition of a material under complex illumination conditions; A grayscale image is obtained by grayscale processing of the original material image; A noise-free image is obtained by denoising the grayscale image through a Gaussian filter; A to-be-matched material image is obtained by binarization processing of the noise-free image according to a preset threshold.
6. The template matching method under complex lighting conditions according to claim 1, characterized in that, After the illumination detection of the to-be-matched region image according to the template illumination threshold, including: When the illumination detection is qualified, template matching is performed between the template image and the to-be-matched region image to obtain a matching result, so as to complete material feature positioning.
7. A device for template matching under complex lighting conditions, characterized by Including: A material image acquisition module is configured to obtain an original material image, and obtain a to-be-matched material image after preprocessing; A template image reading module is configured to obtain a template image, a template illumination threshold and matching region information from a material database; A matching region drawing module is configured to draw a matching region on the to-be-matched material image according to the matching region information to obtain a to-be-matched region image; An illumination detection module is configured to perform illumination detection on the to-be-matched region image according to the template illumination threshold; An illumination enhancement module is configured to perform illumination enhancement processing on the to-be-matched region image when the illumination detection is unqualified to obtain a reconstructed region image; The illumination enhancement module includes: An edge detection submodule is configured to perform edge detection on the to-be-matched region image to extract edge information; A region segmentation submodule is configured to perform region segmentation on the to-be-matched region image according to the edge information to obtain a dark region and a bright region; The region segmentation submodule includes: A connected region analysis unit is configured to perform inflation and corrosion processing on the edge information, traverse all edge information through a connected region algorithm, and screen out the largest contour as a material contour; A bright region determination unit is configured to perform edge detection and connected region analysis on the image containing the material contour again, obtain the largest contour as a bright region contour, and determine the bright region; A dark region segmentation unit is configured to segment the image containing the material contour into a dark region and a bright region according to the bright region contour; An illumination enhancement submodule is configured to analyze the distribution of the dark region in the bright region based on the pixel illuminance of the dark region and the bright region, search for the minimum brightness deviation between the dark region and the bright region through a particle swarm algorithm, and perform illumination enhancement on the dark region; A region image reconstruction submodule is configured to obtain a reconstructed region image according to the bright region and the dark region after illumination enhancement; A template matching module is configured to perform template matching between the template image and the reconstructed region image to obtain a matching result, so as to complete material feature positioning.
8. The device for template matching under complex lighting conditions according to claim 7, characterized in that, The template matching module is further configured to, when the light detection is qualified, perform template matching between the template image and the region image to be matched to obtain a matching result, so as to complete material feature positioning.
Citation Information
Patent Citations
Method and system for detecting whether part is missing or not under condition of uneven illumination
CN115587966A
Method for facial features detection
EP1693782A1