Longevity logo

Calorie Estimation of Food using ML And OpenCV

The best way to estimate Food calories with the reference object(research Base)

By Smit PrajapatiPublished 5 years ago 3 min read

Nowadays diet has become part of life. Eating a healthy balanced diet accompanied by regular exercise is essential in maintaining physical and mental health and well-being. Not only are these effective in preventing excess weight gain or in maintaining weight loss, but healthier lifestyles are also associated with improved sleep and mood. I was wondering what if we can get the value of food calories. so I started researching, how we get accurate calories.

I know you may have seen many methods for Food calories estimation. But I Found a very unique technique to get Food calories. In this article, I will be discuss with you only about apple calories estimation.

As you all know there are many deep learning models to estimate apple calories.

So what the Problem with deep learning models?

We know that if we use any models, It's high chance that the model will be overfitting or underfitting. Let's see how it gonna work

First of all, I had created a K-Mean clustering model. I trained it to just cluster the unique pixel in the image or you can train it for only apple's pixel. we will use a coin as a reference with apple.

Now we use API to remove the background of an image and set any intense color of the background, which will help us to identify the contour of the image. Now it's time to find contour using our K-Mean Clustering model and Opencv. The output should like this:-

As we all know that an apple is a 3D object. so what we can do is use two images, one is Top View and the second is Side with coin as a reference(Note down the height and width of coin).

Now we can get the shape for both apple and coin. After getting the dimensions of apple and coin convert them into either inch, meter, or centimeter(Take Avg. for Top view height and width and Side view height and width). The dimension we got after converting into a particular scale is just the image's object dimension, what we want is the real height and width of the apple. So we will compare the real coin's height and width with the image's coin height width. It's just simple math. After comparison, we will get a ratio of the coin. After that multiply with the image's apple height and width and we will have our real height and width.

It's so simple from Now. We know how to find the volume of the sphere(use the Ave. value we found before and take it as radius).

Volume Formula for apple in Our case

From the above equation(I was using this formula because it's fit the best for apple's shape), we can get the Volume of the apple with real measure. We know the standard density of apple from that we will have apple's weight. The value of an apple's calories per 100gm is around 0.52. From the calories formula, we can easily get the real calories of an apple. Isn't it quite easy from other methods?

We can also check how accurate our method works, for that we can take the dimensions of apples we have and then apply the method to the image and compare the weight of both results.

Here You can see what result I find from the method. In this sheet, I am sharing only a few results.

Experiment Result:--https://cutt.ly/Inw4U05

Conclusion

The method we use is quite easy from others but it's only possible with a reference object, it's the only limitation of this method. This method can be improved, we can add an artificial object with an apple in the real world, It will handier.

I hope you like the technique I explained. I want to also thank my mates who help me with this technique.

Author linkedin:-https://bit.ly/2TdV6EY

Research partner:

Harsh Trambdia:https://bit.ly/3um5pnr

Bhargav Taraviya: https://bit.ly/2ShVyld

diet

About the Creator

Reader insights

Be the first to share your insights about this piece.

How does it work?

Add your insights

Comments

There are no comments for this story

Be the first to respond and start the conversation.

Sign in to comment

    Find us on social media

    Miscellaneous links

    • Explore
    • Contact
    • Privacy Policy
    • Terms of Use
    • Support

    © 2026 Creatd, Inc. All Rights Reserved.