Method and device for detecting target in image
By splitting the agricultural production images into multiple sub-maps and performing in-depth model detection, the problem of difficulty in identifying small targets in the prior art is solved, and the accuracy and detection rate of detection are improved.
Patent Information
- Application Number
- CN202111573344.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-21
- Publication Date
- 2025-04-22
- Estimated Expiration
- 2041-12-21
AI Technical Summary
The existing depth model is difficult to identify small targets in agricultural production images, resulting in inaccurate detection results.
By splitting the original image into multiple sub-maps, each sub-map has overlapping areas with adjacent sub-maps, and inputting these sub-maps into a pre-trained depth model for detection, obtaining the sub-object information, and then merging the target information in the original image.
It improves the accuracy of detection of objects in the image, and is especially suitable for detection of small objects in the image, effectively reducing the difficulty of identifying small objects and improving the detection rate.
Smart Images

Figure CN114241345B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a method and device for detecting a target in an image. Background Art
[0002] This section is intended to provide a background or context to the embodiments of the invention recited in the claims. No admission is made that the description herein is prior art by inclusion in this section.
[0003] In the process of agricultural production, it is often necessary to detect some targets that affect the growth of crops (such as bees, pests, etc.). These targets are small in size in agricultural production. In addition, due to the complex outdoor environment and changeable light, the target objects account for a small proportion in the collected agricultural production images. Small targets have fewer effective pixels in the image.
[0004] When using existing deep models to detect targets in images, the original image is normalized to a fixed size, and the normalized image is used for target detection. However, since some small targets have very few effective pixels in the original image, the effective pixels of the small targets are further reduced after normalization, and the features of the small targets are not prominent enough. When using deep models for detection, these small targets may not be detected. In other words, the current deep models have difficulty in identifying small targets, and the detection results are not accurate enough. Summary of the invention
[0005] An embodiment of the present invention provides a method for detecting an object in an image, which is used to improve the accuracy of detecting an object in an image. The method includes:
[0006] The original image to be detected is split into multiple sub-images; each sub-image has an overlapping area with its adjacent sub-image;
[0007] The multiple sub-images obtained by splitting are respectively input into a pre-trained deep model for detection to obtain sub-target information corresponding to each sub-image; the sub-target information includes the coordinates of the detection target in the sub-image and the category of the detection target; the deep model is trained using the sub-image containing the detection target;
[0008] According to the sub-target information corresponding to each sub-image and the coordinates of each sub-image in the original image, the coordinates of the detected target in the original image and the category of the detected target are obtained.
[0009] The embodiment of the present invention further provides a device for detecting an object in an image, which is used to improve the accuracy of detecting an object in an image. The device includes:
[0010] An image splitting module is used to split the original image to be detected into multiple sub-images; wherein each sub-image has an overlapping area with its adjacent sub-images;
[0011] A detection module, used to input the multiple sub-images obtained by splitting into a pre-trained deep model for detection, and obtain sub-target information corresponding to each sub-image; the sub-target information includes the coordinates of the detection target in the sub-image and the category of the detection target; the deep model is trained using the sub-image containing the detection target;
[0012] The target information processing module is used to obtain the coordinates of the detection target in the original image and the category of the detection target according to the sub-target information corresponding to each sub-image and the coordinates of each sub-image in the original image.
[0013] An embodiment of the present invention further provides a computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above-mentioned method for detecting targets in an image when executing the computer program.
[0014] An embodiment of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method for detecting an object in an image is implemented.
[0015] An embodiment of the present invention further provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the computer program implements the above-mentioned method for detecting an object in an image.
[0016] In an embodiment of the present invention, an original image to be detected is split into multiple sub-images; each sub-image has an overlapping area with its adjacent sub-image; the multiple sub-images obtained by splitting are respectively input into a pre-trained deep model for detection to obtain sub-target information corresponding to each sub-image; the sub-target information includes the coordinates of the detection target in the sub-image, and the category of the detection target; the deep model is trained using the sub-image containing the detection target; based on the sub-target information corresponding to each sub-image and the coordinates of each sub-image in the original image, the coordinates of the detection target in the original image and the category of the detection target are obtained. In this way, the original image to be detected is split into multiple sub-images, and detection is performed on each sub-image. The ratio of pixel points of the target to be detected in the sub-image to the pixel points of the sub-image is higher than the ratio of pixel points of the target to be detected in the original image to the pixel points of the original image, that is, the ratio of effective pixel points of the target in the sub-image is higher than the ratio of effective pixel points in the original image. The original target information of the corresponding original image is obtained according to the sub-target information of each sub-image, and then the detection result of the original image is obtained. This can improve the accuracy of target detection in the original image, and is especially suitable for the detection of small targets in the image. It can effectively reduce the difficulty of recognizing small targets in the image and improve the detection rate. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the prior art descriptions. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work. In the drawings:
[0018] Figure 1 A flowchart of a method for detecting an object in an image provided in an embodiment of the present invention;
[0019] Figure 2 A flow chart of a method for splitting an original image to be detected into multiple sub-images in an embodiment of the present invention;
[0020] Figure 3 This is a flow chart of a method for training a deep model in an embodiment of the present invention;
[0021] Figure 4 A flow chart of a method for splitting an original sample image and an annotated image corresponding to the original sample image to obtain a plurality of sample sub-images corresponding to the original sample image and a sample annotated sub-image corresponding to each sample sub-image, provided in an embodiment of the present invention;
[0022] Figure 5An example diagram of performing edge annotation information processing on an initial sample annotation sub-graph corresponding to each sample sub-graph provided in an embodiment of the present invention;
[0023] Figure 6 A flow chart of a method for obtaining the coordinates of a detection target in an original image and the category of the detection target according to a labeled sub-image corresponding to each sub-image and the coordinates of each sub-image in the original image provided in an embodiment of the present invention;
[0024] Figure 7 The figure is a schematic diagram of a device for detecting an object in an image provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0025] To make the purpose, technical solution and advantages of the embodiments of the present invention more clear, the embodiments of the present invention are further described in detail below in conjunction with the accompanying drawings. Here, the exemplary embodiments of the present invention and their descriptions are used to explain the present invention, but are not intended to limit the present invention.
[0026] The term "and / or" herein only describes an association relationship, indicating that three relationships may exist. For example, A and / or B may represent the following three situations: A exists alone, A and B exist at the same time, and B exists alone. In addition, the term "at least one" herein represents any combination of at least two of any one or more of a plurality of. For example, including at least one of A, B, and C may represent including any one or more elements selected from the set consisting of A, B, and C.
[0027] In the description of this specification, the terms "include", "including", "have", "contain", etc. are all open terms, which mean including but not limited to. The descriptions with reference to the terms "one embodiment", "a specific embodiment", "some embodiments", "for example", etc. mean that the specific features, structures or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present application. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures or characteristics described may be combined in a suitable manner in any one or more embodiments or examples. The order of steps involved in each embodiment is used to schematically illustrate the implementation of the present application, and the order of steps is not limited and can be appropriately adjusted as needed.
[0028] Research has found that in the process of agricultural production, it is often necessary to detect some targets that affect the growth of crops (such as bees, pests, etc.). These targets are small in size in agricultural production. In addition, due to the complex outdoor environment and changeable light in agriculture, the proportion of targets in the collected agricultural production images is small, and they are small targets. Small targets have fewer effective pixels in the image. When using the existing deep model to detect targets in images, the original image will be normalized, the size of the original image will be normalized to a fixed size, and the normalized image will be used for target detection. However, because some small targets have very few effective pixels in the original image, after normalization, the effective pixels of small targets are further reduced, and the features of small targets are not prominent enough. When using the deep model for detection, these small targets may not be detected, that is, the current deep model has difficulty in identifying small targets, and the detection results are not accurate enough.
[0029] In view of the above research, an embodiment of the present invention provides a method for detecting an object in an image, such as Figure 1 As shown, including:
[0030] S101, splitting the original image to be detected into multiple sub-images; wherein each sub-image has an overlapping area with its adjacent sub-image;
[0031] S102, inputting the multiple sub-images obtained by splitting into a pre-trained deep model for detection, and obtaining sub-target information corresponding to each sub-image; the sub-target information includes the coordinates of the detection target in the sub-image and the category of the detection target; the deep model is trained using the sub-image containing the detection target;
[0032] S103, obtaining the coordinates of the detection target in the original image and the category of the detection target according to the sub-target information corresponding to each sub-image and the coordinates of each sub-image in the original image.
[0033] In an embodiment of the present invention, an original image to be detected is split into multiple sub-images; each sub-image has an overlapping area with its adjacent sub-image; the multiple sub-images obtained by splitting are respectively input into a pre-trained deep model for detection to obtain sub-target information corresponding to each sub-image; the sub-target information includes the coordinates of the detection target in the sub-image, and the category of the detection target; the deep model is trained using the sub-image containing the detection target; based on the sub-target information corresponding to each sub-image and the coordinates of each sub-image in the original image, the coordinates of the detection target in the original image and the category of the detection target are obtained. In this way, the original image to be detected is split into multiple sub-images, and detection is performed on each sub-image. The ratio of pixel points of the target to be detected in the sub-image to the pixel points of the sub-image is higher than the ratio of pixel points of the target to be detected in the original image to the pixel points of the original image, that is, the ratio of effective pixel points of the target in the sub-image is higher than the ratio of effective pixel points in the original image. The original target information of the corresponding original image is obtained according to the sub-target information of each sub-image, and then the detection result of the original image is obtained. This can improve the accuracy of target detection in the original image, and is especially suitable for the detection of small targets in the image. It can effectively reduce the difficulty of recognizing small targets in the image and improve the detection rate.
[0034] The above S101 to S103 are described in detail below.
[0035] With respect to the above S101, in order to ensure recognition of the target at the edge of the sub-image obtained by splitting, when the original image is split into multiple sub-images, for example, each sub-image may have an overlapping area with its adjacent sub-image.
[0036] Specifically, Figure 2 As shown, a flow chart of a method for splitting an original image to be detected into multiple sub-images provided by an embodiment of the present invention includes:
[0037] S201: Obtaining an overlap size according to a size of a detection target and a first preset ratio between the overlap size and the detection target size.
[0038] In a preferred embodiment, the overlap size can be, for example, 2 to 3 times the size of the detection target, that is, the first preset ratio between the overlap size and the detection target size can include, for example, 2:1 or 3:1. This is only for the purpose of illustrating a preferred embodiment, and does not mean that the first preset ratio only includes the above two. The first preset ratio can be limited in combination with the actual application scenario, and is not limited here.
[0039] S202: Determine a sub-image size according to a normalized size of an input of the depth model and a size of a detection target.
[0040] Here, the sub-image size is related to the size of the detection target, the normalized size of the input of the deep model, and the computational time efficiency requirements. The smaller the detection target, the smaller the sub-image size, the more effective pixels of the detection target, and the higher the recognition efficiency. At the same time, the normalized size of the input of the deep model must also be taken into account. When the sub-image size is the same as the normalized size of the input of the deep model, the sub-image input to the deep model will not be resized. When the sub-image size is smaller than the normalized size of the input of the deep model, the sub-image input to the deep model will be enlarged by the deep model, and the detection target will be enlarged to the same scale. When the sub-image size is larger than the normalized size of the input of the deep model, the sub-image input to the deep model will be reduced, and the detection target will be reduced to the same scale. The smaller the sub-image size, the more sub-images are obtained by splitting the original image, and the longer the deep model recognition time will be.
[0041] Therefore, in the specific implementation process, the range of the sub-image size can be determined according to the size of the detection target and the normalized size of the input of the depth model, and then a sub-image size can be determined from the sub-image size range in combination with the actual application scenario. For example, the range of the sub-image size is determined according to the size of the detection target and the normalized size of the input of the depth model, and then a sub-image size is determined from the range of the sub-image size according to the size of the original image and the recognition time range.
[0042] S203: splitting the original image to be detected into multiple initial sub-images according to the overlapping size and the sub-image size; wherein each initial sub-image has an overlapping area with its adjacent initial sub-images.
[0043] S204: Fill edge sub-images whose sizes are smaller than the sub-image size among the multiple initial sub-images to the sub-image size using pixels of a first preset color.
[0044] Here, the sub-images obtained by splitting the edge positions of the original image may be smaller than the sub-image size, and these edge sub-images with sizes smaller than the sub-image size are filled to the sub-image size using pixels of preset colors.
[0045] S205: taking the initial sub-images whose sizes are equal to the sub-image size and the filled edge sub-images among the multiple initial sub-images as the multiple sub-images after the original image to be detected is split.
[0046] With respect to the above S102, the depth model is pre-trained using sub-images containing detection targets. The depth model can identify and detect detection targets in each sub-image, and output sub-target information corresponding to each sub-image, wherein the sub-target information includes the coordinates of the detection target in the sub-image and the category of the detection target.
[0047] like Figure 3As shown, a flow chart of a method for training a deep model provided by an embodiment of the present invention includes:
[0048] S301: Annotate an original sample image containing a detection target to obtain an annotated image corresponding to the original sample image; wherein the annotated image contains annotation information, and the annotation information includes the coordinates of the detection target in the original sample image and the category of the detection target.
[0049] S302: Split the original sample image and the annotated image corresponding to the original sample image to obtain a plurality of sample sub-images corresponding to the original sample image and a sample annotated sub-image corresponding to each sample sub-image.
[0050] Specifically, Figure 4 As shown, a flow chart of a method for splitting an original sample image and an annotated image corresponding to the original sample image to obtain multiple sample sub-images corresponding to the original sample image and a sample annotated sub-image corresponding to each sample sub-image provided by an embodiment of the present invention includes:
[0051] S401: Split the original sample image according to preset sample sub-image sizes to obtain multiple sample sub-images.
[0052] S402: Split the sample annotated image according to the sample sub-image size and the splitting order of the original sample image to obtain an initial sample annotated sub-image corresponding to each sample sub-image.
[0053] S403: Update the coordinates of the detection target in each initial sample annotated sub-image in the original sample image to the coordinates of the detection target in the initial sample annotated sub-image.
[0054] Among them, the coordinates of the detection target in the initial sample annotated subimage are calculated based on the coordinates of the initial sample annotated subimage in the sample annotated image and the coordinates of the detection target in the original sample image. The coordinates of the detection target in the initial sample annotated subimage represent the coordinates of the detection target in the corresponding sample subimage.
[0055] S404: Process edge annotation information of the initial sample annotated sub-graph corresponding to each sample sub-graph to obtain a sample annotated sub-graph corresponding to each sample sub-graph.
[0056] Specifically, for example, the following method can be used to process the edge annotation information of the initial sample annotated sub-image corresponding to each sample sub-image to obtain the sample annotated sub-image corresponding to each sample sub-image: obtain the annotation box of the detection target in the sample annotated sub-image according to the coordinates of the detection target in the sample annotated sub-image; when the ratio of the area of the annotation box of the annotation information at the edge of the initial sample annotated sub-image to the area of the complete annotation box is less than a second preset ratio, delete the annotation information at the edge of the initial sample annotated sub-image; when the ratio of the area of the annotation box of the annotation information at the edge of the initial sample annotated sub-image to the area of the complete annotation box is not less than the second preset ratio, retain the annotation information at the edge of the initial sample annotated sub-image.
[0057] Here, the coordinates of the detection target in the original sample image include: the coordinates of the upper left corner and the lower right corner of the detection target in the original sample image; when the ratio of the area of the annotation box of the annotation information of the edge of the initial sample annotation sub-image to the area of the complete annotation box is less than the second preset ratio, the annotation information of the edge of the initial sample annotation sub-image is deleted; when the ratio of the area of the annotation box of the annotation information of the edge of the initial sample annotation sub-image to the area of the complete annotation box is not less than the second preset ratio, the annotation information of the edge of the initial sample annotation sub-image is retained, for example, according to the first coordinates of the sample sub-image where the upper left corner coordinates of each detection target are located in the original sample image, and the second coordinates of the sample sub-image where the lower right corner coordinates of each detection target are located in the original sample image, the sample sub-image where each detection target is located after splitting can be determined; the area of each region of the detection target split into different sample sub-images in the corresponding sample sub-image is calculated, and when the ratio of the area corresponding to the region to the area of the complete detection target is less than the second preset ratio, the annotation information of the region in the corresponding initial sample annotation sub-image is deleted, and when the ratio of the area of the region to the area of the complete annotation box is not less than the second preset ratio, the annotation information of the region in the corresponding initial sample annotation sub-image is retained.
[0058] In addition, the annotation box is used to mark the detection target in the sample annotation sub-image, and the annotation box includes, for example, a rectangular box that circles the detection target from the image. The annotation box is determined according to the coordinates of the detection target in the sample annotation sub-image, for example, the coordinates of the upper left corner of the detection target are the upper left corner of the annotation box, and the coordinates of the lower right corner of the detection target are the lower right corner of the annotation box.
[0059] For example, Figure 5As shown, an example diagram of edge annotation information processing for an initial sample annotated sub-image corresponding to each sample sub-image provided by an embodiment of the present invention is provided. Assuming that the sample sub-image where the coordinates of the upper left corner of any detection target in the original sample image are located has a first coordinate (r1, c1) in the original sample image, the initial sample annotated sub-image corresponding to the sample sub-image is recorded as Z1, and the sample sub-image where the coordinates of the lower right corner are located has a second coordinate (r2, c2) in the original sample image. The initial sample annotated sub-image corresponding to the sample sub-image is recorded as Z2, wherein r represents the row number corresponding to the sample sub-image in the original sample image, and c represents the column number of the sample sub-image in the original sample image. The process of edge annotation information processing for the initial sample annotated sub-image corresponding to each sample sub-image includes:
[0060] S501: Determine whether r1 is equal to r2, if so, jump to S502, if not, jump to S503;
[0061] S502: Determine whether c1 is equal to c2, if so, jump to S504, if not, jump to S505;
[0062] S503: Determine whether c1 is equal to c2, if so, jump to S505, if not, jump to S506;
[0063] S504: At this time, each detection target is split into different sample sub-graphs, that is, the detection target is in one sample sub-graph, Z1 and Z2 are the same initial sample labeled sub-graph, and the edge labeling information in the initial sample labeled sub-graph is retained, and the process ends.
[0064] S505: At this time, the detection target is split into two sample sub-images, and the two sample sub-images are located in the same row or the same column in the original sample image. The area of the region in the sample sub-image where the coordinates of the upper left corner of the detection target are located is recorded as O1, and the area of the region in the sample sub-image where the lower right corner of the detection target is located is recorded as O2. The area of the detection target is recorded as O. When O1 / O is less than the second preset ratio, the edge annotation information in Z1 is deleted. When O1 / O is not less than the second preset ratio, the edge annotation information in Z1 is retained. When O2 / O is less than the second preset ratio, the edge annotation information in Z2 is deleted. When O2 / O is not less than the second preset ratio, the edge annotation information in Z2 is retained, and the process ends.
[0065] S506: At this time, the detection target is split into four sample sub-images, the area of the region in the sample sub-image where the coordinates of the upper left corner of the detection target are located is recorded as O1, the area of the region in the sample sub-image where the lower right corner of the detection target is located is recorded as O2, the area of the region in the sample sub-image where the lower left corner of the detection target is located is recorded as O3, and its corresponding initial labeled sample sub-image is recorded as Z3, the area of the region in the sample sub-image where the upper right corner of the detection target is located is recorded as O4, and its corresponding initial labeled sample sub-image is recorded as Z4, and the area of the detection target is recorded as O. When O1 / O is less than the second preset ratio, the edge annotation information in Z1 is deleted. When O1 / O is not less than the second preset ratio, the edge labeling information in Z1 is retained; when O2 / O is less than the second preset ratio, the edge labeling information in Z2 is deleted; when O2 / O is not less than the second preset ratio, the edge labeling information in Z2 is retained; when O3 / O is less than the second preset ratio, the edge labeling information in Z3 is deleted; when O3 / O is not less than the second preset ratio, the edge labeling information in Z3 is retained; when O4 / O is less than the second preset ratio, the edge labeling information in Z4 is deleted; when O4 / O is not less than the second preset ratio, the edge labeling information in Z4 is retained.
[0066] In addition, when the original sample image and the sample annotated image corresponding to the original sample image are split, for the sample sub-image located at the edge and the sample annotated sub-image located at the edge, if the size is smaller than the sample sub-image size, pixels of a second preset color can be used to fill them to the sample sub-image size.
[0067] S303: According to the sample annotated subgraph corresponding to each sample subgraph, extract the sample annotated subgraph containing the annotation information and the sample subgraph corresponding to the sample annotated subgraph containing the annotation information to form a training sample set and a test sample set.
[0068] Here, in the process of splitting the sample annotated image, some initial sample annotated subgraphs do not contain annotation information, and some initial sample annotated subgraphs containing annotation information no longer contain annotation information after edge annotation information processing. These sample annotated subgraphs that do not contain annotation information and their corresponding sample subgraphs will affect the training accuracy of the deep model. Therefore, sample annotated subgraphs that contain annotation information and sample subgraphs corresponding to these sample annotated subgraphs containing annotation information are selected from the sample annotated subgraphs to form a training sample set and a test sample set.
[0069] S304: Train the initial depth model using the training sample set to obtain an intermediate depth model.
[0070] S305: Testing the intermediate depth model using the test sample set, and obtaining a trained depth model when the output error of the intermediate depth model is less than a preset error.
[0071] Regarding the above S103, if Figure 6 As shown, a flowchart of a method for obtaining the coordinates of a detection target in an original image and the category of the detection target according to sub-target information corresponding to each sub-image and the coordinates of each sub-image in the original image provided by an embodiment of the present invention includes:
[0072] S601: According to the coordinates of each sub-image in the original image, convert the sub-target information corresponding to each sub-image output by the depth model into the original target information corresponding to the original image, and obtain a first target information set; wherein the original target information includes the coordinates of the detection target in each sub-image in the original image and the category of the detection target, and the first target information set includes first redundant original target information caused by the depth model and second redundant original target information caused by converting the target information corresponding to the sub-image into the target information corresponding to the original image.
[0073] Here, because each sub-image has an overlapping area with its adjacent sub-image when the original image is split, when the sub-target information corresponding to each sub-image is converted into the original target information corresponding to the original image, the coordinates and categories of the overlapping area are redundant, that is, the second redundant original target information appears. The redundant original target information will be intertwined, affecting the recognition of the detection target.
[0074] In addition, when the deep model detects a sub-image, it generates more than one sub-target information for each detected target (that is, each detected target has more than one coordinate and category in the labeled sub-image). Therefore, there is redundant sub-target information. The original target information after the redundant sub-target information is converted is also redundant original target information, that is, there is first redundant original target information. These redundant original target information are intertwined, affecting the detection accuracy of the detected target.
[0075] S602: The original target information contained in the first target information set is taken as the first original target information, and a first non-maximum suppression operation is performed on the first original target information to obtain a second target information set; the second target information set contains second redundant original target information resulting from the conversion of target information corresponding to the sub-image into target information corresponding to the original image.
[0076] Here, the first original target information is the original target information contained in the first target information set (including the original target information corresponding to the original image converted from the sub-target information corresponding to the detection target in each sub-image, and these original target information include first redundant original target information and second redundant original target information). The first maximum suppression operation can delete the first redundant original target information in the first target information set to obtain the second target information set.
[0077] In one embodiment of the present invention, after the multiple sub-images obtained by splitting are respectively input into a pre-trained deep model for detection, the matching degree between the sub-target information corresponding to each sub-image and the detection target is obtained; according to the coordinates of each sub-image in the original image, the target information corresponding to each sub-image output by the deep model is converted into the target information corresponding to the original image, and after the first target information set is obtained, the matching degree between each original target information in the first target information set and the detection target is obtained according to the matching degree between the sub-target information corresponding to each sub-image and the detection target; specifically, for example, the following method can be used to perform a first non-maximum suppression operation on the first original target information to obtain the second target information set:
[0078] Step 1: Select the first original target information with the highest matching degree with the detection target from the first original target information;
[0079] Step 2: Calculate the first overlap between each of the other first original target information and the target first original target information;
[0080] Step 3: deleting the first original target information whose first overlap degree is greater than the first preset threshold, and retaining the first original target information whose first overlap degree is not greater than the first preset threshold;
[0081] Step 4: Determine whether the amount of the retained first original target information is 0, if not 0, execute step 5, if 0, terminate the execution, and obtain the second target information set;
[0082] Step 5: Select the new target first original target information with the highest matching degree with the detection target from the retained first original target information;
[0083] Step 6: Calculate the first overlap between each of the other first original target information in the retained first original target information and the first original target information of the new target, and jump to step 3;
[0084] The first degree of overlap is calculated, including:
[0085] According to the coordinates of the detection target contained in the first original target information in the original image, the position area of the detection target corresponding to the first original target information in the original image is obtained; according to the ratio of the intersection area between the position areas of the detection targets corresponding to the two first original target information in the original image and the union area between the position areas of the detection targets corresponding to the two first original target information in the original image, the first overlap degree between the two first original target information is obtained.
[0086] S603: taking the original target information included in the second target information set as the second original target information, performing a second non-maximum suppression operation on the second original target information, and obtaining a final target information set corresponding to the original image.
[0087] Here, the second original target information is the original target information contained in the second target information set, and the second original target information includes second redundant original target information. The second redundant original target information in the second original target information can be deleted through the second maximum suppression operation to obtain the final target information set.
[0088] In one embodiment of the present invention, after the multiple sub-images obtained by splitting are respectively input into a pre-trained deep model for detection, the matching degree between the sub-target information corresponding to each sub-image and the detection target is obtained; according to the coordinates of each sub-image in the original image, the target information corresponding to each sub-image output by the deep model is converted into the target information corresponding to the original image, and after the first target information set is obtained, the matching degree between each original target information in the first target information set and the detection target is obtained according to the matching degree between the sub-target information corresponding to each sub-image and the detection target; specifically, for example, the following method can be used to perform a second non-maximum suppression operation on the second original target information to obtain the final target information set corresponding to the original image:
[0089] Step 1: Select the second original target information with the highest matching degree with the detection target from the second original target information;
[0090] Step 2: Calculate the second overlap between each of the other second original target information and the target second original target information;
[0091] Step 3: deleting the second original target information whose second overlap degree is greater than the second preset threshold, and retaining the second original target information whose second overlap degree is not greater than the second preset threshold;
[0092] Step 4: Determine whether the amount of the retained second original target information is 0, if not 0, execute step 5, if 0, terminate the execution, and obtain the final target information set;
[0093] Step 5: Select the new target second original target information with the highest matching degree with the detection target from the retained second original target information;
[0094] Step 6: Calculate the second overlap between the other second original target information in the retained second original target information and the new target second original target information, and jump to step 3;
[0095] The second overlap degree is calculated, including:
[0096] According to the coordinates of the detection target contained in the first original target information in the original image, the position area of the detection target corresponding to the first original target information in the original image is obtained; according to the ratio of the intersection area between the position areas of the detection targets corresponding to the two second original target information in the original image and the area of the position area of the detection target corresponding to the second original target information with the smallest area among the position areas of the detection targets corresponding to the two second original target information in the original image, the second overlap degree between the two second original target information is obtained.
[0097] S604: Obtain the coordinates of the detected target in the original image and the category of the detected target according to each piece of original target information included in the final target information set corresponding to the original image.
[0098] The present invention also provides a device for detecting an object in an image, as described in the following embodiments. Since the principle of the device to solve the problem is similar to the method for detecting an object in an image, the implementation of the device can refer to the implementation of the method for detecting an object in an image, and the repeated parts will not be repeated.
[0099] like Figure 7 FIG. 1 is a schematic diagram of a device for detecting a target in an image provided by an embodiment of the present invention, comprising: an image segmentation module 701, a detection module 702, and a target information processing module 703; wherein
[0100] An image splitting module 701 is used to split the original image to be detected into multiple sub-images; wherein each sub-image has an overlapping area with its adjacent sub-images;
[0101] The detection module 702 is used to input the multiple sub-images obtained by splitting into a pre-trained deep model for detection, and obtain sub-target information corresponding to each sub-image; the sub-target information includes the coordinates of the detection target in the sub-image and the category of the detection target; the deep model is trained using the sub-image containing the detection target;
[0102] The target information processing module 703 is used to obtain the coordinates of the detection target in the original image and the category of the detection target according to the sub-target information corresponding to each sub-image and the coordinates of each sub-image in the original image.
[0103] In one possible implementation, an image splitting module is specifically used to obtain an overlapping size according to the size of a detection target and a first preset ratio between the overlapping size and the detection target size; determine a sub-image size according to a normalized size of an input of the depth model and the size of the detection target; split an original image to be detected according to the overlapping size and the sub-image size to obtain a plurality of initial sub-images; wherein each initial sub-image has an overlapping area with an adjacent initial sub-image; fill edge sub-images of the plurality of initial sub-images whose size is smaller than the sub-image size with pixels of a first preset color to the sub-image size; and use the initial sub-images of the plurality of initial sub-images whose size is equal to the sub-image size and the filled edge sub-images as the plurality of sub-images after the original image to be detected is split.
[0104] In a possible implementation, a target information processing module is specifically used to convert sub-target information corresponding to each sub-image output by a depth model into original target information corresponding to the original image according to the coordinates of each sub-image in the original image, so as to obtain a first target information set; wherein the original target information includes the coordinates of the detection targets in each sub-image in the original image and the category of the detection targets, and the first target information set includes first redundant original target information caused by the depth model and second redundant original target information caused by converting the target information corresponding to the sub-image into the target information corresponding to the original image; the original target information included in the first target information set is used as the first original target information, and a first non-maximum suppression operation is performed on the first original target information to obtain a second target information set; the second target information set includes second redundant original target information caused by converting the target information corresponding to the sub-image into the target information corresponding to the original image; the original target information included in the second target information set is used as the second original target information, and a second non-maximum suppression operation is performed on the second original target information to obtain a final target information set corresponding to the original image; according to each original target information included in the final target information set corresponding to the original image, the coordinates of the detection targets in the original image and the category of the detection targets are obtained.
[0105] In a possible implementation, the detection module is further used to input the multiple sub-images obtained by splitting into a pre-trained deep model for detection, and obtain the matching degree between the sub-target information corresponding to each sub-image and the detection target; the target information processing module is further used to obtain the matching degree between each original target information in the first target information set and the detection target according to the matching degree between the sub-target information corresponding to each sub-image and the detection target;
[0106] The target information processing module is specifically used to perform the following steps:
[0107] Step 1: Select the first original target information of the target with the highest matching degree with the detection target from the first original target information; Step 2: Calculate the first overlap between each other first original target information and the target first original target information; Step 3: Delete the first original target information whose first overlap degree is greater than the first preset threshold, and retain the first original target information whose first overlap degree is not greater than the first preset threshold; Step 4: Determine whether the number of retained first original target information is 0, if not 0, execute step 5, if 0, end the execution, and obtain the second target information set; Step 5: Select the new first original target with the highest matching degree with the detection target from the retained first original target information Information; Step 6: Calculate the first degree of overlap between the other first original target information in the retained first original target information and the first original target information of the new target, and jump to Step 3; wherein calculating the first degree of overlap includes: obtaining the position area of the detection target in the original image corresponding to the first original target information according to the coordinates of the detection target in the original image contained in the first original target information; obtaining the first degree of overlap between the two first original target information according to the ratio of the intersection area between the position areas of the detection targets in the original image corresponding to the two first original target information and the union area between the position areas of the detection targets in the original image corresponding to the two first original target information.
[0108] In a possible implementation, the detection module is further used to input the multiple sub-images obtained by splitting into a pre-trained deep model for detection, and then obtain the matching degree between the sub-target information corresponding to each sub-image and the detection target; the target information processing module is also used to obtain the matching degree between each original target information in the first target information set and the detection target based on the matching degree between the sub-target information corresponding to each sub-image and the detection target; the target information processing module is specifically used to perform the following steps: Step 1: Select the target second original target information with the highest matching degree with the detection target from the second original target information; Step 2: Calculate the second overlap between each other second original target information and the target second original target information; Step 3: Delete the second original target information whose second overlap is greater than the second preset threshold, and retain the second original target information whose second overlap is not greater than the second preset threshold; Step 4: Determine whether the number of retained second original target information is 0, if not If it is 0, execute step 5, if it is 0, end the execution and obtain the final target information set; Step 5: Select the second original target information of the new target with the highest matching degree with the detection target from the retained second original target information; Step 6: Calculate the second overlap between other second original target information in the retained second original target information and the second original target information of the new target, and jump to step 3; wherein, calculating the second overlap includes: obtaining the position area of the detection target in the original image corresponding to the first original target information according to the coordinates of the detection target in the original image contained in the first original target information; obtaining the second overlap between the two second original target information according to the ratio of the intersection area between the position areas of the detection targets in the original image corresponding to the two second original target information and the area of the position area of the detection target in the original image corresponding to the second original target information with the smallest area among the position areas of the detection targets in the original image corresponding to the two second original target information.
[0109] In a possible implementation, it also includes: a model training module, which is used to annotate the original sample image containing the detection target to obtain a sample annotated image corresponding to the original sample image; wherein the sample annotated image contains annotation information, and the annotation information contains the coordinates of the detection target in the original sample image and the category of the detection target; the original sample image and the sample annotated image corresponding to the original sample image are split to obtain multiple sample sub-images corresponding to the original sample image and a sample annotated sub-image corresponding to each sample sub-image; according to the sample annotated sub-image corresponding to each sample sub-image, the sample annotated sub-image containing the annotation information and the sample sub-image corresponding to the sample annotated sub-image containing the annotation information are extracted to form a training sample set and a test sample set; the initial depth model is trained using the training sample set to obtain an intermediate depth model; the intermediate depth model is tested using the test sample set, and when the output error of the intermediate depth model is less than the preset error, a trained depth model is obtained.
[0110] In a possible implementation, the model training module is specifically used to split the original sample image according to a preset sample sub-image size to obtain multiple sample sub-images; split the sample annotated image according to the sample sub-image size and the splitting order of the original sample image to obtain an initial sample annotated sub-image corresponding to each sample sub-image; update the coordinates of the detection target in each initial sample annotated sub-image in the original sample image to the coordinates of the detection target in the initial sample annotated sub-image; wherein the coordinates of the detection target in the initial sample annotated sub-image are calculated based on the coordinates of the initial sample annotated sub-image in the sample annotated image and the coordinates of the detection target in the original sample image; for each sample sub-image corresponding to The initial sample labeled sub-graph is processed with edge labeling information to obtain a sample labeled sub-graph corresponding to each sample sub-graph; wherein, the edge labeling information of the initial sample labeled sub-graph corresponding to each sample sub-graph is processed, including: obtaining a labeling frame of the detection target in the sample labeled sub-graph according to the coordinates of the detection target in the sample labeled sub-graph; when the ratio of the area of the labeling frame of the labeling information at the edge of the initial sample labeled sub-graph to the area of the complete labeling frame is less than a second preset ratio, deleting the labeling information at the edge of the initial sample labeled sub-graph, and when the ratio of the area of the labeling frame of the labeling information at the edge of the initial sample labeled sub-graph to the area of the complete labeling frame is not less than the second preset ratio, retaining the labeling information at the edge of the initial sample labeled sub-graph.
[0111] In a possible implementation, the coordinates of the detection target in the original sample image include: the coordinates of the upper left corner and the coordinates of the lower right corner of the detection target in the original sample image; a model training module is specifically used to determine the sample sub-image where each detection target is located after splitting according to the first coordinates of the sample sub-image where the upper left corner coordinates of each detection target are located in the original sample image, and the second coordinates of the sample sub-image where the lower right corner coordinates of each detection target are located in the original sample image; calculate the area of each region of the detection target split into different sample sub-images in the corresponding sample sub-image, and when the ratio of the area corresponding to the region to the area of the complete detection target is less than a second preset ratio, delete the annotation information of the region in the corresponding initial sample annotation sub-image, and when the ratio of the area of the region to the area of the complete annotation box is not less than the second preset ratio, retain the annotation information of the region in the corresponding initial sample annotation sub-image.
[0112] An embodiment of the present invention further provides a computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above-mentioned method for detecting targets in an image when executing the computer program.
[0113] An embodiment of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method for detecting an object in an image is implemented.
[0114] An embodiment of the present invention further provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the computer program implements the above-mentioned method for detecting an object in an image.
[0115] In an embodiment of the present invention, an original image to be detected is split into multiple sub-images; each sub-image has an overlapping area with its adjacent sub-image; the multiple sub-images obtained by splitting are respectively input into a pre-trained deep model for detection to obtain sub-target information corresponding to each sub-image; the sub-target information includes the coordinates of the detection target in the sub-image, and the category of the detection target; the deep model is trained using the sub-image containing the detection target; based on the sub-target information corresponding to each sub-image and the coordinates of each sub-image in the original image, the coordinates of the detection target in the original image and the category of the detection target are obtained. In this way, the original image to be detected is split into multiple sub-images, and detection is performed on each sub-image. The ratio of pixel points of the target to be detected in the sub-image to the pixel points of the sub-image is higher than the ratio of pixel points of the target to be detected in the original image to the pixel points of the original image, that is, the ratio of effective pixel points of the target in the sub-image is higher than the ratio of effective pixel points in the original image. The original target information of the corresponding original image is obtained according to the sub-target information of each sub-image, and then the detection result of the original image is obtained. This can improve the accuracy of target detection in the original image, and is especially suitable for the detection of small targets in the image. It can effectively reduce the difficulty of recognizing small targets in the image and improve the detection rate.
[0116] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0117] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0118] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0119] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0120] The specific embodiments described above further illustrate the objectives, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above description is only a specific embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.
Claims
1. A method for detecting an object in an image, characterized in that: include: The original image to be detected is split into multiple sub-images; each sub-image has an overlapping area with its adjacent sub-image; The multiple sub-images obtained by splitting are respectively input into a pre-trained deep model for detection to obtain sub-target information corresponding to each sub-image; the sub-target information includes the coordinates of the detection target in the sub-image and the category of the detection target; the deep model is trained using the sub-image containing the detection target; According to the sub-target information corresponding to each sub-image and the coordinates of each sub-image in the original image, the coordinates of the detection target in the original image and the category of the detection target are obtained; According to the sub-target information corresponding to each sub-image and the coordinates of each sub-image in the original image, the coordinates of the detected target in the original image and the category of the detected target are obtained, including: According to the coordinates of each sub-image in the original image, the sub-target information corresponding to each sub-image output by the deep model is converted into the original target information corresponding to the original image, so as to obtain a first target information set; wherein the original target information includes the coordinates of the detection target in each sub-image in the original image and the category of the detection target, and the first target information set includes the first redundant original target information caused by the deep model and the second redundant original target information caused by converting the target information corresponding to the sub-image into the target information corresponding to the original image; The original target information contained in the first target information set is used as the first original target information, and a first non-maximum suppression operation is performed on the first original target information to obtain a second target information set; the second target information set contains second redundant original target information resulting from converting the target information corresponding to the sub-image into the target information corresponding to the original image; The original target information contained in the second target information set is used as the second original target information, and a second non-maximum suppression operation is performed on the second original target information to obtain a final target information set corresponding to the original image; According to each piece of original target information contained in the final target information set corresponding to the original image, the coordinates of the detected target in the original image and the category of the detected target are obtained.
2. The detection method according to claim 1, characterized in that The original image to be detected is split into multiple sub-images, including: Obtaining an overlap size according to a size of the detection target and a first preset ratio between the overlap size and the detection target size; Determining a sub-image size according to a normalized size of an input of the depth model and a size of a detection target; The original image to be detected is split according to the overlap size and the sub-image size to obtain a plurality of initial sub-images; wherein each initial sub-image has an overlap area with an adjacent initial sub-image; Filling edge sub-images whose sizes are smaller than the sub-image size among the multiple initial sub-images to the sub-image size using pixels of a first preset color; The initial sub-images whose sizes are equal to the sub-image size and the filled edge sub-images among the multiple initial sub-images are used as the multiple sub-images after the original image to be detected is split.
3. The detection method according to claim 1, characterized in that After the multiple sub-images obtained by splitting are input into the pre-trained deep model for detection, the method further includes: Get the matching degree between the sub-target information corresponding to each sub-image and the detection target; According to the coordinates of each sub-image in the original image, the target information corresponding to each sub-image output by the depth model is converted into the target information corresponding to the original image, and after the first target information set is obtained, the method further includes: According to the matching degree between the sub-target information corresponding to each sub-image and the detection target, the matching degree between each original target information in the first target information set and the detection target is obtained; Performing a first non-maximum suppression operation on the first original target information to obtain a second target information set, including: Step 1: Select the first original target information with the highest matching degree with the detection target from the first original target information; Step 2: Calculate the first overlap between each of the other first original target information and the target first original target information; Step 3: deleting the first original target information whose first overlap degree is greater than the first preset threshold, and retaining the first original target information whose first overlap degree is not greater than the first preset threshold; Step 4: Determine whether the amount of the retained first original target information is 0, if not 0, execute step 5, if 0, terminate the execution, and obtain the second target information set; Step 5: Select the new target first original target information with the highest matching degree with the detection target from the retained first original target information; Step 6: Calculate the first overlap between each of the other first original target information in the retained first original target information and the first original target information of the new target, and jump to step 3; The first degree of overlap is calculated, including: Obtaining a location area of the detection target in the original image corresponding to the first original target information according to the coordinates of the detection target in the original image contained in the first original target information; The first degree of overlap between the two first original target information is obtained according to the ratio of the intersection area between the position areas of the detection targets corresponding to the two first original target information in the original image and the union area between the position areas of the detection targets corresponding to the two first original target information in the original image.
4. The detection method according to claim 1, characterized in that After the multiple sub-images obtained by splitting are input into the pre-trained deep model for detection, the method further includes: Get the matching degree between the sub-target information corresponding to each sub-image and the detection target; According to the coordinates of each sub-image in the original image, the target information corresponding to each sub-image output by the depth model is converted into the target information corresponding to the original image, and after the first target information set is obtained, the method further includes: According to the matching degree between the sub-target information corresponding to each sub-image and the detection target, the matching degree between each original target information in the first target information set and the detection target is obtained; Performing a second non-maximum suppression operation on the second original target information, obtaining a final target information set corresponding to the original image, including: Step 1: Select the second original target information with the highest matching degree with the detection target from the second original target information; Step 2: Calculate the second overlap between each of the other second original target information and the target second original target information; Step 3: deleting the second original target information whose second overlap degree is greater than the second preset threshold, and retaining the second original target information whose second overlap degree is not greater than the second preset threshold; Step 4: Determine whether the amount of the retained second original target information is 0, if not 0, execute step 5, if 0, terminate the execution, and obtain the final target information set; Step 5: Select the new target second original target information with the highest matching degree with the detection target from the retained second original target information; Step 6: Calculate the second overlap between the other second original target information in the retained second original target information and the new target second original target information, and jump to step 3; The second overlap degree is calculated, including: Obtaining a location area of the detection target in the original image corresponding to the first original target information according to the coordinates of the detection target in the original image contained in the first original target information; The second degree of overlap between the two second original target information is obtained based on the ratio of the intersection area between the position areas of the detection targets corresponding to the two second original target information in the original image and the area of the position area of the detection target corresponding to the second original target information with the smallest area among the position areas of the detection targets corresponding to the two second original target information in the original image.
5. The detection method according to claim 1, characterized in that Before splitting the original image to be detected into multiple sub-images, it also includes: Annotate the original sample image containing the detection target to obtain a sample annotated image corresponding to the original sample image; wherein the sample annotated image contains annotation information, and the annotation information includes the coordinates of the detection target in the original sample image and the category of the detection target; The original sample image and the sample annotation image corresponding to the original sample image are split to obtain a plurality of sample sub-images corresponding to the original sample image and a sample annotation sub-image corresponding to each sample sub-image; According to the sample annotated subgraph corresponding to each sample subgraph, the sample annotated subgraph containing the annotation information and the sample subgraph corresponding to the sample annotated subgraph containing the annotation information are extracted to form a training sample set and a test sample set; Use the training sample set to train the initial depth model to obtain an intermediate depth model; The intermediate depth model is tested using the test sample set. When the output error of the intermediate depth model is less than the preset error, a trained depth model is obtained.
6. The detection method according to claim 5, characterized in that The original sample image and the sample annotation image corresponding to the original sample image are split to obtain multiple sample sub-images corresponding to the original sample image and a sample annotation sub-image corresponding to each sample sub-image, including: Split the original sample image according to the preset sample sub-image size to obtain multiple sample sub-images; The sample annotation image is split according to the sample sub-image size and the splitting order of the original sample image to obtain an initial sample annotation sub-image corresponding to each sample sub-image; The coordinates of the detection target in each initial sample annotated sub-image in the original sample image are updated to the coordinates of the detection target in the initial sample annotated sub-image; wherein the coordinates of the detection target in the initial sample annotated sub-image are calculated based on the coordinates of the initial sample annotated sub-image in the sample annotated image and the coordinates of the detection target in the original sample image, and the coordinates of the detection target in the initial sample annotated sub-image represent the coordinates of the detection target in the corresponding sample sub-image; Processing edge annotation information of the initial sample annotation subgraph corresponding to each sample subgraph to obtain a sample annotation subgraph corresponding to each sample subgraph; The edge annotation information processing is performed on the initial sample annotation sub-graph corresponding to each sample sub-graph, including: Obtain a labeling box of the detection target in the sample labeling sub-image according to the coordinates of the detection target in the sample labeling sub-image; When the ratio of the area of the annotation box of the annotation information of the edge of the initial sample annotation sub-image to the area of the complete annotation box is less than a second preset ratio, the annotation information of the edge of the initial sample annotation sub-image is deleted; when the ratio of the area of the annotation box of the annotation information of the edge of the initial sample annotation sub-image to the area of the complete annotation box is not less than the second preset ratio, the annotation information of the edge of the initial sample annotation sub-image is retained.
7. The detection method according to claim 6, characterized in that The coordinates of the detection target in the original sample image include: the coordinates of the upper left corner and the coordinates of the lower right corner of the detection target in the original sample image; When the ratio of the area of the annotation box of the annotation information of the edge of the initial sample annotation sub-image to the area of the complete annotation box is less than a second preset ratio, the annotation information of the edge of the initial sample annotation sub-image is deleted; when the ratio of the area of the annotation box of the annotation information of the edge of the initial sample annotation sub-image to the area of the complete annotation box is not less than the second preset ratio, the annotation information of the edge of the initial sample annotation sub-image is retained, including: Determine the sample sub-image where each detection target is located after being split according to the first coordinate of the sample sub-image where the coordinates of the upper left corner of each detection target are located in the original sample image, and the second coordinate of the sample sub-image where the coordinates of the lower right corner of each detection target are located in the original sample image; The area of each region of the detection target split into different sample sub-images in the corresponding sample sub-image is calculated. When the ratio of the area corresponding to the region to the area of the complete detection target is less than a second preset ratio, the annotation information of the region in the corresponding initial sample annotation sub-image is deleted. When the ratio of the area of the region to the area of the complete annotation box is not less than the second preset ratio, the annotation information of the region in the corresponding initial sample annotation sub-image is retained.
8. A device for detecting an object in an image, characterized in that: include: An image splitting module is used to split the original image to be detected into multiple sub-images; wherein each sub-image has an overlapping area with its adjacent sub-images; A detection module, used to input the multiple sub-images obtained by splitting into a pre-trained deep model for detection, and obtain sub-target information corresponding to each sub-image; the sub-target information includes the coordinates of the detection target in the sub-image and the category of the detection target; the deep model is trained using the sub-image containing the detection target; The target information processing module is used to obtain the coordinates of the detection target in the original image and the category of the detection target according to the sub-target information corresponding to each sub-image and the coordinates of each sub-image in the original image; According to the sub-target information corresponding to each sub-image and the coordinates of each sub-image in the original image, the coordinates of the detected target in the original image and the category of the detected target are obtained, including: According to the coordinates of each sub-image in the original image, the sub-target information corresponding to each sub-image output by the deep model is converted into the original target information corresponding to the original image, so as to obtain a first target information set; wherein the original target information includes the coordinates of the detection target in each sub-image in the original image and the category of the detection target, and the first target information set includes the first redundant original target information caused by the deep model and the second redundant original target information caused by converting the target information corresponding to the sub-image into the target information corresponding to the original image; The original target information contained in the first target information set is used as the first original target information, and a first non-maximum suppression operation is performed on the first original target information to obtain a second target information set; the second target information set contains second redundant original target information resulting from converting the target information corresponding to the sub-image into the target information corresponding to the original image; The original target information contained in the second target information set is used as the second original target information, and a second non-maximum suppression operation is performed on the second original target information to obtain a final target information set corresponding to the original image; According to each piece of original target information contained in the final target information set corresponding to the original image, the coordinates of the detected target in the original image and the category of the detected target are obtained.
9. The detection device according to claim 8, characterized in that: The image splitting module is specifically used to obtain the overlap size according to the size of the detection target and a first preset ratio between the overlap size and the detection target size; Determining a sub-image size according to a normalized size of an input of the depth model and a size of a detection target; Splitting the original image to be detected according to the overlap size and the sub-image size to obtain a plurality of initial sub-images; Each initial subgraph has an overlapping area with its adjacent initial subgraph; Filling edge sub-images whose sizes are smaller than the sub-image size among the multiple initial sub-images to the sub-image size using pixels of a first preset color; The initial sub-images whose sizes are equal to the sub-image size and the filled edge sub-images among the multiple initial sub-images are used as the multiple sub-images after the original image to be detected is split.
10. The detection device according to claim 8, characterized in that: Also includes: The model training module is used to annotate the original sample image containing the detection target to obtain a sample annotated image corresponding to the original sample image; wherein the sample annotated image contains annotation information, and the annotation information includes the coordinates of the detection target in the original sample image and the category of the detection target; The original sample image and the sample annotation image corresponding to the original sample image are split to obtain a plurality of sample sub-images corresponding to the original sample image and a sample annotation sub-image corresponding to each sample sub-image; According to the sample annotated subgraph corresponding to each sample subgraph, the sample annotated subgraph containing the annotation information and the sample subgraph corresponding to the sample annotated subgraph containing the annotation information are extracted to form a training sample set and a test sample set; Use the training sample set to train the initial depth model to obtain an intermediate depth model; The intermediate depth model is tested using the test sample set. When the output error of the intermediate depth model is less than the preset error, a trained depth model is obtained.
11. The detection device according to claim 10, characterized in that: The model training module is specifically used to split the original sample image according to the preset sample sub-image size to obtain multiple sample sub-images; The sample annotation image is split according to the sample sub-image size and the splitting order of the original sample image to obtain an initial sample annotation sub-image corresponding to each sample sub-image; The coordinates of the detection target in each initial sample annotated sub-image in the original sample image are updated to the coordinates of the detection target in the initial sample annotated sub-image; wherein the coordinates of the detection target in the initial sample annotated sub-image are calculated based on the coordinates of the initial sample annotated sub-image in the sample annotated image and the coordinates of the detection target in the original sample image; Processing edge annotation information of the initial sample annotation subgraph corresponding to each sample subgraph to obtain a sample annotation subgraph corresponding to each sample subgraph; The edge annotation information processing is performed on the initial sample annotation sub-graph corresponding to each sample sub-graph, including: Obtain a labeling box of the detection target in the sample labeling sub-image according to the coordinates of the detection target in the sample labeling sub-image; When the ratio of the area of the annotation box of the annotation information of the edge of the initial sample annotation sub-image to the area of the complete annotation box is less than a second preset ratio, the annotation information of the edge of the initial sample annotation sub-image is deleted; when the ratio of the area of the annotation box of the annotation information of the edge of the initial sample annotation sub-image to the area of the complete annotation box is not less than the second preset ratio, the annotation information of the edge of the initial sample annotation sub-image is retained.
12. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the method according to any one of claims 1 to 7 is implemented.
13. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
14. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
High-resolution field image rice ear detection and counting method based on deep learning
CN112069985A