Dietary nutritional ingredient calculation method based on image recognition, electronic equipment and medium
The dish image recognition is performed through the convolutional neural network model (CNN), and the feature similarity is calculated in combination with the feature vectors of the recipe library, which solves the problem of low image recognition accuracy in the prior art, and realizes efficient and accurate calculation of dietary nutritional ingredients.
Patent Information
- Application Number
- CN202411674609.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-21
- Publication Date
- 2025-03-11
Smart Images

Figure CN119600594A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of food type recognition, and in particular relates to a dietary nutrient component calculation method based on image recognition, an electronic device and a medium. Background Art
[0002] As the concept of healthy eating becomes more popular, people are paying more attention to the nutritional content of their diet. By understanding the nutritional content of their daily diet, people can better manage their health.
[0003] In related technologies, image recognition technology has been introduced to identify dishes by taking photos or uploading images, and automatically extract relevant nutritional information. For example, applications such as Mint Health and Huawei Sports Health provide this function. The existing image recognition technology is still not accurate enough when processing complex dish images, which may lead to inaccurate recognition results, thus affecting the subsequent calculation of nutritional components, especially when the dishes are highly mixed, and the ability to recognize the details of some dishes and ingredients is insufficient. Summary of the invention
[0004] In view of this, the present invention provides a dietary nutrient composition calculation method, electronic device and medium based on image recognition to solve the problem that the ordinary image recognition precision and accuracy in the prior art are not high enough.
[0005] In a first aspect, the present invention provides a method for calculating dietary nutrients based on image recognition, comprising: acquiring a pre-recognized image; calculating the feature similarity of the pre-recognized image based on a recipe library and the pre-recognized image; identifying a dish name based on the feature similarity; identifying corresponding ingredient information based on the dish name, the ingredient information including the ingredient name and standard portion; calculating total nutrients based on the ingredient information; and outputting a nutrient result based on the total nutrients, the nutrient result including the content and proportion of each nutrient.
[0006] In some embodiments, the feature similarity of the pre-recognized image is calculated based on the recipe library and the pre-recognized image, specifically including: obtaining a feature vector of the pre-recognized image and all feature vectors of the recipe library; comparing the feature vector of the pre-recognized image with all feature vectors of the recipe library to calculate the similarity, and the calculation formula used is the Euclidean distance calculation formula: Where d is the distance, x is i is the feature vector of the pre-recognition image, y i is the feature vector of the recipe library.
[0007] In some embodiments, identifying the dish name based on the feature similarity specifically includes: sorting the feature similarity calculation results to obtain a sorting result; obtaining a number of similar dish names based on the sorting result; and identifying the dish name based on the several similar dish names.
[0008] In some implementations, if the dish name cannot be confirmed based on the several similar dish names, the recipe library is updated.
[0009] In some embodiments, the total nutritional components are calculated based on the ingredient information, specifically including: obtaining nutritional component information; calculating the nutritional components of a single ingredient based on the nutritional component information; and adding the nutritional components of all ingredients to obtain the total nutritional components corresponding to the dish name.
[0010] In some embodiments, calculating the total nutritional components based on the food information specifically includes: adjusting the actual portion of the food according to the food information; and calculating the total nutritional components based on the actual portion.
[0011] In some embodiments, any of the dietary nutrient calculation methods based on image recognition further includes building a recipe library, specifically including: obtaining original images of multiple foods; preprocessing the original images to obtain tensor images; convolving the tensor images to extract edge and texture features; further extracting local features based on the edge and texture features, and reducing the feature map to 1×1. Global features and local features at different levels are spliced to form a final multi-scale feature representation; the feature vector based on the multi-scale feature representation and the corresponding dish name are stored in a feature vector database to build the recipe library.
[0012] In some embodiments, the original image is preprocessed to obtain a tensor image, specifically including: adjusting the size of the original image to 256×256 pixels to obtain an adjusted image; cropping the adjusted image to obtain a 224×224 image; converting the 224×224 image into a tensor to obtain the tensor image.
[0013] In a second aspect, the present invention also provides an electronic device, comprising: at least one processor; a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can: obtain a pre-recognized image; calculate the feature similarity of the pre-recognized image based on a recipe library and the pre-recognized image; identify the name of a dish based on the feature similarity; identify the corresponding ingredient information based on the dish name, the ingredient information including the ingredient name and standard portion; calculate the total nutritional components based on the ingredient information; and output the nutritional components results based on the total nutritional components.
[0014] In a third aspect, the present invention provides a medium storing a computer program, wherein the computer program, when executed by a processor, implements any one of the methods for calculating dietary nutrients based on image recognition.
[0015] The beneficial effects of the present invention are:
[0016] The present invention realizes automatic recognition of dish images through a convolutional neural network model (CNN), avoiding tedious manual input steps. By identifying the features of the pre-recognized image, calculating according to the feature similarity to identify the dish name, then identifying the corresponding ingredient information according to the dish name, and calculating the dietary nutrients of the dish, efficient and accurate dietary nutrient calculation is achieved, providing a user-friendly solution, significantly improving user experience and calculation accuracy. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0018] Figure 1 A flowchart of a method for calculating dietary nutrients based on image recognition according to an embodiment of the present invention;
[0019] Figure 2 A flowchart of a method for calculating dietary nutrients based on image recognition according to another embodiment of the present invention;
[0020] Figure 3 The figure is a block diagram of an electronic device according to an embodiment of the present invention.
[0021] Description of reference numerals:
[0022] 110. Processor;
[0023] 120. Memory. DETAILED DESCRIPTION
[0024] In the relevant technologies, most of the nutrient calculation methods on the market still have many deficiencies and cannot fully meet the needs of users. At present, there are some applications on the market that provide a certain degree of automated nutrient calculation function. These applications are mainly implemented in the following ways:
[0025] Manual input of ingredients and dish information: Users need to manually input the name, quantity, and cooking method of each ingredient, and the system then looks up the nutritional data of the ingredient and calculates the total nutritional content based on this information. This method is inefficient and prone to errors.
[0026] Scanning barcodes: Some apps can quickly get nutritional information about food by scanning the barcode on the food packaging. This method works well for packaged foods, but is less effective for homemade recipes and complex dishes.
[0027] Image recognition technology: A few advanced applications have begun to introduce image recognition technology, which can identify dishes by taking photos or uploading images and automatically extract relevant nutritional information. For example, applications such as Mint Health and Huawei Sports Health provide this function.
[0028] Although the existing technology has solved the problem of nutrient composition calculation to a certain extent, it still has the following shortcomings:
[0029] Manual input is cumbersome and error-prone: Users need to enter the name and quantity of each ingredient one by one, which is cumbersome and prone to input errors, affecting the accuracy of the calculation results. Even the method of scanning barcodes is limited to packaged foods and cannot cover homemade dishes and complex dishes.
[0030] Insufficient image recognition accuracy: Existing image recognition technology still does not have high enough recognition accuracy when processing complex food images, which may lead to inaccurate recognition results, thus affecting the subsequent calculation of nutritional components. The ability to recognize details of some dishes and ingredients is insufficient, especially when the dishes are highly mixed.
[0031] Incomplete information on ingredients and nutrition: Existing databases may not contain the nutritional information of all dishes and ingredients, and users need to search and supplement them by themselves, which increases the difficulty and complexity of use. This leads to incomplete calculation of nutrients and affects users' ability to obtain accurate dietary nutrition information.
[0032] Lack of flexibility and user customization: Users cannot adjust the portion size and ingredient content of dishes according to actual conditions, which cannot meet personalized needs. Existing systems usually provide fixed ingredients and portion options and lack flexibility. This limits the ability of users to adjust according to their personal eating habits and nutritional needs, resulting in a poor user experience.
[0033] There is also a technology that inputs the image taken by the user into a standard food recognition model for recognition, obtains the food category name, and analyzes the nutritional information of the food corresponding to the food category name and the user label to obtain the analysis result. The user cannot adjust the food content according to the actual situation, which affects the accuracy of the nutritional analysis results.
[0034] The present invention uses automated and intelligent technologies to identify dishes and calculate nutritional components, which can greatly improve user experience and calculation accuracy.
[0035] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0036] Combine the following Figures 1 to 3 , describing an embodiment of the present invention.
[0037] like Figure 1 and Figure 2 As shown, according to an embodiment of the present invention, on the one hand, a method for calculating dietary nutrients based on image recognition is provided, comprising the following steps:
[0038] Step S101: Acquire a pre-recognition image.
[0039] Step S103: Calculate the feature similarity of the pre-recognized image based on the recipe library and the pre-recognized image.
[0040] Step S105: Identify the dish name based on feature similarity.
[0041] Step S107: Identify the corresponding ingredient information according to the dish name, where the ingredient information includes the ingredient name and standard portion.
[0042] Step S109: Calculate the total nutritional content based on the food information.
[0043] Step S1011: Outputting the nutritional component results according to the total nutritional components, the nutritional component results including the content and proportion of each nutritional component.
[0044] In this embodiment, the automatic recognition of dish images is realized through the convolutional neural network model (CNN), avoiding the cumbersome manual input steps. The user operation process is simplified through automated image recognition and information extraction technology. Users only need to take pictures or upload images to quickly obtain the nutritional information of dishes, which is easy and quick to operate. The automated recognition and information extraction functions effectively reduce errors in the manual input process and ensure the accuracy and reliability of the calculation of nutritional components. Users no longer need to enter ingredients and servings one by one, reducing the possibility of errors. The system can accurately identify dishes and extract relevant information, improving recognition accuracy and efficiency.
[0045] The recipe library stores the names of dishes and the corresponding ingredient information. The features of the pre-recognized image are identified, and the feature similarity is calculated to identify the dish name, and then the corresponding ingredient information is identified based on the dish name, and the dietary nutrients of the dish are calculated, and the results are displayed to the user, and a detailed nutritional report can be generated. Users can view specific nutritional data, including the content and proportion of each ingredient, to achieve efficient and accurate dietary nutritional calculations, providing users with a user-friendly solution that significantly improves user experience and calculation accuracy.
[0046] Further, based on step S103, the feature similarity of the pre-recognized image is calculated according to the recipe library and the pre-recognized image, which specifically includes the following steps:
[0047] Step S1031: Obtain the feature vector of the pre-recognized image and all feature vectors of the recipe library.
[0048] Step S1033: Compare the feature vector of the pre-recognized image with all feature vectors in the recipe library to calculate the similarity. The calculation formula used is the Euclidean distance calculation formula:
[0049]
[0050] Where d is the distance, x is i is the feature vector of the pre-recognition image, y i is the feature vector of the recipe library.
[0051] When a user uploads a dish image, also known as a pre-recognition image, the system will identify it through the following steps:
[0052] The dish image data is preprocessed and then feature extracted. The Euclidean distance is used as the similarity measurement method to compare the feature vector of the pre-recognized image with all the feature vectors in the feature vector database in the recipe library to calculate the similarity, thereby improving the accuracy of the calculation.
[0053] The present invention uses advanced deep learning technology to extract and classify features through convolutional neural networks, significantly improving the precision and accuracy of dish recognition. Compared with the existing technology, the present invention performs better in processing complex dish images and can accurately identify a variety of dishes and their ingredients.
[0054] Furthermore, step S105, identifying the dish name according to the feature similarity, specifically includes the following steps:
[0055] Step S1051, sorting the feature similarity calculation results to obtain a sorting result.
[0056] Step S1053, obtaining several similar dish names according to the sorting results.
[0057] Step S1055, identifying the dish name based on several similar dish names.
[0058] Understandably, the results of feature similarity calculation are sorted, the 10 most similar foods are found, and the matching dish names are output and returned to the user. The user can select the correct food recognition result on the system page to identify the dish name, and the identified dish name is more accurate.
[0059] Furthermore, if the dish name cannot be confirmed based on several similar dish names, the recipe library is updated.
[0060] If all 10 results are incorrect, the user can upload new dish images and corresponding ingredient information, and the system will automatically update the recipe library. The system supports users to upload new dish images and related information, and automatically updates the recipe library to ensure timely update and expansion of database content, so that the system can continue to provide the latest and most comprehensive dietary nutrition information.
[0061] The present invention combines a dynamically updated recipe library and nutritional ingredient table to automatically obtain and identify the ingredients and standard servings of dishes, and extracts nutritional ingredient information of each ingredient from the nutritional ingredient table, providing detailed and accurate dietary nutritional ingredient data to ensure that users can obtain comprehensive nutritional information.
[0062] Further, based on step S109, the total nutritional components are calculated according to the food information, which specifically includes the following steps:
[0063] Step S1091: Obtain nutritional information.
[0064] Step S1093: Calculate the nutritional components of a single food ingredient based on the nutritional component information.
[0065] Step S1095: Add up the nutritional components of all ingredients to obtain the total nutritional components corresponding to the dish name.
[0066] Taking the dish "Fish-flavored Shredded Pork" as an example, the specific steps are as follows:
[0067] Get nutritional information: The system gets the nutritional data of each ingredient from the nutritional table. The nutritional table data comes from the public Chinese food composition database, covering more than 1,500 ingredients, including the nutritional content of each 100 grams of ingredients, such as calories, protein, fat, carbohydrates, vitamins and minerals. Taking "Fish-flavored Shredded Pork" as an example, suppose the user deletes the ingredients green pepper, red pepper and onion, the nutritional composition of the remaining main ingredients (per 100g) is as follows:
[0068]
[0069]
[0070] Calculate the nutritional content of a single ingredient: Calculate the actual nutritional content of each ingredient based on the amount of ingredients confirmed by the user. The formula is as follows:
[0071] Nutritional content of food i
[0072] =Nutritional content of ingredient i per 100g x (amount of ingredient i confirmed by the user / 100g)
[0073] Taking the ingredients in Fish-flavored Shredded Pork with a weight greater than 0g as an example, calculate the nutritional content of 200g of pork (tenderloin):
[0074] Calories = 155 × (200 / 100) = 310 kcal
[0075] Protein = 20.2 x (200 / 100) = 40.4 g
[0076] Fat = 7.9 x (200 / 100) = 15.8 g
[0077] Carbohydrates = 0.7 x (200 / 100) = 1.4 g
[0078] Other nutrients are calculated in the same way.
[0079] Calculate the nutritional content of 50 grams of carrots:
[0080] Calories = 43 x (50 / 100) = 21.5 kcal
[0081] Protein = 1.4 x (50 / 100) = 0.7 g
[0082] Fat = 0.2 x (50 / 100) = 0.1 g
[0083] Carbohydrates = 10.2 x (50 / 100) = 5.1 grams
[0084] Other nutrients are calculated in the same way.
[0085] Calculate the nutritional content of 10 grams of black fungus:
[0086] Calories = 205 × (10 / 100) = 20.5 kcal
[0087] Protein = 12.1 x (10 / 100) = 1.21 g
[0088] Fat = 1.5 x (10 / 100) = 0.15 g
[0089] Carbohydrates = 65.6 x (10 / 100) = 6.56 grams
[0090] Other nutrients are calculated in the same way.
[0091] Calculate total nutrition facts: Add together the nutrition facts of all ingredients to get the total nutrition facts of the whole dish.
[0092] Total calories = 310 + 21.5 + 20.5 = 352 kcal
[0093] Total protein = 40.4 + 0.7 + 1.21 = 42.31 grams
[0094] Total fat = 15.8 + 0.1 + 0.15 = 16.05 grams
[0095] Total carbohydrates = 1.4 + 5.1 + 6.56 = 13.06 grams
[0096] Other nutrients are added in the same way.
[0097] Generate nutritional composition report: The system generates a detailed nutritional composition report and displays it on the front-end page. Users can view detailed nutritional composition information, including the content and proportion of each nutrient.
[0098] Based on step S109, the total nutritional components are calculated according to the food information, which specifically includes the following steps:
[0099] Step S1097: Adjust the actual amount of the ingredients according to the ingredient information.
[0100] Step S1099: Calculate the total nutritional content based on the actual serving size.
[0101] In this embodiment, after determining the type of food and identifying the name of the dish, the system searches for a dish with the same name as the identification result from the recipe library, extracts the ingredient list and standard portion information of the dish from the matched recipe, and displays it on the system front page. The user can view and adjust the ingredients and portion of the food. Taking the dish "Fish-flavored Shredded Pork" as an example, the specific steps are as follows:
[0102] Ingredient information extraction: The system searches the recipe library for a dish record with the same name as "Fish-flavored Shredded Pork". Each record in the recipe library contains the dish name, ingredients, and the standard portion of each ingredient. The ingredients of "Fish-flavored Shredded Pork" include pork (tenderloin), carrots, green peppers, red peppers, onions, and fungus. The standard portion information of each ingredient is 200 grams of pork (tenderloin), 50 grams of carrots, 50 grams of green peppers, 50 grams of red peppers, 20 grams of onions, and 10 grams of fungus.
[0103] Adjust ingredient information: The system displays the ingredient list and standard portion information on the front-end page, and users can view detailed ingredient information. Users can adjust the portion of each ingredient according to actual needs, such as adjusting the pork portion to 150 grams, the carrot portion to 80 grams, etc. Users can also add new ingredients or delete unnecessary ingredients, and the system will update the ingredient information list on the page.
[0104] Confirm ingredients and servings: The user confirms the adjusted ingredient information and servings, and the system records and saves the confirmation information, providing a reliable data basis for subsequent dietary nutritional calculations.
[0105] The present invention allows users to manually adjust the recommended food portions and the content of each food according to actual needs, meeting personalized dietary needs. Users can easily modify the ingredients of dishes, and the system will recalculate the nutritional components based on the adjusted data, and can provide personalized nutritional information.
[0106] Furthermore, the dietary nutrient composition calculation method based on image recognition also includes building a recipe library, which specifically includes the following steps:
[0107] Step S1013: Acquire original images of multiple foods.
[0108] Step S1015: pre-process the original image to obtain a tensor image.
[0109] Step S1016: Convolve the tensor image to extract edge and texture features.
[0110] Step S1017: further extract local features based on edge and texture features, and reduce the feature map to 1×1.
[0111] Step S1018: concatenate global features and local features at different levels to form a final multi-scale feature representation.
[0112] Step S1019: Store the feature vector based on the multi-scale feature representation and the corresponding dish name in the feature vector database to construct a recipe library.
[0113] After preprocessing the original image, feature extraction is performed. In this process, the model and pre-trained weights need to be loaded. The model includes a convolutional neural network with a multi-scale fusion attention mechanism. The model loads the pre-trained SENet154 model weights and is enhanced based on global and local feature extraction. The specific steps are as follows:
[0114] The image tensor first passes through a basic convolutional block, including convolution, batch normalization, and ReLU activation function, to extract basic edge and texture features.
[0115] The image features are passed through the initial layer (layer0) of SENet154 to further extract features.
[0116] The features are passed through the first layer (layer1) of SENet154 to extract 256-channel features. The features are passed through the second, third, and fourth layers (layer2, layer3, and layer4) of SENet154 to extract 512, 1024, and 2048-channel features respectively. On each layer, a harmonious attention mechanism is applied, which includes spatial attention and channel attention, to enhance feature representation.
[0117] After the 2nd, 3rd, and 4th layers, the spatial transformation parameters predicted by the hard attention mechanism are applied to transform specific regions. The transformed feature map is passed through the Inception module to extract local features, which includes three parallel convolution and pooling streams to splice the results together. The extracted local features are globally average pooled to reduce the feature map to 1×1. After the 2nd, 3rd, and 4th layers, the global features are adaptively average pooled to reduce the feature map to 1×1. The global features and local features at different levels are spliced to form the final multi-scale feature representation.
[0118] The extracted feature vectors and the corresponding dish names are stored in the feature vector database for subsequent query and matching
[0119] Based on step S1015: preprocessing the original image to obtain a tensor image, specifically including the following steps:
[0120] The original image is resized to 256×256 pixels to obtain the adjusted image.
[0121] The adjusted image is cropped to obtain a 224×224 image.
[0122] Convert the 224×224 image to a tensor and get a tensor image.
[0123] In this embodiment, 200 food images and food information are collected to build a recipe library, the dish images in the recipe library are sorted, and each image is preprocessed. The preprocessing includes adjusting the image size, center cropping, normalization, etc. The specific steps are as follows:
[0124] Resizes the image to 256x256 pixels. If the original size of the image is not a square, it will be stretched or scaled to fit the specified size of 256x256.
[0125] A 224×224 image is cropped from the center of the resized image.
[0126] The image is converted into a tensor and normalized using a predefined mean and standard deviation. The mean and standard deviation here are calculated from the ImageNet dataset, using different mean and standard deviation for each channel of the RGB image.
[0127] like Figure 3 As shown, according to an embodiment of the present invention, on the other hand, an electronic device is provided, comprising: at least one processor 110; a memory 120 communicatively connected to the at least one processor, wherein the memory 120 stores instructions executable by the at least one processor 110, and the instructions are executed by the at least one processor 110 so that the at least one processor 110 can:
[0128] Get the pre-recognition image.
[0129] The feature similarity of the pre-recognition image is calculated based on the recipe library and the pre-recognition image.
[0130] Identify dish names based on feature similarity.
[0131] Identify the corresponding ingredient information based on the dish name, the ingredient information includes the ingredient name and standard portion.
[0132] Calculate total nutritional content based on ingredient information.
[0133] Output the nutritional composition results based on the total nutritional composition, and the nutritional composition results include the content and ratio of each nutritional component.
[0134] According to an embodiment of the present invention, on the other hand, a storage medium is provided, storing a computer program, which implements any one of the dietary nutrient calculation methods based on image recognition when executed by a processor.
[0135] The computer executes the instructions to perform the following steps:
[0136] Step S101: Acquire a pre-recognition image.
[0137] Step S103: Calculate the feature similarity of the pre-recognized image based on the recipe library and the pre-recognized image.
[0138] Step S105: Identify the dish name based on feature similarity.
[0139] Step S107: Identify the corresponding ingredient information according to the dish name, where the ingredient information includes the ingredient name and standard portion.
[0140] Step S109: Calculate the total nutritional content based on the food information.
[0141] Step S1011: Outputting the nutritional component results according to the total nutritional components, the nutritional component results including the content and proportion of each nutritional component.
[0142] The present invention proposes a method for calculating dietary nutritional components based on image recognition. The method uses a feature extractor and feature similarity calculation to classify dish images by comparing with existing data, obtains the ingredients and standard portions of dishes from the recipe library, allows users to manually modify the dish portions and the content of each ingredient, obtains the nutritional components of each ingredient from the nutritional component table, and finally calculates the dietary nutritional components of the dish. For dish categories that are not in the database, users are allowed to upload and update the recipe library.
[0143] The present invention combines the recipe library and the nutritional composition table to automatically obtain and identify the ingredients and standard portions of dishes, and extract the nutritional composition information of each ingredient from the nutritional composition table to provide detailed and accurate dietary nutritional composition data. The system allows users to upload new dishes and update the database to ensure the timeliness and comprehensiveness of the data.
[0144] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device, equipment, and non-volatile computer storage medium embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0145] Although the embodiments of the present invention have been described in conjunction with the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present invention, and such modifications and variations are all within the scope defined by the appended claims.
Claims
1. A method for calculating dietary nutritional components based on image recognition, characterized in that: include: Obtaining a pre-recognition image; Calculating feature similarity of the pre-recognized image based on the recipe library and the pre-recognized image; Identifying the name of the dish according to the feature similarity; Identify the corresponding ingredient information according to the dish name, wherein the ingredient information includes the ingredient name and standard portion; Calculate the total nutritional content according to the food information; The nutritional component results are output according to the total nutritional component, and the nutritional component results include the content and ratio of each nutritional component.
2. The method for calculating dietary nutrients based on image recognition according to claim 1, characterized in that: Calculating the feature similarity of the pre-recognized image based on the recipe library and the pre-recognized image, specifically comprising: Obtaining a feature vector of a pre-recognized image and all feature vectors of the recipe library; The feature vector of the pre-recognized image is compared with all feature vectors of the recipe library to calculate the similarity. The calculation formula used is the Euclidean distance calculation formula: Where d is the distance, x is i is the feature vector of the pre-recognition image, y i is the feature vector of the recipe library.
3. The dietary nutrient composition calculation method based on image recognition according to claim 1, characterized in that: The dish name is identified according to the feature similarity, specifically including: Sorting the feature similarity calculation results to obtain a sorting result; Obtaining several similar dish names according to the sorting result; The dish name is identified based on the several similar dish names.
4. The method for calculating dietary nutrients based on image recognition according to claim 3, characterized in that: If the dish name cannot be confirmed based on the several similar dish names, the recipe library is updated.
5. The dietary nutrient calculation method based on image recognition according to any one of claims 1 to 4, characterized in that: The total nutritional content is calculated based on the food information, including: Get nutritional information; Calculate the nutritional content of a single food ingredient according to the nutritional content information; Add up the nutritional components of all ingredients to obtain the total nutritional components corresponding to the dish name.
6. The dietary nutrient calculation method based on image recognition according to any one of claims 1 to 4, characterized in that: The total nutritional content is calculated based on the food information, including: adjusting the actual amount of the ingredients according to the ingredient information; The total nutritional content is calculated based on the actual serving size.
7. The dietary nutrient calculation method based on image recognition according to any one of claims 1 to 4, characterized in that: It also includes building a recipe library, including: Acquire original images of multiple foods; Preprocessing the original image to obtain a tensor image; Convolving the tensor image to extract edge and texture features; Further extract local features based on the edge and texture features, and reduce the feature map to 1×1; The global features and local features at different levels are concatenated to form the final multi-scale feature representation; The feature vectors based on the multi-scale feature representation and the corresponding dish names are stored in a feature vector database to construct the recipe library.
8. The method for calculating dietary nutrients based on image recognition according to claim 7, characterized in that: The original image is preprocessed to obtain a tensor image, specifically including: The original image is resized to 256×256 pixels to obtain an adjusted image; Cropping the adjusted image to obtain a 224×224 image; The 224×224 image is converted into a tensor to obtain the tensor image.
9. An electronic device, characterized in that: include: at least one processor (110); a memory (120) communicatively coupled to the at least one processor (110); The memory (120) stores instructions executable by the at least one processor (110), and the instructions are executed by the at least one processor (110) to enable the at least one processor (110) to: Obtaining a pre-recognition image; Calculating feature similarity of the pre-recognized image based on the recipe library and the pre-recognized image; Identifying the name of the dish according to the feature similarity; Identify the corresponding ingredient information according to the dish name, wherein the ingredient information includes the ingredient name and standard portion; Calculate the total nutritional content according to the food information; Outputting a nutrient content result according to the total nutrient content.
10. A medium, characterized in that A computer program is stored, and when the computer program is executed by a processor, a dietary nutrient component calculation method based on image recognition as described in any one of claims 1 to 8 is implemented.
Citation Information
Cited By
Method and device for identifying dishes based on food materials
CN120726617A