Method for identifying food safety risks in catering service processing based on image data
By acquiring and analyzing the grayscale values and edge change values of food images, the system distinguishes between water film reflection and food abnormalities, solving the problem of high misjudgment rate in existing technologies and achieving more accurate food safety risk identification.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- SHENZHEN GEWU ZHENGYUAN QUALITY STANDARD SYST CO LTD
- Filing Date
- 2026-03-18
- Publication Date
- 2026-06-19
Smart Images

Figure CN122244517A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of food safety risk identification technology, specifically a method for identifying food safety risks in the food service processing process based on image data. Background Technology
[0002] With the rapid development of the catering industry and the increasing attention of consumers to food safety, food safety supervision during the food service processing has become a key link in protecting public health. Traditional manual inspection methods rely on on-site inspections by supervisors, which have drawbacks such as low efficiency and strong subjectivity. Existing risk identification methods based on visible light images still face many challenges in practical applications. Among them, the water film reflection phenomenon on the surface of washed fruits and vegetables presents similar visual characteristics to early food abnormalities and uncleaned food, resulting in a high misjudgment rate for food safety. The water film reflection is essentially a physical optical phenomenon, manifested as a localized area of high brightness and low saturation specular reflection, while food abnormalities are caused by changes in color and texture due to changes in the composition of biological tissues. Both change in color, making them easy to misidentify. In other words, existing technologies easily confuse the water film reflection phenomenon with food abnormalities through images, leading to an increased misjudgment rate in food safety risk identification. Summary of the Invention
[0003] This invention aims to at least partially address one of the technical problems in the prior art. It involves obtaining a first historical grayscale value based on an image of normally washed food; obtaining a first normal threshold and a second normal threshold based on the first historical grayscale value; obtaining an image of the washed food and labeling it as a real-time food image; obtaining real-time food grayscale values based on the real-time food image; obtaining real-time abnormal grayscale values based on the real-time food grayscale value, the first normal threshold, and the second normal threshold; obtaining real-time abnormal contours based on the real-time abnormal grayscale values; constructing real-time edge change values based on the real-time abnormal contours; obtaining historical edge change values based on an image of the washed food containing water film reflection; obtaining a water film reflection threshold based on the historical edge change values; and determining whether a food safety risk exists based on the real-time abnormal judgment value and the water film reflection threshold. This addresses the problem in the prior art where water film reflection is easily confused with food abnormalities through images, leading to an increased misjudgment rate in food safety risk identification.
[0004] To achieve the above objectives, this application provides a method for identifying food safety risks in the food service processing process based on image data, comprising the following steps: The first historical grayscale value is obtained based on the food image after normal washing. The first normal threshold and the second normal threshold are obtained based on the first historical grayscale value; Acquire images of cleaned food and label them as real-time food images; obtain real-time food grayscale values based on real-time food images. Real-time abnormal grayscale values are obtained based on real-time food grayscale values, a first normal threshold, and a second normal threshold. Real-time anomaly contours are obtained based on real-time anomaly grayscale values; Construct real-time edge change values based on real-time anomaly contours; Historical edge change values are obtained from images of washed food containing water film and reflecting light. The water film reflectivity threshold is obtained based on historical edge change values; The presence of food safety risks is determined based on real-time anomaly assessment values and water film reflectivity thresholds.
[0005] Furthermore, obtaining the first historical grayscale value based on the food image after normal cleaning includes the following sub-steps: The images of food after normal cleaning are converted to grayscale to obtain grayscale images, which are then marked as historical food grayscale images. Mark the gray values of the food region pixels in the historical food grayscale image as the first historical grayscale value.
[0006] Furthermore, obtaining the first normal threshold and the second normal threshold based on the first historical grayscale value includes the following sub-steps: Retrieve the first number of first historical grayscale values; A Cartesian coordinate system is established with the first historical grayscale value as the horizontal axis data and the number of the first historical grayscale values as the vertical axis data, and this system is marked as the first historical coordinate system. Obtain all first historical grayscale values and their corresponding quantities as coordinate points on the x and y axes, and mark them as first historical coordinate points; Plot all the first historical coordinate points in the first historical coordinate system.
[0007] Get the maximum value of the y-coordinate among all the first historical coordinate points and mark it as the first data height; Create a rectangle on the horizontal axis of the first historical coordinate system with a height equal to the height of the first data and a width equal to the length of the first data, and be able to move left and right. Mark this rectangle as the first judgment rectangle. The number of real-time historical grayscale values within the first judgment rectangle is marked as the first judgment quantity; Assuming that the first historical grayscale value is uniformly distributed within the range, the first judgment quantity at this time is obtained and marked as the first average quantity; Set a first ratio value, and mark the product of the first average quantity and the first ratio value as the first quantity threshold; The first judgment rectangle is shifted to the right starting from the smallest first historical gray value. When the number of first judgments is greater than or equal to the first number threshold, the first judgment rectangle is stopped from moving. The first historical gray value corresponding to the smallest x-coordinate of the first judgment rectangle at this time is obtained and marked as the first normal threshold. The first judgment rectangle is shifted to the left starting from the largest first historical gray value. When the number of first judgments is greater than or equal to the first number threshold, the first judgment rectangle is stopped from moving. The first historical gray value corresponding to the largest horizontal coordinate of the first judgment rectangle at this time is obtained and marked as the second normal threshold.
[0008] Furthermore, obtaining real-time food grayscale values based on real-time food images includes the following sub-steps: The real-time food image is converted to grayscale to obtain a grayscale image, which is then labeled as the real-time food grayscale image. Establish a Cartesian coordinate system and label it as the real-time comparison coordinate system; place the real-time food grayscale image in the first quadrant of the real-time comparison coordinate system; Mark the gray values of the pixels in the food area of the real-time food grayscale image as the real-time food grayscale value.
[0009] Furthermore, obtaining real-time abnormal grayscale values based on real-time food grayscale values, a first normal threshold, and a second normal threshold includes the following sub-steps: Real-time food grayscale values between the first normal threshold and the second normal threshold are marked as real-time normal grayscale values; Real-time food grayscale values that are not between the first and second normal thresholds are marked as real-time abnormal grayscale values.
[0010] Furthermore, obtaining the real-time anomaly contour based on the real-time anomaly grayscale value includes the following sub-steps: Each independent region composed of real-time abnormal grayscale values is marked as a real-time abnormal region. Mark the contours of real-time anomaly regions as real-time anomaly contours.
[0011] Furthermore, constructing real-time edge change values based on real-time anomaly contours includes the following sub-steps: Obtain a second number of coordinate points on the real-time anomaly contour and mark them as real-time contour coordinate points; Draw a perpendicular line from the real-time contour coordinate point to the real-time abnormal contour, and mark it as the real-time contour perpendicular line; take the real-time contour coordinate point as the starting point, and obtain the gray value of the first pixel point along the real-time contour perpendicular line to the inside and outside of the real-time abnormal contour, and mark it as the first edge gray value and the second edge gray value respectively. The mean of the absolute values of the differences between all first edge grayscale values and second edge grayscale values is obtained and marked as the real-time edge change value.
[0012] Furthermore, constructing real-time anomaly evaluation values based on real-time anomaly contours and real-time food images includes the following sub-steps: The image of the washed food containing water film reflection is regarded as a real-time food image. The real-time edge change value caused by the water film reflection is obtained and marked as the historical edge change value.
[0013] Furthermore, obtaining the water film reflectivity threshold based on historical edge change values includes the following sub-steps: Obtain the third number of real-time historical change values; A Cartesian coordinate system is established with real-time historical change values as the horizontal axis data and the number of real-time historical change values as the vertical axis data, and this system is marked as the second historical coordinate system. Obtain all real-time historical change values and their corresponding quantities as coordinate points on the x and y axes, and mark them as the second historical coordinate points; Plot all the second history coordinate points in the second history coordinate system.
[0014] Get the maximum value of the y-coordinate among all the second historical coordinate points and mark it as the second data height; Create a rectangle on the horizontal axis of the second historical coordinate system with a height equal to the height of the second data and a width equal to the length of the second data, and mark it as the second judgment rectangle. The number of real-time historical change values within the second judgment rectangle is marked as the second judgment quantity; Assuming that the real-time historical change values are uniformly distributed within the range, the second judgment quantity at this time is obtained and marked as the second average quantity; Set a second ratio value, and mark the product of the second average quantity and the second ratio value as the second quantity threshold; The second judgment rectangle is shifted to the right starting from the smallest real-time historical change value. When the second judgment quantity is greater than or equal to the second quantity threshold, the movement of the second judgment rectangle is stopped. The real-time historical change value corresponding to the smallest horizontal coordinate of the second judgment rectangle at this time is obtained and marked as the water film reflection threshold.
[0015] Furthermore, determining whether a food safety risk exists based on real-time anomaly assessment values and water film reflectivity thresholds includes the following sub-steps: If a real-time abnormal contour appears and the real-time abnormal judgment value is less than the water film reflection threshold, the food in the real-time food image is considered to have a safety risk; if no real-time abnormal contour appears or the real-time abnormal judgment value is greater than or equal to the water film reflection threshold, the food in the real-time food image is considered to have no safety risk.
[0016] The beneficial effects of this invention are as follows: This invention obtains a first historical grayscale value based on an image of food after normal washing; obtains a first normal threshold and a second normal threshold based on the first historical grayscale value; obtains an image of the washed food and marks it as a real-time food image; obtains real-time food grayscale values based on the real-time food image; obtains real-time abnormal grayscale values based on the real-time food grayscale value, the first normal threshold, and the second normal threshold; obtains real-time abnormal contours based on the real-time abnormal grayscale values; constructs real-time edge change values based on the real-time abnormal contours; obtains historical edge change values based on an image of the washed food containing water film reflection; obtains a water film reflection threshold based on the historical edge change values; and determines whether a food safety risk has occurred based on the real-time abnormal judgment value and the water film reflection threshold. The advantage is that it distinguishes the water film reflection phenomenon from abnormal food characteristics, reducing the misjudgment rate of food safety risk identification. This invention constructs real-time edge change values based on real-time abnormal contours. Its advantage lies in distinguishing water film reflection phenomena from abnormal food features through real-time edge change values, thereby reducing the misjudgment rate of food safety risk identification. Attached Figure Description
[0017] Figure 1 This is a flowchart of the steps of the method of the present invention; Figure 2 This is a schematic diagram of the first and second normal thresholds of the present invention; Figure 3 This is a schematic diagram of the water film reflectivity threshold of the present invention. Detailed Implementation
[0018] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0019] Example 1, please refer to Figure 1 As shown, this application provides a method for identifying food safety risks in the food service processing process based on image data, including the following steps: Step S1: Obtain the first historical grayscale value based on the food image after normal cleaning; Step S1 includes the following sub-steps: Step S101: The image of the normally cleaned food is converted to grayscale to obtain a grayscale image, which is then marked as a historical food grayscale image. When obtaining the image of the normally cleaned food, the light intensity is kept the same to facilitate risk identification. The food is vegetables. After washing, the vegetables may contain water, which will cause reflection. The water film reflection phenomenon on the surface of the washed fruits and vegetables presents similar visual characteristics to early abnormalities and unclean food, resulting in a high misjudgment rate of food safety.
[0020] Step S102: Mark the gray values of the food area pixels in the historical food grayscale image as the first historical grayscale value.
[0021] Step S2 involves obtaining a first normal threshold and a second normal threshold based on the first historical grayscale value. Step S2 includes the following sub-steps: Step S201: Obtain a first number of first historical grayscale values; in order to obtain the range of the first historical grayscale values, the first number should not be too small, for example, the first number is 9 million; Step S202: Establish a Cartesian coordinate system with the first historical grayscale value as the horizontal axis data and the number of the first historical grayscale values as the vertical axis data, and mark it as the first historical coordinate system; Step S203: Obtain all first historical grayscale values and their corresponding coordinate points (x-axis and y-axis, respectively), and mark them as first historical coordinate points; the first historical coordinate points are used to observe the distribution of the first historical grayscale values. Step S204: Plot all the first historical coordinate points in the first historical coordinate system.
[0022] Step S205: Obtain the maximum value of the ordinate among all first historical coordinate points and mark it as the first data height; Step S206: Create a rectangle on the horizontal axis of the first historical coordinate system with a height equal to the height of the first data and a width equal to the length of the first data, and allow it to move left and right. Mark this rectangle as the first judgment rectangle. The first judgment rectangle is used to better observe the distribution of the first historical grayscale values. For practical applications, please refer to Figure 2 As shown, the first data height is 55, the first data length is 1, and the first judgment rectangle is obtained.
[0023] Step S207: Mark the number of real-time first historical grayscale values within the first judgment rectangle as the first judgment quantity; Step S208: Assuming the first historical grayscale value is uniformly distributed within the range, obtain the first judgment quantity at this time and mark it as the first average quantity; In practical applications, if the distribution is uniform, that is, the number of each gray value is the same between 40 and 80, the first average number is: 900 × (1 / 40) = 22.5; where 900 is the first number, 1 is the first data length, and 40 is the range length of the first historical gray values.
[0024] Step S209: Set a first ratio value and mark the product of the first average quantity and the first ratio value as the first quantity threshold. The first quantity threshold is set to filter out the first historical gray value range with too few distributions. Therefore, the first ratio value is set to be small. For example, if the first ratio value is 0.2, then the first quantity threshold is: 22.5 × 0.2 = 4.5.
[0025] Step S210: Move the first judgment rectangle to the right starting from the smallest first historical gray value. When the number of first judgments is greater than or equal to the first number threshold, stop moving the first judgment rectangle. Obtain the first historical gray value corresponding to the smallest horizontal coordinate of the first judgment rectangle at this time and mark it as the first normal threshold. Filter out abnormally small first historical gray values to obtain a more accurate minimum value of the first historical gray value. Step S211: Move the first judgment rectangle to the left starting from the largest first historical gray value. When the number of first judgments is greater than or equal to the first number threshold, stop moving the first judgment rectangle. Obtain the first historical gray value corresponding to the largest horizontal coordinate of the first judgment rectangle at this time and mark it as the second normal threshold. Filter out abnormally large first historical gray values to obtain a more accurate maximum value of the first historical gray value. For practical applications, please refer to Figure 2 As shown, the first judgment rectangle is shifted to the right starting from the smallest first historical grayscale value. The shifting of the first judgment rectangle stops when the number of first judgments is greater than or equal to a first quantity threshold. Please refer to [link to relevant documentation]. Figure 2 As shown, the position of the first judgment rectangle is obtained at this time, and the first normal threshold is 41; the first judgment rectangle is shifted to the left starting from the largest first historical gray value, and the movement of the first judgment rectangle stops when the number of first judgments is greater than or equal to the first number threshold; please refer to Figure 2 As shown, the position of the first judgment rectangle is obtained at this time, and the second normal threshold is 79.
[0026] Step S3: Obtain an image of the cleaned food and label it as a real-time food image; obtain the real-time food grayscale value based on the real-time food image; Step S3 includes the following sub-steps: Step S301: After grayscale processing of the real-time food image, a grayscale image is obtained and marked as a real-time food grayscale image. Step S302: Establish a Cartesian coordinate system and mark it as the real-time comparison coordinate system; place the real-time food grayscale image in the first quadrant of the real-time comparison coordinate system; Step S303: Mark the gray values of the food region pixels in the real-time food grayscale image as the real-time food grayscale values.
[0027] Step S4: Obtain real-time abnormal grayscale values based on real-time food grayscale values, a first normal threshold, and a second normal threshold; Step S4 includes the following sub-steps: Step S401: Mark the real-time food grayscale value between the first normal threshold and the second normal threshold as the real-time normal grayscale value; Step S402: Mark the real-time food grayscale value that is not between the first normal threshold and the second normal threshold as the real-time abnormal grayscale value; if it exceeds the range of normal food grayscale value, it may be that the food is not cleaned properly or has deteriorated, or it is caused by water film reflection and requires further investigation.
[0028] Step S5: Obtain the real-time anomaly contour based on the real-time anomaly grayscale value; Step S5 includes the following sub-steps: Step S501: Mark the independent region composed of each real-time abnormal grayscale value as a real-time abnormal region; Step S502: Mark the contour of the real-time anomaly region as the real-time anomaly contour.
[0029] Step S6: Construct real-time edge change values based on real-time anomaly contours; Step S6 includes the following sub-steps: Step S601: Obtain a second number of coordinate points on the real-time abnormal contour and mark them as real-time contour coordinate points; in order to observe the changes in the real-time abnormal contour, the second number of real-time contour coordinate points should not be too small, for example, the second number is 100. Step S602: Draw a perpendicular line to the real-time abnormal contour through the real-time contour coordinate points and mark it as the real-time contour perpendicular line; take the real-time contour coordinate points as the starting point, and obtain the gray values of the first pixel points along the real-time contour perpendicular line to the inside and outside of the real-time abnormal contour respectively, and mark them as the first edge gray value and the second edge gray value respectively. Step S603: Obtain the mean of the absolute values of the differences between all first edge gray values and second edge gray values, and mark it as the real-time edge change value. Since the edge is clear if the film is reflective, the real-time edge change value will be large. If it is not cleaned or deteriorated, the edge will be blurry, and the real-time edge change value will be small. Therefore, the real-time edge change value can be used to determine whether the film is reflective.
[0030] Step S7: Obtain historical edge change values based on the image of the washed food containing water film reflection; Step S7 includes the following sub-steps: Step S701: Treat the image of the washed food containing water film reflection as a real-time food image, obtain the real-time edge change value caused by water film reflection, and mark it as historical edge change value; obtain the range of historical edge change value under water film reflection.
[0031] Step S8: Obtain the water film reflectivity threshold based on historical edge change values; Step S8 includes the following sub-steps: Step S801: Obtain a third number of real-time historical change values; in order to obtain the range of real-time historical change values, the third number should not be too small, for example, the third number is 800; Step S802: Establish a Cartesian coordinate system with real-time historical change values as the horizontal axis data and the number of real-time historical change values as the vertical axis data, and mark it as the second historical coordinate system; Step S803: Obtain all real-time historical change values and their corresponding quantities as coordinate points on the x-axis and y-axis, and mark them as the second historical coordinate points; Step S804: Plot all the second historical coordinate points in the second historical coordinate system.
[0032] Step S805: Obtain the maximum value of the ordinate among all second historical coordinate points and mark it as the second data height; Step S806: Create a rectangle on the horizontal axis of the second historical coordinate system with a height equal to the height of the second data and a width equal to the length of the second data, and allow it to move left and right. Mark this rectangle as the second judgment rectangle. The second judgment rectangle is used to observe the distribution of real-time historical change values. For practical applications, please refer to Figure 3 As shown, the second data height is 52 and the second data length is 1. Draw the second judgment rectangle. Step S807: Mark the number of real-time historical change values within the second judgment rectangle as the second judgment quantity; Step S808: Assuming that the real-time historical change values are uniformly distributed within the range, obtain the second judgment quantity at this time and mark it as the second average quantity; In practical applications, if the distribution is uniform, that is, the number of each gray value is the same between 170 and 210, the second average number is: 800 × (1 / 40) = 20; where 800 is the second number, 1 is the second data length, and 40 is the range length of the real-time historical change value.
[0033] Step S809: Set a second ratio value and mark the product of the second average quantity and the second ratio value as the second quantity threshold. The second quantity threshold is set to a small value to filter out real-time historical change value intervals with too few distributions, for example, the second ratio value is 0.2. Then, the second quantity threshold is: 20 × 0.2 = 4.
[0034] Step S810: Move the second judgment rectangle to the right starting from the smallest real-time historical change value. When the second judgment quantity is greater than or equal to the second quantity threshold, stop moving the second judgment rectangle. Obtain the real-time historical change value corresponding to the smallest horizontal coordinate of the second judgment rectangle at this time, mark it as the water film reflection threshold, filter out abnormally small real-time historical change values, and then obtain a more accurate minimum value of the real-time historical change value. For practical applications, please refer to Figure 3 As shown, the water film reflectance threshold obtained is 181.
[0035] Step S9: Determine whether a food safety risk exists based on the real-time anomaly assessment value and the water film reflectivity threshold; Step S9 includes the following sub-steps: Step S901: If a real-time abnormal contour appears and the real-time abnormal judgment value is less than the water film reflection threshold, the food in the real-time food image is considered to have a safety risk; if no real-time abnormal contour appears or the real-time abnormal judgment value is greater than or equal to the water film reflection threshold, the food in the real-time food image is considered to have no safety risk, because when there is water film reflection, if the real-time abnormal judgment value is large, the food is normal and it is water film reflection; if the real-time abnormal judgment value is small, the food may be clean or spoiled, and there is a food safety risk. In practical applications, for example, if the real-time anomaly assessment value is 20, then if the real-time anomaly assessment value of 20 is less than the water film reflection threshold of 181, then the food in the real-time food image is considered to have a safety risk.
[0036] Example 2: This application also provides an electronic device, which may include: a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus. The memory stores computer-readable instructions, and the processor can call the instructions in the memory. When the computer-readable instructions are executed by the processor, the steps in the food safety risk identification method for catering service processing based on image data are performed to achieve the following functions: obtaining a first historical grayscale value based on an image of normally cleaned food; obtaining a first normal threshold and a second normal threshold based on the first historical grayscale value; obtaining an image of cleaned food and marking it as a real-time food image; obtaining a real-time food grayscale value based on the real-time food image; obtaining a real-time abnormal grayscale value based on the real-time food grayscale value, the first normal threshold, and the second normal threshold; obtaining a real-time abnormal contour based on the real-time abnormal grayscale value; constructing a real-time edge change value based on the real-time abnormal contour; obtaining historical edge change values based on an image of cleaned food containing water film reflection; obtaining a water film reflection threshold based on the historical edge change values; and determining whether a food safety risk has occurred based on the real-time abnormal judgment value and the water film reflection threshold.
[0037] Furthermore, when the logical instructions in the aforementioned memory can be implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0038] Example 3: This application also provides a computer program product, which includes a computer program stored on a computer-readable storage medium. The computer program includes program instructions. When the program instructions are executed by a computer, the computer can execute the food safety risk identification method for food processing based on image data provided by the above methods. The method includes: obtaining a first historical grayscale value based on a normally cleaned food image; obtaining a first normal threshold and a second normal threshold based on the first historical grayscale value; obtaining a cleaned food image and marking it as a real-time food image; obtaining a real-time food grayscale value based on the real-time food image; obtaining a real-time abnormal grayscale value based on the real-time food grayscale value, the first normal threshold, and the second normal threshold; obtaining a real-time abnormal contour based on the real-time abnormal grayscale value; constructing a real-time edge change value based on the real-time abnormal contour; obtaining historical edge change values based on an image of cleaned food containing water film reflection; obtaining a water film reflection threshold based on the historical edge change values; and determining whether a food safety risk has occurred based on the real-time abnormal judgment value and the water film reflection threshold.
[0039] Example 4: This application also provides a computer-readable storage medium storing a computer program. When executed by a processor, the computer program performs the steps of the above-described method for identifying food safety risks in the food service processing of image data, to achieve the following functions: obtaining a first historical grayscale value based on an image of normally cleaned food; obtaining a first normal threshold and a second normal threshold based on the first historical grayscale value; obtaining an image of cleaned food and marking it as a real-time food image; obtaining real-time food grayscale values based on the real-time food image; obtaining real-time abnormal grayscale values based on the real-time food grayscale value, the first normal threshold, and the second normal threshold; obtaining real-time abnormal contours based on the real-time abnormal grayscale values; constructing real-time edge change values based on the real-time abnormal contours; obtaining historical edge change values based on an image of cleaned food containing water film reflection; obtaining a water film reflection threshold based on the historical edge change values; and determining whether a food safety risk has occurred based on the real-time abnormal judgment value and the water film reflection threshold.
[0040] Based on the above description of the embodiments, the embodiments of the present invention can be provided as methods, systems, or computer program products. Based on this understanding, the above technical solutions, in essence or in terms of their contribution to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or certain parts of the embodiments.
[0041] In the embodiments provided in this application, it should be understood that the disclosed system or method can be implemented in other ways. The embodiments described above are merely illustrative. For example, the division of modules or units is only a logical functional division, and there may be other division methods in actual implementation. Furthermore, multiple modules or units may be combined or integrated into another system, or some features may be ignored or not executed. Additionally, the coupling or direct coupling or communication connection shown or discussed may be through some communication interfaces. The indirect coupling or communication connection between systems, modules, and units may be electrical, mechanical, or other forms.
[0042] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application.
Claims
1. A method for identifying food safety risks in the food service processing process based on image data, characterized in that, Includes the following steps: The first historical grayscale value is obtained based on the food image after normal washing. The first normal threshold and the second normal threshold are obtained based on the first historical grayscale value; Acquire images of cleaned food and label them as real-time food images; obtain real-time food grayscale values based on real-time food images. Real-time abnormal grayscale values are obtained based on real-time food grayscale values, a first normal threshold, and a second normal threshold. Real-time anomaly contours are obtained based on real-time anomaly grayscale values; Construct real-time edge change values based on real-time anomaly contours; Historical edge change values are obtained from images of washed food containing water film and reflecting light. The water film reflectivity threshold is obtained based on historical edge change values; The presence of food safety risks is determined based on real-time anomaly assessment values and water film reflectivity thresholds.
2. The food safety risk identification method for catering service processing based on image data according to claim 1, characterized in that, Obtaining the first historical grayscale value based on a normally cleaned food image includes the following sub-steps: The images of food after normal cleaning are converted to grayscale to obtain grayscale images, which are then marked as historical food grayscale images. Mark the gray values of the food region pixels in the historical food grayscale image as the first historical grayscale value.
3. The food safety risk identification method for catering service processing based on image data according to claim 2, characterized in that, Obtaining the first normal threshold and the second normal threshold based on the first historical grayscale value includes the following sub-steps: Retrieve the first number of first historical grayscale values; A Cartesian coordinate system is established with the first historical grayscale value as the horizontal axis data and the number of the first historical grayscale values as the vertical axis data, and this system is marked as the first historical coordinate system. Obtain all first historical grayscale values and their corresponding quantities as coordinate points on the x and y axes, and mark them as first historical coordinate points; Plot all the first historical coordinate points in the first historical coordinate system; Get the maximum value of the y-coordinate among all the first historical coordinate points and mark it as the first data height; Create a rectangle on the horizontal axis of the first historical coordinate system with a height equal to the height of the first data and a width equal to the length of the first data, and be able to move left and right. Mark this rectangle as the first judgment rectangle. The number of real-time historical grayscale values within the first judgment rectangle is marked as the first judgment quantity; Assuming that the first historical grayscale value is uniformly distributed within the range, the first judgment quantity at this time is obtained and marked as the first average quantity; Set a first ratio value, and mark the product of the first average quantity and the first ratio value as the first quantity threshold; The first judgment rectangle is shifted to the right starting from the smallest first historical gray value. When the number of first judgments is greater than or equal to the first number threshold, the first judgment rectangle is stopped from moving. The first historical gray value corresponding to the smallest x-coordinate of the first judgment rectangle at this time is obtained and marked as the first normal threshold. The first judgment rectangle is shifted to the left starting from the largest first historical gray value. When the number of first judgments is greater than or equal to the first number threshold, the first judgment rectangle is stopped from moving. The first historical gray value corresponding to the largest horizontal coordinate of the first judgment rectangle at this time is obtained and marked as the second normal threshold.
4. The food safety risk identification method for catering service processing based on image data according to claim 3, characterized in that, Obtaining real-time food grayscale values from real-time food images includes the following sub-steps: The real-time food image is converted to grayscale to obtain a grayscale image, which is then labeled as the real-time food grayscale image. Establish a Cartesian coordinate system and label it as the real-time comparison coordinate system; place the real-time food grayscale image in the first quadrant of the real-time comparison coordinate system; Mark the gray values of the pixels in the food area of the real-time food grayscale image as the real-time food grayscale value.
5. The food safety risk identification method for catering service processing based on image data according to claim 4, characterized in that, Obtaining real-time abnormal grayscale values based on real-time food grayscale values, a first normal threshold, and a second normal threshold includes the following sub-steps: Real-time food grayscale values between the first normal threshold and the second normal threshold are marked as real-time normal grayscale values; Real-time food grayscale values that are not between the first and second normal thresholds are marked as real-time abnormal grayscale values.
6. The food safety risk identification method for catering service processing based on image data according to claim 5, characterized in that, Obtaining real-time anomaly contours based on real-time anomaly grayscale values includes the following sub-steps: Each independent region composed of real-time abnormal grayscale values is marked as a real-time abnormal region. Mark the contours of real-time anomaly regions as real-time anomaly contours.
7. The food safety risk identification method for catering service processing based on image data according to claim 6, characterized in that, Constructing real-time edge change values based on real-time anomaly contours includes the following sub-steps: Obtain a second number of coordinate points on the real-time anomaly contour and mark them as real-time contour coordinate points; Draw a perpendicular line from the real-time contour coordinate point to the real-time abnormal contour, and mark it as the real-time contour perpendicular line; take the real-time contour coordinate point as the starting point, and obtain the gray value of the first pixel point along the real-time contour perpendicular line to the inside and outside of the real-time abnormal contour, and mark it as the first edge gray value and the second edge gray value respectively. The mean of the absolute values of the differences between all first edge grayscale values and second edge grayscale values is obtained and marked as the real-time edge change value.
8. The food safety risk identification method for catering service processing based on image data according to claim 7, characterized in that, Constructing real-time anomaly evaluation values based on real-time anomaly contours and real-time food images includes the following sub-steps: The image of the washed food containing water film reflection is regarded as a real-time food image. The real-time edge change value caused by the water film reflection is obtained and marked as the historical edge change value.
9. The food safety risk identification method for catering service processing based on image data according to claim 8, characterized in that, Obtaining the water film reflectivity threshold based on historical edge change values includes the following sub-steps: Obtain the third number of real-time historical change values; A Cartesian coordinate system is established with real-time historical change values as the horizontal axis data and the number of real-time historical change values as the vertical axis data, and this system is marked as the second historical coordinate system. Obtain all real-time historical change values and their corresponding quantities as coordinate points on the x and y axes, and mark them as the second historical coordinate points; Plot all the second history coordinate points in the second history coordinate system; Get the maximum value of the y-coordinate among all the second historical coordinate points and mark it as the second data height; Create a rectangle on the horizontal axis of the second historical coordinate system with a height equal to the height of the second data and a width equal to the length of the second data, and mark it as the second judgment rectangle. The number of real-time historical change values within the second judgment rectangle is marked as the second judgment quantity; Assuming that the real-time historical change values are uniformly distributed within the range, the second judgment quantity at this time is obtained and marked as the second average quantity; Set a second ratio value, and mark the product of the second average quantity and the second ratio value as the second quantity threshold; The second judgment rectangle is shifted to the right starting from the smallest real-time historical change value. When the second judgment quantity is greater than or equal to the second quantity threshold, the movement of the second judgment rectangle is stopped. The real-time historical change value corresponding to the smallest horizontal coordinate of the second judgment rectangle at this time is obtained and marked as the water film reflection threshold.
10. The food safety risk identification method for catering service processing based on image data according to claim 9, characterized in that, Determining whether a food safety risk exists based on real-time anomaly assessment values and water film reflectivity thresholds includes the following sub-steps: If a real-time abnormal contour appears and the real-time abnormal judgment value is less than the water film reflection threshold, the food in the real-time food image is considered to have a safety risk; if no real-time abnormal contour appears or the real-time abnormal judgment value is greater than or equal to the water film reflection threshold, the food in the real-time food image is considered to have no safety risk.