Template matching device and template matching method
The template matching device efficiently processes sparse template matching by extracting and comparing feature and target pixels, overcoming the limitations of existing technologies to achieve faster and more accurate position detection in applications like crime prevention and product inspection.
Patent Information
- Application Number
- PCT/JP2023/013058
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Filing Date
- 2023-03-30
- Publication Date
- 2024-10-03
AI Technical Summary
Existing template matching technologies, such as those described in Japanese Patent Application Publication No. 03-094387, are inefficient in processing sparse template matching due to their inability to effectively refer to sparsified target pixels, limiting their speed and real-time detection capabilities in applications like crime prevention and product inspection.
A template matching device comprising a feature pixel extraction unit, a target pixel extraction unit, a distance calculation unit, and a position detection unit, which extracts and compares feature pixels from a template image with target pixels from an observed image, calculating pixel distances to efficiently detect the position of the template image, thereby speeding up sparse template matching processing.
The proposed solution enables efficient sparse template matching, allowing for real-time detection by simultaneously processing multiple target pixels and feature pixels, enhancing the speed and accuracy of position detection in template matching applications.
Smart Images

Figure JP2023013058_03102024_PF_FP_ABST
Abstract
Description
Template matching device and template matching method
[0001] The present disclosure relates to speeding up template matching.
[0002] Template matching is a technique for detecting the position of a template image from an observed image. The observed image is an image obtained by taking a photograph using a camera or the like. The template image is an image that contains the object to be searched.
[0003] Template matching is used in the following areas: In the fields of crime prevention and security, template matching is used for face recognition or object detection. In factory lines, template matching is used for product inspection.
[0004] By speeding up the template matching process, for example, real-time detection can be realized. To speed up the process, sparse template matching has been proposed. Sparse template matching is a method of making the pixels to be compared sparse.
[0005] Patent Document 1 proposes a circuit configuration for speeding up template matching processing. Specifically, the proposed circuit configuration is capable of simultaneously comparing feature pixels of a template image with multiple target pixels of an observed image.
[0006] Japanese Patent Application Publication No. 03-094387
[0007] The control in Patent Document 1 is a simple control that sequentially references specific pixels to extract target pixels from an observed image. Therefore, the circuit configuration in Patent Document 1 cannot efficiently reference target pixels that have been variously sparsed by sparse template matching. Therefore, the circuit configuration in Patent Document 1 cannot achieve the high speed achieved by sparse template matching.
[0008] The present disclosure aims to achieve high speed through sparse template matching.
[0009] The template matching device of the present disclosure includes: a feature pixel extraction unit that extracts a plurality of feature pixels from a template image; a target pixel extraction unit that extracts, for each extracted feature pixel, a plurality of target pixels from an observed image to be compared with the feature pixel; a distance calculation unit that calculates, for each extracted target pixel, a pixel distance to the extracted plurality of feature pixels; and a position detection unit that detects a position corresponding to the template image from the observed image based on the pixel distance of each target pixel.
[0010] According to the present disclosure, it is possible to achieve high speed through sparse template matching.
[0011] FIG. 1 is a configuration diagram of a template matching device 100 according to the first embodiment. FIG. 2 is a configuration diagram of a pixel comparison unit 120 according to the first embodiment. FIG. 3 is a flowchart of a template matching method according to the first embodiment. FIG. 4 is a flowchart of step S110 according to the first embodiment. FIG. 5 is a flowchart of step S120 according to the first embodiment. FIG. 6 is a configuration diagram of a template matching device 100 according to a second embodiment. FIG. 7 is a configuration diagram of a pixel comparison unit 120 according to the second embodiment. FIG. 8 is a flowchart of a template matching method according to the second embodiment. FIG. 9 is a flowchart of step S220 according to the second embodiment. FIG. 10 is a flowchart of a template matching method according to a third embodiment. FIG. 11 is a flowchart of step S320 according to the third embodiment. FIG. 12 is a hardware configuration diagram of a template matching device 100 according to an embodiment.
[0012] In the embodiments and drawings, the same or corresponding elements are denoted by the same reference numerals. The description of elements denoted by the same reference numerals as those already described will be omitted or simplified as appropriate. Arrows in the drawings primarily indicate the flow of data or the flow of processing.
[0013] First Embodiment A first embodiment of sparse template matching will be described with reference to FIGS.
[0014] ***Configuration Description***
[0015] The configuration of a template matching device 100 will be described with reference to Fig. 1. The template matching device 100 includes elements such as an observed image acquisition unit 110, a pixel comparison unit 120, a position detection unit 130, and an overall control unit 170. The template matching device 100 also includes an element called a storage unit. Specifically, the template matching device 100 includes storage units such as an observed image storage unit 140, a template image storage unit 150, and a coordinate information storage unit 160.
[0016] The components of template matching apparatus 100 are connected to one another via signal lines.
[0017] The configuration of the pixel comparison unit 120 will be described with reference to Fig. 2. The pixel comparison unit 120 includes elements such as a feature pixel extraction unit 121, a target pixel extraction unit 122, and a distance calculation unit 123.
[0018] ***Explanation of Operation*** The procedure of operation of template matching device 100 corresponds to the template matching method.
[0019] The template matching method will be described with reference to Fig. 3. When the template matching device 100 is started, the overall control unit 170 starts the template matching method. In the template matching method, the observed image acquisition unit 110, the pixel comparison unit 120, the position detection unit 130, and various storage units are controlled by the overall control unit 170.
[0020] In step S110, the observed image acquisition unit 110 acquires an observed image. The observed image is an image of a target object, and is obtained by capturing an image of the target object using a photographing device such as a camera. The target object is an object that is the target of template matching.
[0021] The procedure of step S110 will be described with reference to Fig. 4. In step S111, an observed image is input to the template matching device 100 in sequence, one or more pixels at a time. For example, one or more pixels of the observed image are input to the template matching device 100 from a camera. The observed image acquisition unit 110 receives the input observed image.
[0022] In step S112 , the observed image acquisition unit 110 stores the received one or more pixels in the observed image storage unit 140 .
[0023] The observed image acquisition unit 110 also updates the number of times the observed image has been stored by adding 1. The number of times the observed image has been stored is managed using an internal counter. The initial value of the number of times the observed image has been stored is zero.
[0024] In step S113, the observed image acquisition unit 110 determines whether sufficient pixels of the observed image have been stored in the observed image storage unit 140 to perform the template matching method. For example, if the number of stored pixels reaches a threshold, the observed image pixels are sufficiently stored. The threshold is, for example, the number of pixels in the observed image, and is determined in advance. If sufficient pixels of the observed image have not been stored, the process proceeds to step S111. If sufficient pixels of the observed image have been stored, step S110 ends.
[0025] Returning to FIG. 3 , the description continues from step S120. In step S120, the pixel comparison unit 120 calculates the pixel distance for each target pixel in the observed image. The pixel distance is the distance of the target pixel to multiple feature pixels in the template image. The template image is an image that shows a target object and is stored in advance in the template image storage unit 150. The feature pixels are pixels that show feature points and are extracted from the template image. The target pixels are pixels to be compared with the feature pixels and are extracted from the observed image.
[0026] The procedure of step S120 will be described with reference to Fig. 5. In step S121, the feature pixel extraction unit 121 extracts one unextracted feature pixel from the template image. The feature pixel extraction unit 121 then passes the extracted feature pixel to the distance calculation unit 123.
[0027] Feature pixels are extracted as follows. First, the feature pixel extraction unit 121 generates addresses of feature pixels in the template image based on coordinate information and an internal counter for the number of feature pixels. The coordinate information indicates the coordinate values of each of multiple feature pixels in the template image. The coordinate information is specified by the user and is stored in advance in the coordinate information storage unit 160. Then, the feature pixel extraction unit 121 extracts feature pixels from the template image based on the generated addresses.
[0028] The "feature pixel" in step S122 means one feature pixel extracted in step S121.
[0029] In step S122, the target pixel extracting unit 122 extracts one unextracted target pixel from the observed image. Then, the target pixel extracting unit 122 passes the extracted target pixel to the distance calculating unit 123.
[0030] Similar to feature pixels, target pixels are extracted as follows: First, the target pixel extractor 122 generates an address of the target pixel in the observed image based on the coordinate information. Then, the target pixel extractor 122 extracts the target pixel from the observed image based on the generated address.
[0031] The "characteristic pixel" in step S123 means one characteristic pixel extracted in step S121. The "target pixel" in step S123 means one target pixel extracted in step S122.
[0032] In step S123, the distance calculation unit 123 calculates the distance between the feature pixel and the target pixel.
[0033] The distance is calculated, for example, as follows: The distance calculation unit 123 calculates the difference (absolute value of the difference) between the pixel value of the feature pixel and the pixel value of the target pixel. The calculated difference (absolute value of the difference) is the distance between the feature pixel and the target pixel.
[0034] In step S124, the target pixel extraction unit 122 determines whether there are any target pixels that have not yet been extracted.
[0035] The determination is performed as follows. First, the target pixel extraction unit 122 adds 1 to update the number of processed target pixels. The number of processed target pixels is managed using an internal counter. The initial value of the number of processed target pixels is zero. Then, the target pixel extraction unit 122 compares the number of processed target pixels with a threshold value. The threshold value is a predetermined value specified by the user. If the number of processed target pixels is equal to the threshold value, there are no unextracted target pixels. If the number of processed target pixels is less than the threshold value, there are unextracted target pixels.
[0036] If there is an unextracted target pixel, the process proceeds to step S122, whereas if there is no unextracted target pixel, the process proceeds to step S125.
[0037] The "target pixel" in step S125 refers to each of the multiple target pixels extracted in step S122.
[0038] In step S125, the distance calculation unit 123 updates the pixel distance for each target pixel based on the distance between the feature pixel and the target pixel, thereby calculating the pixel distance for each target pixel.
[0039] The pixel distance is updated, for example, as follows: The distance calculation unit 123 updates the pixel distance by adding the distance between the feature pixel and the target pixel. The initial value of the pixel distance is zero.
[0040] In step S126, the feature pixel extraction unit 121 determines whether there are any feature pixels that have not yet been extracted.
[0041] The determination is performed as follows. First, the feature pixel extraction unit 121 adds 1 to update the number of processed feature pixels. The number of processed feature pixels is managed using an internal counter. The initial value of the number of processed feature pixels is zero. Then, the feature pixel extraction unit 121 compares the number of processed feature pixels with a threshold value. The threshold value is a predetermined value specified by the user. If the number of processed feature pixels is equal to the threshold value, there are no unextracted feature pixels. If the number of processed feature pixels is less than the threshold value, there are unextracted feature pixels.
[0042] If there are any unextracted feature pixels, the process proceeds to step S121. At this time, the feature pixel extraction unit 121 initializes the number of processed target pixels. The feature pixel extraction unit 121 also adds 1 to update the number of processed feature pixels. The number of processed feature pixels is managed using an internal counter. The initial value of the number of processed feature pixels is zero.
[0043] If there are no unextracted feature pixels, step S120 ends.
[0044] 3, step S130 will be described. In step S130, the position detection unit 130 detects a position corresponding to the template image from the observed image based on the pixel distance of each target pixel. The position detection unit 130 then outputs the detection result.
[0045] For example, the position corresponding to the template image is detected as follows: The position detection unit 130 selects the position of the target pixel with the smallest pixel distance. The selected position is the position corresponding to the template pixel.
[0046] After step S130, the template matching method ends.
[0047] ***Effects of First Embodiment*** The first embodiment aims to speed up position detection through efficient sparse template matching processing. The first embodiment realizes sparse template matching processing. In the first embodiment, feature pixels and target pixels are extracted based on coordinate information (position information) and an internal counter for the number of feature pixels, and the extracted feature pixels are compared with the extracted target image. This speeds up position detection through sparse template matching processing.
[0048] ***Example of First Embodiment*** The template image storage unit 150 may store all feature pixels in the template image instead of storing all pixels of the template image. The feature pixel extraction unit 121 extracts feature pixels from the template image storage unit 150 based on an internal counter for the number of feature pixels, without referring to coordinate information. For example, the target pixel extraction unit 122 extracts target pixels corresponding to the feature pixels extracted by the feature pixel extraction unit 121.
[0049] Step S120 may be started before all pixels of one observed image are read in step S110. In this case, the number of loops in step S120 is changed depending on the size of the read observed image.
[0050] A plurality of template images may be used. In this case, an internal counter for the number of template images is added, and branching processing occurs depending on the value of the internal counter, and position detection is performed by comparing a plurality of pixel distances for the plurality of template images.
[0051] Second Embodiment A second embodiment of speeding up sparse template matching will be described below, focusing mainly on the differences from the first embodiment, with reference to FIGS.
[0052] ***Description of Configuration*** The configuration of the template matching device 100 will be described with reference to Fig. 6. The configuration of the template matching device 100 differs from the configuration in the first embodiment in that a plurality of observed image storage units 140 are provided.
[0053] The configuration of the pixel comparison unit 120 will be described with reference to Fig. 7. The pixel comparison unit 120 includes elements such as a feature pixel extraction unit 121, a plurality of target pixel extraction units 122, a plurality of distance calculation units 123, and a comparison range control unit .
[0054] The plurality of target pixel extraction units 122 are arranged in parallel and operate simultaneously. The plurality of distance calculation units 123 are arranged in parallel and operate simultaneously. The target pixel extraction units 122 and the distance calculation units 123 are connected in a one-to-one correspondence.
[0055] The comparison range control unit 124 determines two or more target pixels for which pixel distances are to be calculated from among the plurality of target pixels.
[0056] ***Description of Operation*** The template matching method will be described with reference to Fig. 8. In step S210, the observed image acquisition unit 110 acquires an observed image. The procedure of step S210 is the same as the procedure of step S110 in the first embodiment. However, the observed image is stored in each of the multiple observed image storage units 140.
[0057] In step S220, the pixel comparison unit 120 calculates the pixel distance for each target pixel in the observed image.
[0058] The procedure of step S220 will be described with reference to Fig. 9. In step S221, the feature pixel extracting unit 121 extracts one unextracted feature pixel from the template image. Step S221 is the same as step S121 in the first embodiment.
[0059] In step S222, the plurality of target pixel extracting units 122 simultaneously extract different target pixels, thereby extracting a plurality of target pixels at once.
[0060] The multiple target pixels are extracted as follows: A different offset address is set in each observed image storage unit 140. Each target pixel extraction unit 122 extracts a target pixel from the observed image stored in the associated observed image storage unit 140, based on the address based on the coordinate information and an internal counter for the number of feature pixels, and the offset address of the associated observed image storage unit 140.
[0061] If the number of observed image storage units 140 is greater than the number of target pixel extraction units 122, the comparison range control unit 124 determines two or more observed image storage units 140 to be used in step S222 based on the coordinate information.
[0062] In step S223, the distance calculation units 123 simultaneously calculate the distances between the feature pixels and the target pixels for different target pixels. This allows the distances between the feature pixels and each target pixel to be calculated at once. The calculation method is the same as the method in the first embodiment.
[0063] Specifically, each distance calculation unit 123 calculates the distance between the feature pixel and the target pixel extracted by the associated target pixel extraction unit 122 .
[0064] A memory element such as a shift register can be used to control the comparison range. A shift register is an example of a memory element that can move data by simple shift processing. A plurality of target pixels are stored in the shift register. A portion (a certain range) of the plurality of target pixels is compared with the feature pixel. In other words, the distance between each of the target pixels and the feature pixel is calculated. The feature pixel is extracted from the memory element by performing a shift process on the memory element for the coordinate information. The feature pixel is a number of feature pixels corresponding to the number of digits specified in advance by the user.
[0065] In step S224, the distance calculation units 123 update the pixel distances for different target pixels based on the distances between the feature pixels and the target pixels. This allows the pixel distances for each target pixel to be calculated simultaneously. The update method is the same as the method in the first embodiment.
[0066] Specifically, each distance calculation unit 123 updates the pixel distance of the target pixel extracted by the associated target pixel extraction unit 122 .
[0067] In step S225, the feature pixel extraction unit 121 determines whether there are any feature pixels that have not yet been extracted. Step S225 is the same as step S126 in the first embodiment.
[0068] If there are any unextracted feature pixels, the process proceeds to step S221. At this time, the feature pixel extraction unit 121 updates the number of processed feature pixels by adding 1. If there are no unextracted feature pixels, step S220 ends.
[0069] 8, step S230 will be described. In step S230, the position detection unit 130 detects a position corresponding to the template image from the observed image based on the pixel distance of each target pixel. Step S230 is the same as step S130 in the first embodiment.
[0070] After step S230, the template matching method ends.
[0071] ***Effects of Second Embodiment*** In the second embodiment, the feature pixels of the template image and multiple target pixels of the observed image are processed simultaneously, thereby speeding up the sparse template matching process. In the second embodiment, multiple target pixel extraction units 122 and distance calculation units 123 are provided. This makes it possible to simultaneously calculate the distances between the feature pixels of the template image and multiple target pixels of the observed image. This speeds up the sparse template matching process. The template matching device 100 includes a comparison range control unit 124, which selects the target pixel to be compared from pixels extracted from multiple observed image storage units 140 by shift processing. This makes it possible to realize a circuit configuration that is flexible for other image processing without imposing any restrictions on the number of divisions when storing the observed image.
[0072] Third Embodiment A third embodiment of speeding up sparse template matching will be described below, focusing mainly on the differences from the second embodiment, with reference to FIGS.
[0073] ***Description of Configuration*** The configuration of template matching device 100 is the same as that in the second embodiment.
[0074] ***Description of Operation*** The template matching method will be described with reference to Fig. 10. In step S310, the observed image acquisition unit 110 acquires an observed image. Step S310 is the same as step S210 in the second embodiment.
[0075] In step S320, the pixel comparison unit 120 calculates the pixel distance for each target pixel in the observed image.
[0076] The procedure of step S320 will be described with reference to Fig. 11. In step S321, the feature pixel extraction unit 121 extracts one unextracted feature pixel set from the template image.
[0077] A feature pixel set is one or more feature pixels. Specifically, a feature pixel set is one or more pixels that are separated by a fixed distance from two or more feature pixels on the same line in the template image.
[0078] In step S322, the target pixel extractor 122 extracts a plurality of target pixels from the observed image. The extracted target pixels are different from one another.
[0079] The number of target pixels is equal to the sum of the number of target pixels for one feature pixel and the distances between the feature pixel pairs.
[0080] In step S323, the distance calculation units 123 calculate the distance between each feature pixel in the feature pixel set and the target pixel for each target pixel corresponding to the feature pixel in the feature pixel set. The calculation method is the same as the method in step S223 in the second embodiment.
[0081] Some of the feature pixels are extracted from the storage elements by performing a shift process on the storage elements by an amount equal to the coordinate information of the feature pixels and a fixed distance of the feature pixels.
[0082] In step S324, the distance calculation units 123 update the pixel distance for each target pixel based on the distance between the target pixel and each feature pixel in the feature pixel set. The updating method is the same as the method in the first embodiment.
[0083] Specifically, each distance calculation unit 123 updates the pixel distance for the target pixel extracted by the associated target pixel extraction unit 122 .
[0084] In step S325, the feature pixel extraction unit 121 determines whether there are any feature pixel sets that have not yet been extracted. Step S325 is the same as step S126 in the first embodiment.
[0085] If there is an unextracted feature pixel set, the process proceeds to step S321. At this time, the feature pixel extraction unit 121 updates the number of processed feature pixels by adding 1. If there is no unextracted feature pixel set, step S320 ends.
[0086] 10, step S330 will be described. In step S330, the position detection unit 130 detects a position corresponding to the template image from the observed image based on the pixel distance of each target pixel. Step S330 is the same as step S230 in the second embodiment.
[0087] After step S330, the template matching method process ends.
[0088] ***Effects of Third Embodiment*** The third embodiment speeds up the sparse template matching process when constraints are imposed on the coordinates of feature pixels of the template image. The third embodiment improves the efficiency of extracting multiple target pixels. It also makes it possible to reduce the number of iterations in step S320. The more feature pixels included in the feature pixel set, the greater the effect of reducing the number of iterations. Furthermore, the smaller the fixed distance, the more efficient the extraction of multiple target pixels.
[0089] *** Supplementary Information of the Embodiment *** The hardware configuration of the template matching device 100 will be described with reference to FIG. 12 . The template matching device 100 includes a processing circuit 101 and an input / output interface 102. The processing circuit 101 is hardware that implements an observed image acquisition unit 110, a pixel comparison unit 120, a position detection unit 130, an observed image storage unit 140, a template image storage unit 150, a coordinate information storage unit 160, and an overall control unit 170. The processing circuit 101 may be dedicated hardware, or may be a processor that executes a program stored in memory. The program can be recorded (stored) in a computer-readable manner on a non-volatile storage medium such as an optical disk or a flash memory.
[0090] When the processing circuit 101 is dedicated hardware, the processing circuit 101 may be, for example, a single circuit, a composite circuit, a programmed processor, a parallel programmed processor, an ASIC, an FPGA, or a combination thereof. ASIC is an abbreviation for Application Specific Integrated Circuit. FPGA is an abbreviation for Field Programmable Gate Array.
[0091] The template matching apparatus 100 may include a plurality of processing circuits that replace the processing circuit 101 .
[0092] In the processing circuit 101, some functions may be realized by dedicated hardware, and the remaining functions may be realized by software or firmware.
[0093] In this way, the functions of template matching device 100 can be realized by hardware, software, firmware, or a combination of these.
[0094] Each embodiment is an example of a preferred embodiment and is not intended to limit the technical scope of the present disclosure. Each embodiment may be implemented in part or in combination with other embodiments. Procedures described using flowcharts, etc. may be modified as appropriate.
[0095] The template matching device 100 may be read as an "image processing device" or an "image processing circuit." The "device" in the template matching device 100 may be read as a "circuit." The "part" of each element of the template matching device 100 may be read as a "process," "step," "circuit," or "circuitry."
[0096] 100 Template matching device, 101 Processing circuit, 102 Input / output interface, 110 Observation image acquisition unit, 120 Pixel comparison unit, 121 Feature pixel extraction unit, 122 Target pixel extraction unit, 123 Distance calculation unit, 124 Comparison range control unit, 130 Position detection unit, 140 Observation image storage unit, 150 Template image storage unit, 160 Coordinate information storage unit, 170 Overall control unit.
Claims
1. A template matching device comprising: a feature pixel extraction unit that extracts a plurality of feature pixels from a template image; a target pixel extraction unit that extracts a plurality of target pixels from an observed image to be compared with the feature pixels for each extracted feature pixel; a distance calculation unit that calculates a pixel distance to the extracted feature pixels for each extracted target pixel; and a position detection unit that detects a position corresponding to the template image from the observed image based on the pixel distance of each target pixel.
2. The template matching device according to claim 1, comprising: a plurality of target pixel extraction units; and a plurality of distance calculation units, wherein the plurality of target pixel extraction units simultaneously extract different target pixels, and the plurality of distance calculation units simultaneously calculate the pixel distances of the different target pixels.
3. The template matching device according to claim 1 or 2, further comprising a comparison range control unit which determines, from among the plurality of target pixels, two or more target pixels for which the pixel distance is to be calculated.
4. The template matching device according to claim 2 or claim 3, wherein the feature pixel extraction unit extracts a plurality of feature pixel sets by defining as a feature pixel set one or more pixels that are separated by a fixed distance from two or more feature pixels on the same line in the template image, and the target pixel extraction unit extracts the plurality of target pixels to be compared with the feature pixel set for each extracted feature pixel set.
5. A template matching method comprising: extracting a plurality of feature pixels from a template image; extracting a plurality of target pixels from an observed image to be compared with the extracted feature pixels for each of the extracted feature pixels; calculating a pixel distance for each of the extracted target pixels to the extracted feature pixels; and detecting a position corresponding to the template image from the observed image based on the pixel distance for each target pixel.
Citation Information
Patent Citations
Locating regions in a target image using color matching, luminance pattern matching and hue plane pattern matching
US20030083850A1
