Disclosure of Invention
In view of the above technical problems, the present invention provides a method, system, device and storage medium for pig weight estimation based on images.
The technical scheme for solving the technical problems is as follows:
in a first aspect, the invention provides an image-based pig weight estimation method, which comprises the following steps:
acquiring an image of a pig in a target area;
adopting an image processing algorithm to segment the outline of the pig in the image;
judging whether the contour is complete;
and if the profile is incomplete, matching a most similar complete profile according to the incomplete profile, and taking the weight of the pig corresponding to the complete profile as the weight of the pig corresponding to the incomplete profile.
On the basis of the technical scheme, the invention can be further improved as follows.
Further, the determining whether the contour is complete specifically includes:
and inputting the contour into a pre-constructed CNN classification model, and judging whether the contour is complete or not.
Further, still include:
and if the contour is complete, estimating the weight of the corresponding pig according to the complete contour.
Further, the estimating the weight of the corresponding pig according to the complete profile specifically includes:
and inputting the pixel area of the outline into a conversion formula, and calculating to obtain the corresponding weight of the pig.
Further, before inputting the pixel area of the contour into a conversion formula and calculating the weight of the corresponding pig, the method further comprises the following steps:
identifying a breed of pig in the image;
and determining a corresponding conversion formula according to the identified pig breeds.
Further, the matching a most similar complete contour according to the incomplete contour specifically includes:
and inputting the incomplete contour into a pre-trained deep learning model to obtain a most similar complete contour.
Further, the training method of the deep learning model comprises the following steps:
constructing a batch of complete pig images and incomplete pig images, covering pigs of different body types and sizes, marking a matching pair as a label to train a deep learning model, inputting the deep learning model into the pig images and the segmentation contour images of the pigs, and outputting whether the pig images are matched or not.
In a second aspect, the present invention provides an image-based pig weight estimation system, comprising:
the image acquisition module is used for acquiring an image of the pig in the target area;
the image segmentation module is used for segmenting the outline of the pig in the image by adopting an image processing algorithm;
the contour judging module is used for judging whether the contour is complete or not;
the contour matching module is used for matching a most similar complete contour according to the incomplete contour if the contour judging module judges that the contour is incomplete;
and the weight estimation module is used for taking the weight of the pig corresponding to the complete contour as the weight of the pig corresponding to the incomplete contour.
Further, the weight estimation module is further configured to estimate the weight of the corresponding pig according to the complete contour if the contour judgment module judges that the contour is complete.
Further, the weight estimation module estimates the weight of the corresponding pig according to the complete contour, and specifically comprises:
and inputting the pixel area of the outline into a conversion formula, and calculating to obtain the corresponding weight of the pig.
Further, still include:
the breed identification module is used for identifying the breeds of the pigs in the image before the weight estimation module inputs the pixel area of the outline into a conversion formula and calculates the weight of the corresponding pigs;
and the formula determination module is used for determining a corresponding conversion formula according to the identified pig breed.
In a third aspect, the present invention provides a terminal device, including:
a processor; and
a memory having executable code stored thereon, which when executed by the processor, causes the processor to perform the method described above.
In a fourth aspect, the present invention provides a non-transitory machine-readable storage medium having stored thereon executable code, which when executed by a processor of an electronic device, causes the processor to perform the above-described method.
The invention has the beneficial effects that: the weight of the incomplete pig in the image can be estimated, the technical problem that the weight cannot be estimated due to the incomplete target is solved, the automation degree of the weight measurement of the pig in a pig farm is greatly improved, and the required manpower and material resources are reduced.
Detailed Description
The principles and features of this invention are described below in conjunction with the following drawings, which are set forth by way of illustration only and are not intended to limit the scope of the invention.
Fig. 1 is a flowchart of a pig weight estimation method based on an image according to an embodiment of the present invention, as shown in fig. 1, the method includes:
110. acquiring an image of a pig in a target area;
specifically, as shown in fig. 2, a camera may be arranged at the top of the pigsty to shoot the pigs in the target area of the lower pigsty, and the camera sends the images back to the computer for subsequent processing, and the shot images of the pigs are shown in fig. 3.
120. Adopting an image processing algorithm to segment the outline of the pig in the image;
in this step, the image processing algorithm used for segmenting the contour of the pig belongs to the prior art, which is not described in detail in this embodiment, and the segmented contour is shown in fig. 4 and 5.
130. Judging whether the contour is complete;
specifically, a CNN classification model can be constructed by collecting sample data of a complete pig, so that whether the contour image is complete can be judged by inputting the contour image into the CNN classification model.
140. And if the profile is incomplete, matching a most similar complete profile according to the incomplete profile, and taking the weight of the pig corresponding to the complete profile as the weight of the pig corresponding to the incomplete profile.
Specifically, in the step, a batch of complete pig images and incomplete pig images can be constructed to cover pigs of different body types and sizes, then a matching pair is labeled to be used as a label to train a deep learning model, the deep learning model inputs the pig images and the segmentation contour images of the pigs, and the output is whether the pig images and the segmentation contour images are matched.
Thus, the incomplete contour is input into the deep learning model obtained by training, and a most similar complete contour can be obtained. The matching result is shown in fig. 6.
The weight of the pig corresponding to the complete contour can be obtained by inputting the pixel area of the contour into a conversion formula calibrated in advance.
Optionally, in this embodiment, the method further includes:
150. and if the contour is complete, estimating the weight of the corresponding pig according to the complete contour.
Optionally, in this embodiment, the estimating the weight of the corresponding pig according to the complete contour specifically includes:
and inputting the pixel area of the outline into a conversion formula, and calculating to obtain the corresponding weight of the pig.
The conversion formula can be determined in a calibration mode, specifically, when a camera is fixed at a certain height to shoot a certain fixed area, the pixel area of a target in the area is linearly related to the physical weight of the target, and the conversion formula can be obtained by data acquisition and a least square method.
In addition, since the precision of the above conversion formula may be affected by the breeds of different pigs, the method includes, as an embodiment of the present invention:
210. acquiring an image of a pig in a target area;
220. adopting an image processing algorithm to segment the outline of the pig in the image;
230. judging whether the contour is complete;
240. if the profile is incomplete, matching a most similar complete profile according to the incomplete profile, and taking the weight of the pig corresponding to the complete profile as the weight of the pig corresponding to the incomplete profile;
250. if the contour is complete, identifying the pig breed in the image;
260. and determining a corresponding conversion formula according to the identified pig breeds.
270. And inputting the pixel area of the outline into a conversion formula, and calculating to obtain the corresponding weight of the pig.
In the embodiment, the pig breeds are considered in the process of determining the conversion formula, so that the weight can be accurately estimated under the condition that various pigs are mixed.
Fig. 7 is a block diagram of a pig weight estimation system based on an image according to an embodiment of the present invention, and as shown in fig. 7, the system includes:
the image acquisition module is used for acquiring an image of the pig in the target area;
the image segmentation module is used for segmenting the outline of the pig in the image by adopting an image processing algorithm;
the contour judging module is used for judging whether the contour is complete or not;
the contour matching module is used for matching a most similar complete contour according to the incomplete contour if the contour judging module judges that the contour is incomplete;
and the weight estimation module is used for taking the weight of the pig corresponding to the complete contour as the weight of the pig corresponding to the incomplete contour.
Optionally, in this embodiment, the weight estimation module is further configured to estimate the weight of the corresponding pig according to the complete contour if the contour judgment module judges that the contour is complete.
Optionally, in this embodiment, the weight estimation module estimates the weight of the corresponding pig according to the complete contour, which specifically includes:
and inputting the pixel area of the outline into a conversion formula, and calculating to obtain the corresponding weight of the pig.
Optionally, in this embodiment, the method further includes:
the breed identification module is used for identifying the breeds of the pigs in the image before the weight estimation module inputs the pixel area of the outline into a conversion formula and calculates the weight of the corresponding pigs;
and the formula determination module is used for determining a corresponding conversion formula according to the identified pig breed.
An embodiment of the present invention provides a terminal device, including:
a processor; and
a memory having executable code stored thereon, which when executed by the processor, causes the processor to perform the method described above.
Embodiments of the present invention provide a non-transitory machine-readable storage medium having stored thereon executable code, which, when executed by a processor of an electronic device, causes the processor to perform the above-described method.
The reader should understand that in the description of this specification, reference to the description of the terms "one embodiment," "some embodiments," "an example," "a specific example," or "some examples," etc., means that a particular feature, structure, material, or characteristic described in connection with the embodiment or example is included in at least one embodiment or example of the invention. In this specification, the schematic representations of the terms used above are not necessarily intended to refer to the same embodiment or example. Furthermore, the particular features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples. Furthermore, various embodiments or examples and features of different embodiments or examples described in this specification can be combined and combined by one skilled in the art without contradiction.
It can be clearly understood by those skilled in the art that, for convenience and brevity of description, the specific working processes of the modules and units in the above described system embodiment may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
In the several embodiments provided in the present application, it should be understood that the disclosed apparatus and method may be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative, and for example, a division of a unit is merely a logical division, and an actual implementation may have another division, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed.
Units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment of the present invention.
In addition, functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention essentially or partially contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product stored in a storage medium and including instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
While the invention has been described with reference to specific embodiments, it will be understood by those skilled in the art that various changes in form and details may be made therein without departing from the spirit and scope of the invention as defined by the appended claims. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.