Block information determination method and system and storage medium
By binarizing the image and looking up the outline, the zero-order moment is calculated to determine the block area, the problem of low block information extraction efficiency in the prior art is solved, and the rapid and accurate counting and positioning of blocks is achieved.
Patent Information
- Application Number
- CN202411730198.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-29
- Publication Date
- 2024-12-27
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
In the prior art, block information extraction uses an algorithm based on connection domain search, which is time-consuming and low efficiency, making it difficult to quickly and accurately count and locate blocks.
By performing binarization of the original image, contour search processing is performed to extract the outer and inner contours, calculate the zero-order moment of the outer and inner contours to determine the area of the block, and filter the target block according to the preset area threshold value. to achieve rapid counting of blocks.
It realizes accurate and efficient extraction and counting of blocks, improves the efficiency of block information extraction, and can quickly screen out blocks that meet the expected area conditions, which is suitable for industrial application scenarios.
Smart Images

Figure CN119205788A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a method, system and storage medium for determining block information. Background Art
[0002] In industrial application scenarios, providing block information can facilitate actual operations. For example, it can quickly count and locate the number of workpieces, provide information such as the position and orientation of each workpiece, and facilitate subsequent robotic arms to grasp the target objects.
[0003] However, in the related art, the algorithm used for extracting block information is based on connected domain search, which is time-consuming and relatively inefficient.
[0004] In view of the above problems, effective technical solutions are urgently needed. Summary of the invention
[0005] The purpose of the present application is to provide a method, system and storage medium for determining block information, which can solve the problem that the algorithm based on connected domain search is used for extracting block information in related technologies, which is time-consuming and relatively inefficient. By binarizing the original image to obtain a binary image, and performing contour search processing on the binary image to obtain multiple outer contours and inner contours corresponding to each outer contour, the contour of the block can be accurately and efficiently extracted, which is conducive to separating the blocks to be detected in the original image; by calculating the area of each block to be detected based on the zero-order moment of the first pixel area corresponding to the outer contour and the zero-order moment of the second pixel area corresponding to each corresponding inner contour, and determining the block to be detected with an area greater than a preset area threshold as a target block, the blocks that meet the expected area conditions can be quickly screened out, and the target blocks can be accurately counted to obtain the total number of blocks.
[0006] In a first aspect, the present application provides a method for determining block information, the method comprising: Acquire an original image containing a block to be detected, and perform binarization processing on the original image to obtain a binarized image; Performing contour search processing on the binary image to obtain multiple outer contours and inner contours corresponding to each outer contour, wherein each outer contour represents the peripheral contour feature of the corresponding block to be detected; Calculating the zero-order moment of the first pixel area corresponding to each of the outer contours, and the zero-order moment of the second pixel area corresponding to each of the corresponding inner contours; Subtracting the zero-order moment of each corresponding second pixel area from the zero-order moment of the first pixel area to obtain the area of each block to be detected; The blocks to be detected whose areas are larger than a preset area threshold are determined as target blocks, and the target blocks are counted to obtain the total number of blocks.
[0007] Optionally, before obtaining the area of each block to be detected by subtracting the zero-order moment of each corresponding second pixel area from the zero-order moment of the first pixel area, the method further includes: respectively correcting the zero-order moment of the first pixel region and the corresponding zero-order moment of each of the second pixel regions; The step of subtracting the zero-order moment of each corresponding second pixel area from the zero-order moment of the first pixel area to obtain the area of each block to be detected includes: The area of each block to be detected is obtained by subtracting the corresponding corrected zero-order moment of each second pixel area from the corrected zero-order moment of the first pixel area.
[0008] Optionally, the calculation formulas for respectively correcting the zero-order moment of the first pixel region and the corresponding zero-order moment of each of the second pixel regions are as follows: , , in, is the corrected zero-order moment of the first pixel area, is the original zero-order moment of the first pixel area, is the number of edge pixels in the first pixel area, is the corrected zero-order moment of each of the second pixel regions, is the original zero-order moment of the second pixel area, is the number of edge pixels in the second pixel area.
[0009] Optionally, after performing contour search processing on the binary image to obtain multiple outer contours and inner contours corresponding to each of the outer contours, the method further includes: Calculate the first-order moment of the first pixel area corresponding to each of the outer contours, and the first-order moment of the second pixel area corresponding to each of the corresponding inner contours; After counting the target blocks to obtain the total number of blocks, the method further includes: Based on the zero-order moment and the first-order moment of the first pixel region corresponding to the target block, and the zero-order moment and the first-order moment of each corresponding second pixel region, the centroid coordinates of the target block are calculated.
[0010] Optionally, before calculating the centroid coordinates of the target block based on the zero-order moment and the first-order moment of the first pixel area corresponding to the target block, and the zero-order moment and the first-order moment of each corresponding second pixel area, the method further includes: respectively correcting the first-order moment of the first pixel region corresponding to the target block and the first-order moment of each corresponding second pixel region; The calculating of the centroid coordinates of the target block based on the zero-order moment and the first-order moment of the first pixel region corresponding to the target block, and the zero-order moment and the first-order moment of each corresponding second pixel region, includes: The centroid coordinates of the target block are calculated based on the zero-order moment and the corrected first-order moment of the first pixel region corresponding to the target block, and the zero-order moment and the corrected first-order moment of each corresponding second pixel region.
[0011] Optionally, the calculation formulas for respectively correcting the first-order moment of the first pixel region corresponding to the target block and the first-order moment of each corresponding second pixel region are as follows: , in, and is the first-order moment of the first pixel area corresponding to the target block after correction, and is the first-order moment of the first pixel area corresponding to the original target block, and are the sum of the horizontal coordinates and the average horizontal coordinate of the edge points of the first pixel area corresponding to the target block, respectively. and are the sum of the ordinates of the edge points of the first pixel region corresponding to the target block and the average ordinate, and is the first-order moment of each of the second pixel regions after correction, and is the original first-order moment of each second pixel region, and is the sum of the horizontal coordinates of the edge points of each second pixel region and the average horizontal coordinate, and are respectively the sum of the ordinates of the edge points of the second pixel region and the average ordinate.
[0012] Optionally, the pixel area corresponding to the block to be detected in the binary image is a preset foreground color, and the remaining pixel areas are preset background colors; After the original image is binarized to obtain a binarized image, the method further includes: Dividing the binary image into a target detection area and a non-target detection area according to a preset partitioning rule, setting the non-target detection area to the preset background color, and obtaining a target binary image; The step of performing contour search on the binary image to obtain a plurality of outer contours and an inner contour corresponding to each of the outer contours includes: The target binary image is subjected to contour searching processing to obtain a plurality of outer contours and an inner contour corresponding to each of the outer contours.
[0013] Optionally, dividing the binary image into a target detection area and a non-target detection area according to a preset partitioning rule includes: Determine a pixel area in the binary image that satisfies both being located within the region of interest and outside the shielded region as a target detection area; Other pixel areas in the binary image excluding the target detection area are determined as non-target detection areas.
[0014] In a second aspect, the present application provides a block information determination system, the block information determination system comprising: a memory and a processor, the memory comprising a program of a block information determination method, and when the program of the block information determination method is executed by the processor, the following steps are implemented: Acquire an original image containing a block to be detected, and perform binarization processing on the original image to obtain a binarized image; Performing contour search processing on the binary image to obtain multiple outer contours and inner contours corresponding to each outer contour, wherein each outer contour represents the peripheral contour feature of the corresponding block to be detected; Calculating the zero-order moment of the first pixel area corresponding to each of the outer contours, and the zero-order moment of the second pixel area corresponding to each of the corresponding inner contours; Subtracting the zero-order moment of each corresponding second pixel area from the zero-order moment of the first pixel area to obtain the area of each block to be detected; The blocks to be detected whose areas are larger than a preset area threshold are determined as target blocks, and the target blocks are counted to obtain the total number of blocks.
[0015] In a third aspect, the present application provides a computer-readable storage medium, which includes a program of a block information determination method. When the program of the block information determination method is executed by a processor, the steps of the block information determination method are implemented.
[0016] As can be seen from the above, the block information determination method, system and storage medium provided by the present application obtain an original image containing a block to be detected, binarize the original image to obtain a binary image; perform contour search processing on the binary image to obtain multiple outer contours, and inner contours corresponding to each outer contour, wherein each outer contour represents the outer contour feature of the corresponding block to be detected; calculate the zero-order moment of the first pixel area corresponding to each outer contour, and the zero-order moment of the second pixel area corresponding to each corresponding inner contour; subtract the zero-order moment of the corresponding second pixel area from the zero-order moment of the first pixel area to obtain the area of each block to be detected; determine the block to be detected whose area is greater than a preset area threshold as a target block, and count the target blocks to obtain the total number of blocks. In the above scheme, the original image is binarized to obtain a binary image, and the binary image is subjected to contour search processing to obtain multiple outer contours and inner contours corresponding to each outer contour, so that the contours of the blocks can be accurately and efficiently extracted, which is conducive to separating the blocks to be detected in the original image; the area of each block to be detected is calculated based on the zero-order moment of the first pixel area corresponding to the outer contour, and the zero-order moment of the second pixel area corresponding to each inner contour, and the blocks to be detected whose area is greater than a preset area threshold are determined as target blocks, so that blocks that meet the expected area conditions can be quickly screened out, and the target blocks can be accurately counted to obtain the total number of blocks.
[0017] Other features and advantages of the present application will be described in the following description, and partly become apparent from the description, or be understood by practicing the embodiments of the present application. The purpose and other advantages of the present application can be realized and obtained by the structures specifically pointed out in the written description, claims, and drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments of the present application will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0019] Figure 1 A flowchart of a method for determining block information provided in an embodiment of the present application; Figure 2 An original image of a block information to be determined as an example; Figure 3 A binarized image obtained by binarizing the original image provided in an embodiment of the present application; Figure 4A flowchart of another method for determining block information provided in an embodiment of the present application; Figure 5 A binary image after setting the non-target detection area to a preset background color provided in an embodiment of the present application; Figure 6 The result image of the contour of the target block extracted by combining with the original image output provided by the embodiment of the present application; Figure 7 A schematic diagram of the structure of a block information determination system provided in an embodiment of the present application. DETAILED DESCRIPTION
[0020] The technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all of the embodiments. The components of the embodiments of the present application described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the application claimed for protection, but merely represents the selected embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present application.
[0021] It should be noted that similar reference numerals and letters represent similar items in the following drawings, so once an item is defined in one drawing, it does not need to be further defined and explained in subsequent drawings. At the same time, in the description of this application, the terms "first", "second", etc. are only used to distinguish the description and cannot be understood as indicating or implying relative importance.
[0022] Please refer to Figure 1 , Figure 1 A flowchart of a method for determining block information provided in an embodiment of the present application is shown in FIG. Figure 1 As shown, the specific steps include: S101, obtaining an original image containing a block to be detected, and performing binarization processing on the original image to obtain a binarized image; S102, performing contour search processing on the binary image to obtain multiple outer contours and inner contours corresponding to each outer contour, wherein each outer contour represents the peripheral contour feature of the corresponding block to be detected; S103, calculating the zero-order moment of the first pixel area corresponding to each outer contour, and the zero-order moment of the second pixel area corresponding to each corresponding inner contour; S104, subtracting the zero-order moment of each corresponding second pixel area from the zero-order moment of the first pixel area to obtain the area of each block to be detected; S105 , determining the blocks to be detected whose areas are larger than a preset area threshold as target blocks, and counting the target blocks to obtain a total number of blocks.
[0023] It should be noted that Figure 2 As an example, an original image of a block information to be determined is shown in FIG. Figure 2 As shown, the original image can be an image with a high contrast between the scene artifact and the background, wherein the lighting conditions of the scene are relatively stable, and the original image contains a block to be detected. The binarization process can be based on the maximum inter-class variance method to determine the optimal threshold for binarization, or it can be based on a set fixed threshold for binarization, which is not limited in this application. In addition, the contour search process can be based on edge detection algorithm to perform edge detection and then extract contours, or it can be based on functions such as findContours in image processing libraries such as OpenCV to detect and extract contours, which is not limited in this application. Figure 3 The binary image obtained by binarizing the original image provided in the embodiment of the present application is as follows: Figure 3 As shown, each outer contour represents the peripheral contour feature of the corresponding block to be detected, and some of the blocks to be detected also have inner contour features. Therefore, the contour search process needs to simultaneously confirm multiple outer contours in the binary image, as well as the inner contour that each outer contour may correspond to. In addition, since the zero-order moment of the first pixel area is the sum of the pixel points of the first pixel area in the binary image, it can be used to characterize the area enclosed by the outer contour, and the zero-order moment of the second pixel area is the sum of the pixel points of the second pixel area in the binary image, it can be used to characterize the area enclosed by the inner contour. For example, the formula for calculating the zero-order moment of the first pixel area is as follows: , in, is the coordinate point in the pixel area Similarly, the zero-order moment of the second pixel area can be calculated , accordingly, the calculation formula for the area S of the block to be detected is as follows: .
[0024] Thus, by subtracting the zero-order moment of each corresponding second pixel area from the zero-order moment of the first pixel area, the area of each block to be detected can be obtained. The preset area threshold can be used to distinguish whether the block to be detected is a target block. It can be set by the developer based on the feature attributes of the workpiece in the actual industrial scene, and this application does not limit it. It is worth noting that by setting the preset area threshold, blocks that are too small to be detected, such as burrs, can be screened out.
[0025] As described above, by binarizing the original image to obtain a binary image, and performing contour search processing on the binary image to obtain multiple outer contours and inner contours corresponding to each outer contour, the contours of the blocks can be accurately and efficiently extracted, which is beneficial to separating the blocks to be detected in the original image; by calculating the area of each block to be detected based on the zero-order moment of the first pixel area corresponding to the outer contour, and the zero-order moment of the second pixel area corresponding to each inner contour, and determining the blocks to be detected whose area is greater than a preset area threshold as target blocks, the blocks that meet the expected area conditions can be quickly screened out, and the target blocks can be accurately counted to obtain the total number of blocks.
[0026] According to an embodiment of the present invention, before the zero-order moment of each corresponding second pixel region is subtracted from the zero-order moment of the first pixel region to obtain the area of each block to be detected, the method further includes: Correcting the zero-order moment of the first pixel region and the zero-order moment of each corresponding second pixel region respectively; The area of each block to be detected is obtained by subtracting the zero-order moment of each corresponding second pixel area from the zero-order moment of the first pixel area, including: The area of each block to be detected is obtained by subtracting the corresponding corrected zero-order moment of each second pixel area from the corrected zero-order moment of the first pixel area.
[0027] It should be noted that, since the calculation result of the zero-order moment will ignore the edge pixels, the zero-order moment of the first pixel area and the zero-order moment of each corresponding second pixel area can be corrected, so that the area of the block to be detected can be calculated more accurately later. In one embodiment, the zero-order moment of the first pixel area and the zero-order moment of each corresponding second pixel area can be compensated by a preset value, and the preset compensation value can be a fixed value set based on empirical data. In one embodiment, the zero-order moment of the corresponding pixel area can be compensated based on the number of edge points of different pixel areas.
[0028] According to an embodiment of the present invention, the calculation formulas for respectively correcting the zero-order moment of the first pixel region and the zero-order moment of each corresponding second pixel region are as follows: , , in, is the zero-order moment of the first pixel area after correction, is the zero-order moment of the original first pixel area, is the number of edge pixels in the first pixel area, is the corrected zero-order moment of each second pixel area, is the zero-order moment of the original second pixel area, is the number of edge pixels in the second pixel area.
[0029] According to an embodiment of the present invention, after performing contour search processing on the binary image to obtain multiple outer contours and inner contours corresponding to each outer contour, the method further includes: Calculate the first-order moment of the first pixel area corresponding to each outer contour, and the first-order moment of the second pixel area corresponding to each corresponding inner contour; After counting the target blocks to obtain the total number of blocks, it also includes: Based on the zero-order moment and the first-order moment of the first pixel region corresponding to the target block, and the zero-order moment and the first-order moment of each corresponding second pixel region, the centroid coordinates of the target block are calculated.
[0030] It should be noted that the first-order moment of the first pixel area corresponding to each outer contour is calculated, wherein the first-order moment of the first pixel area includes the weighted sum of the pixel values of the first pixel area in the binary image with respect to the x-coordinate and the y-coordinate, and the first-order moment of the second pixel area corresponding to each inner contour, wherein the first-order moment of the second pixel area includes the weighted sum of the pixel values of the second pixel area in the binary image with respect to the x-coordinate and the y-coordinate, respectively, and combined with the zero-order moment calculated previously, the centroid coordinates of the target block can be calculated. For example, the formula for calculating the first-order moment of the first pixel area is as follows: , in, is the coordinate point in the pixel area Similarly, the first-order moment of the second pixel area can be calculated and , accordingly, the calculation formula of the center of mass of the target block is as follows: , , Among them, x represents the horizontal coordinate of the center of mass of the target block, and y represents the vertical coordinate of the center of mass of the target block. and is the first-order moment of the first pixel area corresponding to the target block, and is the first-order moment of each second pixel area.
[0031] It is worth noting that in industrial application scenarios, the centroid coordinates are the geometric center of the object. By calculating the centroid coordinates of the target block, the robot arm can provide a clear grasping target position. By accurately calculating the centroid coordinates of the object, the robot arm can accurately locate the object, thereby achieving efficient grasping operations.
[0032] According to an embodiment of the present invention, before calculating the centroid coordinates of the target block based on the zero-order moment and the first-order moment of the first pixel region corresponding to the target block, and the zero-order moment and the first-order moment of each corresponding second pixel region, the method further includes: Correcting the first-order moment of the first pixel region corresponding to the target block and the first-order moment of each corresponding second pixel region respectively; The centroid coordinates of the target block are calculated based on the zero-order moment and the first-order moment of the first pixel region corresponding to the target block, and the zero-order moment and the first-order moment of each corresponding second pixel region, including: Based on the zero-order moment and the corrected first-order moment of the first pixel region corresponding to the target block, and the zero-order moment and the corrected first-order moment of each corresponding second pixel region, the centroid coordinates of the target block are calculated.
[0033] It should be noted that, since the calculation result of the first-order moment will also ignore the edge pixels, the first-order moment of the first pixel area and the first-order moment of each corresponding second pixel area can be corrected, so that the centroid coordinates of the block to be detected can be calculated more accurately later. In one embodiment, the first-order moment of the first pixel area and the first-order moment of each corresponding second pixel area can be compensated by a preset value, and the preset compensation value can be a fixed value set based on empirical data. In one embodiment, the first-order moment of the corresponding pixel area can be compensated based on the coordinate information of the edge points of different pixel areas.
[0034] According to an embodiment of the present invention, the calculation formulas for correcting the first-order moment of the first pixel region corresponding to the target block and the first-order moment of each corresponding second pixel region are as follows: , in, and is the first-order moment of the first pixel area corresponding to the corrected target block, and is the first-order moment of the first pixel area corresponding to the original target block, and are the sum of the horizontal coordinates and the average horizontal coordinate of the edge points of the first pixel area corresponding to the target block, and are the sum of the ordinates of the edge points of the first pixel region corresponding to the target block and the average ordinate, and is the first-order moment of each second pixel area after correction, and is the first-order moment of each original second pixel area, and are the sum of the abscissas and the average abscissa of the edge points of each second pixel region, and are the sum of the ordinates and the average ordinate of the edge points of each second pixel region.
[0035] Optionally, other information of the target block can also be calculated. The specific calculation formula is as follows: , , , Where S represents the area of the target block, represents the roundness of the block, d represents the maximum distance from the edge point to the center of mass, F represents the Feret diameter, D represents the maximum distance between any two points on the edge, L represents the rectangularity of the block, and T represents the minimum circumscribed matrix area.
[0036] Please refer to Figure 4 , Figure 4 A flowchart of another method for determining block information provided in an embodiment of the present application is shown in FIG. Figure 4 As shown, the specific steps include: S201, obtaining an original image containing a block to be detected, and binarizing the original image to obtain a binary image, wherein a pixel area corresponding to the block to be detected in the binary image is a preset foreground color, and other pixel areas are preset background colors; S202, dividing the binary image into a target detection area and a non-target detection area according to a preset partitioning rule, setting the non-target detection area to a preset background color, and obtaining a target binary image; S203, performing contour search processing on the target binary image to obtain multiple outer contours and inner contours corresponding to each outer contour, wherein each outer contour represents the peripheral contour feature of the corresponding block to be detected; S204, calculating the zero-order moment of the first pixel area corresponding to each outer contour, and the zero-order moment of the second pixel area corresponding to each corresponding inner contour; S205, subtracting the zero-order moment of each corresponding second pixel area from the zero-order moment of the first pixel area to obtain the area of each block to be detected; S206: Determine the blocks to be detected whose areas are larger than a preset area threshold as target blocks, and count the target blocks to obtain a total number of blocks.
[0037] It should be noted that the block to be detected is located in the foreground area of the binary image, and its corresponding preset foreground color can be white, while the remaining pixel areas are background areas, and its corresponding preset background color can be black. Since in actual application scenarios, it may be necessary to determine the information of the target block only for a specific area, the binary image can be divided into regions according to the preset partitioning rules to obtain the target detection area and the non-target detection area. Figure 5 The binary image after setting the non-target detection area to a preset background color provided in the embodiment of the present application is as follows: Figure 5 As shown, by setting the non-target detection area to a preset background color, the block information that does not need to be detected can be shielded, and the block information of the target detection area can be concentratedly extracted. Figure 6 The result image of the contour of the target block extracted by combining the original image output provided in the embodiment of the present application is as follows: Figure 6 As shown, in Figure 5 On this basis, only the blocks in the target detection area and their corresponding bounding rectangles are detected and output.
[0038] According to an embodiment of the present invention, dividing a binary image into a target detection area and a non-target detection area according to a preset partitioning rule includes: The pixel area in the binary image that satisfies both being within the region of interest and outside the shielded area is determined as the target detection area; The other pixel areas in the binary image excluding the target detection area are determined as non-target detection areas.
[0039] It should be noted that the region of interest is the area where the user needs to determine the block information, and the shielded area is the area where the user does not need to determine the block information. Therefore, the target detection area is actually the region of interest minus the shielded area. Among them, the region of interest and the shielded area can be set according to the specific needs of the actual application scenario. For example, the region of interest can be set to surround a specific area to be counted, and the shielded area can be set to an area without artifacts and with greater interference.
[0040] The present invention also provides a block information determination system. Figure 7 A schematic diagram of the structure of a block information determination system provided in an embodiment of the present application is shown in FIG. Figure 7 As shown, the block information determination system includes: a memory 101 and a processor 102, the memory includes a program of the block information determination method, and when the program of the block information determination method is executed by the processor, the following steps are implemented: S101, obtaining an original image containing a block to be detected, and performing binarization processing on the original image to obtain a binarized image; S102, performing contour search processing on the binary image to obtain multiple outer contours and inner contours corresponding to each outer contour, wherein each outer contour represents the peripheral contour feature of the corresponding block to be detected; S103, calculating the zero-order moment of the first pixel area corresponding to each outer contour, and the zero-order moment of the second pixel area corresponding to each corresponding inner contour; S104, subtracting the zero-order moment of each corresponding second pixel area from the zero-order moment of the first pixel area to obtain the area of each block to be detected; S105 , determining the blocks to be detected whose areas are larger than a preset area threshold as target blocks, and counting the target blocks to obtain a total number of blocks.
[0041] It should be noted that, by binarizing the original image to obtain a binary image, and performing contour search processing on the binary image to obtain multiple outer contours and inner contours corresponding to each outer contour, the contours of the blocks can be accurately and efficiently extracted, which is conducive to separating the blocks to be detected in the original image; by calculating the area of each block to be detected based on the zero-order moment of the first pixel area corresponding to the outer contour, and the zero-order moment of the second pixel area corresponding to each inner contour, and determining the blocks to be detected whose area is greater than a preset area threshold as target blocks, the blocks that meet the expected area conditions can be quickly screened out, and the target blocks can be accurately counted to obtain the total number of blocks.
[0042] The present invention also provides a computer-readable storage medium, which includes a program of the block information determination method. When the program of the block information determination method is executed by a processor, the steps of the block information determination method are implemented.
[0043] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are only schematic. For example, the division of units is only a logical function division. There may be other division methods in actual implementation, such as: multiple units or components can be combined, or can be integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the components shown or discussed can be through some interfaces, and the indirect coupling or communication connection of devices or units can be electrical, mechanical or other forms.
[0044] The units described above as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units; they may be located in one place or distributed on multiple network units; some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0045] In addition, all functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may be separately used as a unit, or two or more units may be integrated into one unit; the above-mentioned integrated units may be implemented in the form of hardware or in the form of hardware plus software functional units.
[0046] Those skilled in the art can understand that all or part of the steps of implementing the above method embodiments can be completed by hardware related to program instructions, and the aforementioned program can be stored in a readable storage medium. When the program is executed, it executes the steps of the above method embodiments; and the aforementioned storage medium includes: mobile storage devices, read-only memories (ROM, Read-Only Memory), random access memories (RAM, Random Access Memory), disks or optical disks, and other media that can store program codes.
[0047] Alternatively, if the above-mentioned integrated unit of the present invention is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a readable storage medium. Based on this understanding, the technical solution of the embodiment of the present invention can be essentially or partly reflected in the form of a software product that contributes to the prior art. The software product is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the methods of each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as mobile storage devices, ROM, RAM, magnetic disks or optical disks.
Claims
1. A method for determining block information, characterized in that: include: Acquire an original image containing a block to be detected, and perform binarization processing on the original image to obtain a binarized image; Performing contour search processing on the binary image to obtain multiple outer contours and inner contours corresponding to each outer contour, wherein each outer contour represents the peripheral contour feature of the corresponding block to be detected; Calculating the zero-order moment of the first pixel area corresponding to each of the outer contours, and the zero-order moment of the second pixel area corresponding to each of the corresponding inner contours; Subtracting the zero-order moment of each corresponding second pixel area from the zero-order moment of the first pixel area to obtain the area of each block to be detected; The blocks to be detected whose areas are larger than a preset area threshold are determined as target blocks, and the target blocks are counted to obtain the total number of blocks.
2. The method for determining block information according to claim 1, characterized in that: Before obtaining the area of each block to be detected by subtracting the zero-order moment of each corresponding second pixel area from the zero-order moment of the first pixel area, the method further includes: respectively correcting the zero-order moment of the first pixel region and the corresponding zero-order moment of each of the second pixel regions; The step of subtracting the zero-order moment of each corresponding second pixel area from the zero-order moment of the first pixel area to obtain the area of each block to be detected includes: The area of each block to be detected is obtained by subtracting the corresponding corrected zero-order moment of each second pixel area from the corrected zero-order moment of the first pixel area.
3. The method for determining block information according to claim 2, characterized in that: The calculation formulas for respectively correcting the zero-order moment of the first pixel region and the corresponding zero-order moment of each of the second pixel regions are as follows: , , in, is the corrected zero-order moment of the first pixel area, is the original zero-order moment of the first pixel area, is the number of edge pixels in the first pixel area, is the corrected zero-order moment of each of the second pixel regions, is the original zero-order moment of the second pixel area, is the number of edge pixels in the second pixel area.
4. The method for determining block information according to claim 1, characterized in that: After performing contour search processing on the binary image to obtain multiple outer contours and inner contours corresponding to each of the outer contours, the method further includes: Calculate the first-order moment of the first pixel area corresponding to each of the outer contours, and the first-order moment of the second pixel area corresponding to each of the corresponding inner contours; After counting the target blocks to obtain the total number of blocks, the method further includes: Based on the zero-order moment and the first-order moment of the first pixel region corresponding to the target block, and the zero-order moment and the first-order moment of each corresponding second pixel region, the centroid coordinates of the target block are calculated.
5. The method for determining block information according to claim 4, characterized in that: Before calculating the centroid coordinates of the target block based on the zero-order moment and the first-order moment of the first pixel region corresponding to the target block, and the zero-order moment and the first-order moment of each corresponding second pixel region, the method further includes: respectively correcting the first-order moment of the first pixel region corresponding to the target block and the first-order moment of each corresponding second pixel region; The calculating of the centroid coordinates of the target block based on the zero-order moment and the first-order moment of the first pixel region corresponding to the target block, and the zero-order moment and the first-order moment of each corresponding second pixel region, includes: The centroid coordinates of the target block are calculated based on the zero-order moment and the corrected first-order moment of the first pixel region corresponding to the target block, and the zero-order moment and the corrected first-order moment of each corresponding second pixel region.
6. The method for determining block information according to claim 5, characterized in that: The calculation formulas for respectively correcting the first-order moment of the first pixel region corresponding to the target block and the first-order moment of each of the corresponding second pixel regions are as follows: , in, and is the first-order moment of the first pixel area corresponding to the target block after correction, and is the first-order moment of the first pixel area corresponding to the original target block, and are the sum of the horizontal coordinates and the average horizontal coordinate of the edge points of the first pixel area corresponding to the target block, respectively. and are the sum of the ordinates of the edge points of the first pixel region corresponding to the target block and the average ordinate, and is the first-order moment of each of the second pixel regions after correction, and is the original first-order moment of each of the second pixel areas, and are the sum of the horizontal coordinates of the edge points of the second pixel region and the average horizontal coordinate, and are respectively the sum of the ordinates of the edge points of the second pixel region and the average ordinate.
7. The method for determining block information according to claim 1, characterized in that: The pixel area corresponding to the block to be detected in the binary image is a preset foreground color, and the remaining pixel areas are preset background colors; After the original image is binarized to obtain a binarized image, the method further includes: Dividing the binary image into a target detection area and a non-target detection area according to a preset partitioning rule, setting the non-target detection area to the preset background color, and obtaining a target binary image; The step of performing contour search on the binary image to obtain a plurality of outer contours and an inner contour corresponding to each of the outer contours includes: The target binary image is subjected to contour searching processing to obtain a plurality of outer contours and an inner contour corresponding to each of the outer contours.
8. The method for determining block information according to claim 7, characterized in that: The step of dividing the binary image into a target detection area and a non-target detection area according to a preset partitioning rule includes: Determine a pixel area in the binary image that satisfies both being located within the region of interest and outside the shielded region as a target detection area; Other pixel areas in the binary image excluding the target detection area are determined as non-target detection areas.
9. A block information determination system, characterized in that: The block information determination system comprises: a memory and a processor, wherein the memory comprises a program of the block information determination method, and when the program of the block information determination method is executed by the processor, the following steps are implemented: Acquire an original image containing a block to be detected, and perform binarization processing on the original image to obtain a binarized image; Performing contour search processing on the binary image to obtain multiple outer contours and inner contours corresponding to each outer contour, wherein each outer contour represents the peripheral contour feature of the corresponding block to be detected; Calculating the zero-order moment of the first pixel area corresponding to each of the outer contours, and the zero-order moment of the second pixel area corresponding to each of the corresponding inner contours; Subtracting the zero-order moment of each corresponding second pixel area from the zero-order moment of the first pixel area to obtain the area of each block to be detected; The blocks to be detected whose areas are larger than a preset area threshold are determined as target blocks, and the target blocks are counted to obtain the total number of blocks.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a program of the block information determination method. When the program of the block information determination method is executed by a processor, the steps of the block information determination method according to any one of claims 1 to 8 are implemented.
Citation Information
Patent Citations
Visual positioning processing method and device and robot
CN111209842A
Nut seed kernel worm-eaten defect detection method and device
CN112819746A
Pore area acquisition method and device, computer equipment and storage medium
CN113129315A
Plant hairy body counting method and device and medium
CN115358997A
Dispensing detection method, device, equipment and medium
CN115797271A
Cited By
Block analysis method and system based on stroke code binaryzation and medium
CN120495384A
Block analysis method, system, and medium based on stroke code binarization
CN120495384B
