136 Report
136 Report
136 Report
INTRODUCTION
1.1 OVERVIEW
1
amount of food intake and energy consumed by the individual, and a healthy
meal is necessary. Thus, maintaining a healthy diet is an important goal for
many people. The process of tracking the number of calories consumed can be
very tedious as it requires the user to keep a food journal and perform little
messy calculations to estimate the number of calories consumed in every food
item. Through this research we try to classify Indian food images into their
respective classes. The proposed software model uses machine learning as the
base which recognizes the food image that is uploaded as an input by the user,
processes the food image, recognizes it, and estimates the calories from the
predicted image. People record, upload, and share food images more willingly
than ever on websites like Instagram, Facebook etc. So, it is more convenient
to locate more data (images and videos) related to food. Consequently,
supporting users in diet management and reducing the need for the manual
paper approach.
1.2 OBJECTIVE
2
CHAPTER 2
LITERATURE SURVEY
[1]Raikwar, H., Jain, H. and Baghel, A.,Calorie Estimation from Fast Food
Images Using Support Vector Machine.2019.
[2] Subhi, M.A. and Ali, S.M., A deep convolutional neural network for food
detection and recognition, 2018.
3
implied by for vision networks and covering the hypothesized outcome by dense,
readily available components. With a little tuning of the module, modest profits
were seen in comparison to the other reference networks. Inception V3, the latest
version has been used to build a classifier in the paper.
[3] Pathanjali, C., Salis, V.E., Jalaja, G. and Latha, A.A Comparative Study
of Indian Food Image Classification Using K-Nearest-Neighbor and Support-
Vector-Machines, 2020.
[4]. Reddy, V.H., Kumari, S., Muralidharan, V., Gigoo, K. and Thakare, B.S.,
2019, May. Food Recognition and Calorie Measurement using Image
Processing and Convolutional Neural Network. In 2019 4th In-ternational
Conference on Recent Trends on Electronics, Information, Communication &
Technology (RTEICT) (pp. 109-115). IEEE.
To overcome the manual labor and the erroneous data, various applications
were developed to calculate the food intake. One of the latest technological
advancements to overcome difficulties in pictures of food items is a variety of e-
4
health applications were developed to calculate calories in food that used the
concept of image processing.
Focused on analyzing which features and models are more suitable for the
food recognition, and comply them into food analysis system to calculate the
calories. Automatically estimate the food calories from a food image via
simultaneous learning of food calories, categories, ingredients and cooking
methods using multi-task convolutional neural networks. What’s more, a food
portion estimation method to estimate the energy from food images using
generative adversarial networks. Although food recognition and nutrition contents
analysis have been a popular field in recent year, there are still a few challenges to
be solved. The first is that most of the works are dealing with image with only one
food inside. They try to use classification method to recognize the food. The
5
second challenge is the time consumed to detect the food items. Usually with
detection models, it takes about 2 seconds to detect food items from the image
Fine-tuned the AlexNet model and achieved the best results on public food
datasets so far, with top-1 accuracy of 67.7% for UEC-FOOD-256. [48] evaluates
the effectiveness in classifying food images of a deep-learning approach based on
the specifications of Google’s image recognition architecture - Inception. Their
architecture is a 54 layers CNN. M
6
CHAPTER 3
• In this existing system only detect the food cannot estimate the food
nutrition level.
7
3.2 PROPOSED SYSTEM
• Our proposed system is deep learning based system, which allow the user
to take a video of the food and measure the amount of nutrition intake
automatically.
• The need to have a system that measures daily food intake nutrition value
and that value of food intake nutrition values are maintaining daily health
records.
• The collected dataset should be viewed after 7days wheatear the nutrition
levels are good or poor nutrition. If the nutrition level is poor means
suggest try to eat more protein and fat and if less nutrition level means
suggest to do exercise
8
CHAPTER 4
SYSTEM FUNCTION
9
4.2 MODULES
• Suggestion module
In this module, the input camera will capture the video and the multiple
frames can be converted into single frame image and send to the next block for
further processing.
The Segmentation process will take place and the input image will be
segmented for the purpose of detection which is necessary to identify the region of
interest in the image. This module will convert the processed and segmented
images by performing region based segmentation process.
It uses key factors in the image like hue saturation value, descriptor points in order
to analyze the complete content of the image.
10
3. Feature extraction module:-
In this feature extraction module, the features like color, size and shape can
be extracted from the input food image.
The nutrition level of the food dataset can be pre stored in the database. In
this module, the system will use CNN algorithm to fetch the primitive features in
the pre-stored data in the database and check for the presence of those features in
the input image.
The convolutional neural network algorithm will estimate the food nutrition
level by comparing the dataset of the food nutritional level in the data base. After
that estimate the nutrition level is good or poor nutrition are intake.
The daily food intake data can be stored in the text file.
6. Suggestion module:-
The collected dataset should be viewed after 7days wheatear the nutrition
levels are good or poor nutrition. If the nutrition level is poor means suggest try to
eat more protein and fat and if less nutrition level means suggest to do exercise.
11
CHAPTER 5
SYSTEM SPECIFICATION
12
Fig no 5.1 Food CNN algorithm image
2. ReLU layer
3. Pooling layer
Convolution Layer
This is the first step in the process of extracting valuable features from an
image. A convolution layer has several filters that perform the convolution
operation. Every image is considered as a matrix of pixel values.
13
Consider the following 5x5 image whose pixel values are either 0 or 1.
There’s also a filter matrix with a dimension of 3x3. Slide the filter matrix over the
image and compute the dot product to get the convolved feature matrix.
ReLU layer
ReLU stands for the rectified linear unit. Once the feature maps are
extracted, the next step is to move them to a ReLU layer. ReLU performs an
element-wise operation and sets all the negative pixels to 0. It introduces non-
linearity to the network, and the generated output is a rectified feature map. Below
is the graph of a ReLU function:
14
Fig no 5.3 ReLU layer image
Pooling Layer
15
5.3.2 Advantages:
Disadvantages:
16
There are 4 different types of Image Pre-Processing techniques and they are
listed below.
2. Geometric Transformations
There are two types of Brightness transformations and they are below.
1. Brightness corrections
17
The most common Pixel brightness transforms operations are
2. Sigmoid stretching
3. Histogram equalization
Two commonly used point processes are multiplication and addition with a
constant.
G(x) =αf(x) +β
The parameters α>0 and β are called the gain and bias parameters and sometimes
these parameters are said to control contrast and brightness respectively.
18
5.5Region-Based Segmentation
Top-down approach
Bottom-Up approach
Select seed only from objects of interest. Grow regions only if the
similarity criterion is fulfilled.
Similarity Measures:
19
Pros:
• It did not produce many accurate segmentation results when there are no
significant differences b/w pixel values of the object and the background.
Implementation:
20
5.6 HSV color space
The HSV color space is widely used to generate high quality computer
graphics. In simple terms, it is used to select various different colors needed for a
particular picture. An HSV color wheel is used to select the desired color. A user
can select the particular color needed for the picture from the color wheel. It gives
the color according to human perception.
21
5.6.2 HSV Representations
The HSV color wheel is used to pick the desired color. Hue is represented by
the circle in the wheel. A separate triangle is used to represent saturation and value.
The horizontal axis of the triangle indicates value and the vertical axis represents
saturation. When you need a particular color for your picture, first you need to pick
a color from the hue (the circular region), and then from the vertical angle of the
triangle you can select the desired saturation. For brightness, you can select the
desired value from the horizontal angle of the triangle.
The application of the cylindrical model of HSV color space is similar to the
conical model. Calculations are done in a similar way.
Theoretically, the cylindrical model is the most accurate form of HSV color
space calculation. In practical use, it is not possible to distinguish between
saturation and hue when the value is lowered.
The cylindrical model has lost its relevance due to this and the cone shape is
preferred over it.
22
5.6.3 Advantages of HSV
• The HSV color space is quite similar to the way in which humans
perceive color.
• The other models, except for HSL, define color in relation to the primary
colors.
• The colors used in HSV can be clearly defined by human perception,
which is not always the case with RGB or CMYK.
5.7 CONTOUR MAPPING
A contour map is a type of map where the shape of the land surface is shown
by the contour lines, the relative spacing done between these lines indicates the
relative slope of the particular surface.
In the contour map meaning, it can be said that contour mapping is a type of
topography mapping, but to distinctly study the concept we will find there is an
acute difference between the two, so we cannot use each other as synonyms.
A topographic map is an accurate map that displays natural terrain and also man-
made objects like buildings, roads, or bridges. While Contour maps represent
changes in the elevation with the help of contour lines.
Each of the contour lines being marked on a map joins the points having an
equal height. The method of contouring cannot be totally relied on because two
investigators can produce different types of maps whenever interpolation between
two data takes place
23
5.7.1 Uses of Contour Mapping
The Contours provide important information which can help us to study the
nature of the terrain. This proves to be useful for the selection of sites, to determine
the catchment area of a drainage basin, or to find indivisibility between two or
more stations, etc. Some of the uses of contours are described below.
Nature of Ground
24
Fig no 5.8 Contour mapping image
25
CHAPTER 6
SYSTEM SOFTWARE
6.1 PYQT5
PyQt is a GUI widgets toolkit. It is a Python interface for Qt, one of the
most powerful, and popular cross-platform GUI library. PyQt was developed by
Riverbank Computing Ltd. The latest version of PyQt can be downloaded from its
official website − riverbankcomputing.com
26
QtOpenGL − OpenGL support classes
Supporting Environments
Windows
Wheels for 32-bit or 64-bit architecture are provided that are compatible
with Python version 3.5 or later. The recommended way to install is
using PIP utility −
The PyQt installer comes with a GUI builder tool called Qt Designer. Using
its simple drag and drop interface, a GUI interface can be quickly built without
having to write the code. It is however, not an IDE such as Visual Studio. Hence,
Qt Designer does not have the facility to debug and build the application.
28
Fig no 6.2 PYQT5 main window
29
The designed form is saved as demo.ui. This ui file contains XML representation
of widgets and their properties in the design. This design is translated into Python
equivalent by using pyuic5 command line utility. The usage of pyuic5 is as follows
pyuic5 -x demo.ui -o demo.py
In the above command, -x switch adds a small amount of additional code to the
generated Python script (from XML) so that it becomes a self-executable
standalone application.
if __name__ == "__main__":
Import sys
App = QtGui.QApplication(sys.argv)
Dialog = QtGui.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.show()
sys.exit(app.exec_())
The resultant python script is executed to show the following dialog box −
Python demo.py
The user can input data in input fields but clicking on Add button will not
generate any action as it is not associated with any function. Reacting to user-
generated response is called as event handling.
30
executed in response to user’s actions like clicking on a button, selecting an item
from a collection or a mouse click etc., called events.
Widgets used to build the GUI interface act as the source of such events.
Each PyQt widget, which is derived from QObject class, is designed to
emit ‘signal’ in response to one or more events. The signal on its own does not
perform any action. Instead, it is ‘connected’ to a ‘slot’. The slot can be
any callable Python function.
31
To start with, choose Edit signals/slots from Edit menu (or press F4). Then
highlight the button with mouse and drag the cursor towards the textbox
32
Fig no 6.8 editing page
33
6.2 PYTHON PROGRAMMING LANGUAGE
Free and open-source - You can freely use and distribute Python, even
for commercial use.
Easy to learn - Python has a very simple and elegant syntax. It's much
easier to read and write Python programs compared to other languages
like C++, Java, and C #.
Portable - You can move Python programs from one platform to another,
and run it without any changes.
34
Some facts about Python Programming Language:
PyCharm is the most popular IDE used for Python scripting language. This
chapter will give you an introduction to PyCharm and explains its features.
35
PyCharm offers some of the best features to its users and developers in the
following aspects
Advanced debugging
Support for web programming and frameworks such as Django and Flask
Features of PyCharm
1. Code Completion
PyCharm enables smoother code completion whether it is for built in
or for an external package.
2. SQLAlchemy as Debugger
You can set a breakpoint, pause in the debugger and can see the SQL
representation of the user expression for SQL Language code.
36
5. Package Management
All the installed packages are displayed with proper visual
representation. This includes list of installed packages and the ability to
search and add new packages.
6. Local History
Local History is always keeping track of the changes in a way that
complements like Git. Local history in PyCharm gives complete details of
what is needed to rollback and what is to be added.
7. Refactoring
Refactoring is the process of renaming one or more files at a time and
PyCharm includes various shortcuts for a smooth refactoring process.
37
Fig no: 6.1 PyCharm software
From the screenshot shown above, you can see the newly created project
Demo and the site-packages folder for package management along with various
other folders.
In this chapter, you will learn in detail about the installation process of
PyCharm on your local computer.
38
Steps Involved
You will have to follow the steps given below to install PyCharm on your
system. These steps show the installation procedure starting from downloading the
PyCharm package from its official website to creating a new project.
Step 1
Note that the professional package involves all the advanced features and
comes with free trial for few days and the user has to buy a licensed key for
activation beyond the trial period. Community package is for free and can be
39
downloaded and installed as and when required. It includes all the basic features
needed for installation. Note that we will continue with community package
throughout this tutorial.
Step 2
Download the community package (executable file) onto your system and
mention a destination folder as shown below –
Step 3
Now, begin the installation procedure similar to any other software package.
Step 4
This helps in creating a new project of Python where you can work from the
scratch. Note that unlike other IDEs, PyCharm only focusses on working with
projects of Python scripting language.
This chapter will discuss the basics of PyCharm and make you feel
comfortable to begin working in PyCharm editor.
When you launch PyCharm for the first time, you can see a welcome screen
with entry points to IDE such as
41
Fig no:6.5 PyCharm configure page
Recall that in the last chapter, we created a project named demo1 and we
will be referring to the same project throughout this tutorial. Now we will start
creating new files in the same project to understand the basics of PyCharm Editor.
42
Fig no:6.6 PyCharm editing page
The above snapshot describes the project overview of demo1 and the options
to create a new file. Let us create a new file called main.py.
43
The code included in main.py is as follows
The code created in the file main.py using PyCharm Editor is displayed as
shown below
This code can be run within IDE environment. The basic demonstration of
running a program is discussed below
44
Fig No:6.9 PyCharm project interpreter
45
Note that we have included some errors within the specified code such that
console can execute the code and display output as the way it is intended to.
Steps Involved
The steps for debugging the Python project are as explained below −
Step 1
Start with debugging the Python project as shown in the screenshot below –
46
Fig No:6.12 PyCharm running image
Step 2
Now, Windows firewall asks permission for debugging the Python project as
the procedure involves line by line compilation.
48
The run button moves from one line to another to execute the output as the
way we want.
Understanding Breakpoints
49
Fig No:6.17 PyCharm break points
50
6.2 Python 2 vs. Python 3
If you are reading this in 2019, then there is no point even discussing this
unless and until you work on some project which is still running on some version
of Python 2.x.
When we say Python 2.x we mean Python 2.7 and when we say Python 3.x
we mean Python 3.7 version.
If you still want to go for Python 2.7 we would like to inform you that in
2020 the Python 2.x version will be officially discontinued.
Although there are many changes in the newer version of the language i.e. in
Python 3 as compared to Python 2. We will be covering the ones which are the
most important ones which can cause issues if you are porting your code form
Python 2.7 (or any other 2.x version) to Python 3.x version.
Yes, this is one of the most visible changes as the print statement is used a
lot while you code in python.
51
CHAPTER 7
If we talk about the desktop, mobile, and you only want to do normal
gaming and for everyday use, then Ryzen APU is the way to go. For heavier tasks
like video editing, 3D modelling, etc, Ryzen 7 or 9 CPUs or Thread ripper should
be preferred.
For Ryzen Desktop CPUs and APUs in the AM4 platform, the motherboard
chipset should be checked for support otherwise PC may not boot, although it can
be easily solved with motherboards with USB BIOS flashing for newer processors.
1. AMD is cheaper
For a user who has less funds and budget, this is a good processor. The price
is quite cheap when compared with Intel. Hence it is among the best choice for the
gamers. The price is still low because AMD has not been holding and dominating
the world market which is still being dominated by Intel and also hasn’t earned
much reputation in the market.
Along with the cheaper price, the quality of AMD graphics processor is
better and suitable for playing games because it makes the graphics display of the
game more interesting if with this AMD processor. But, for YouTubers or renderer
Intel is a better choice as AMD can be less suitable if using this one processor.
53
3. AMD Processors Can Detect Malware
1. Less Fame
Talking about the number of users in the world, AMD is very far from Intel.
AMD brand is not very familiar to ordinary people. This is the reason behind the
AMD processors being cheaper than the price of Intel because of its less fame
though the quality of AMD is not less than Intel, even outside Intel.
The AMD processors often expel heat because it does not use the heat sink
as its main cooling component. It still uses the fan as a cooling component.
However, some people have switched to ice cooler to reduce the noise that is not
pleasant to hear.
54
3. Lost to Multimedia
Users being mostly involved in the multimedia world are not recommended
to use this processor in the process you do. Intel is much preferable because it is
designed to handle matters relating to multimedia.
Hence, these are few of the pros and cons of AMD processor. Though it is
lagging behind Intel processors, it is doing its best. Analyze the market and your
needs to choose best processor for yourself.
55
7.2 RAM (Random Access Memory)
7.2.1History of RAM:
The first type of RAM was introduced in 1947 with the Williams tube. It
was used in CRT (cathode ray tube), and the data was stored as
electrically charged spots on the face.
56
The second type of RAM was a magnetic-core memory, invented in
1947. It was made of tiny metal rings and wires connecting to each ring.
A ring stored one bit of data, and it can be accessed at any time.
In October 1969, Intel introduced its first DRAM, the Intel 1103. It was
its first commercially available DRAM.
The word static indicates that the memory retains its contents as long as
power is being supplied. However, data is lost when the power gets down due to
volatile nature. SRAM chips use a matrix of 6-transistors and no capacitors.
57
Transistors do not require power to prevent leakage, so SRAM need not be
refreshed on a regular basis.
There is extra space in the matrix, hence SRAM uses more chips than
DRAM for the same amount of storage space, making the manufacturing costs
higher. SRAM is thus used as cache memory and has very fast access.
RAM allows your computer to perform many of its everyday tasks, such as
loading applications, browsing the internet, editing a spreadsheet, or experiencing
the latest game. Memory also allows you to switch quickly among these tasks,
remembering where you are in one task when you switch to another task. As a rule,
the more memory you have, the better.
When you turn on your computer and open a spreadsheet to edit it, but first
check your email, you’ll have used memory in several different ways. Memory is
used to load and run applications, such as your spreadsheet program, respond to
commands, such as any edits you made in the spreadsheet, or toggle between
59
multiple programs, such as when you left the spreadsheet to check email. Memory
is almost always being actively used by your computer.
Advantages of RAM
A RAM disk is like a hard drive, but it makes the use of memory. You can
use a RAM disk like: you can copy applications and files to the RAM disk, and
then you can start those applications or those files from there if the program
allows that. Mostly, RAM disks are suitable for those
60
• Who want to store temporary data?
• You can also set the Windows temp folder location there for instance.
Whenever you restart your computer, this data got removed entirely
automatically, and you do not need to do this manually.
61
CHAPTER 8
RESULTS
Thus, our project food nutritional intake tracking system based on deep
learning was successfully implemented. In this system the person intake food
nutritional status can be determined by using convolutional neural network
algorithm and also measured number of nutritional data that can be stored in a
file as a daily health record.
62
CHAPTER 9
CONCLUSION
63
CODING AND OUTPUT
10.1.1 FRONT END
from PyQt5 import QtCore, QtGui, QtWidgets
from page2 import Ui_MainWindow_1
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(-4, -10, 831, 631))
self.label.setText("")
self.label.setPixmap(QtGui.QPixmap("1.jpg"))
self.label.setScaledContents(True)
self.label.setObjectName("label")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(34, 20, 681, 61))
self.pushButton.setStyleSheet("background-color: rgb(0, 255, 255);\n"
"font: 75 14pt \"MS Shell Dlg 2\";")
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_2.setGeometry(QtCore.QRect(570, 270, 161, 61))
self.pushButton_2.setStyleSheet("background-color: rgb(255, 170, 127);\n"
64
"font: 75 12pt \"MS Shell Dlg 2\";")
self.pushButton_2.setObjectName("pushButton_2")
self.pushButton_5 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_5.setGeometry(QtCore.QRect(300, 460, 191, 61))
self.pushButton_5.setStyleSheet("background-color: rgb(85, 255, 255);\n"
"font: 75 14pt \"MS Shell Dlg 2\";")
self.pushButton_5.setObjectName("pushButton_5")
MainWindow.setCentralWidget(self.centralwidget)
self.pushButton_5.clicked.connect(self.next_fun)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def next_fun(self):
self.Mainwindow_1 = QtWidgets.QMainWindow()
self.ui = Ui_MainWindow_1()
self.ui.setupUi(self.Mainwindow_1)
self.Mainwindow_1.show()
65
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
from PyQt5 import QtCore, QtGui, QtWidgets
from page3 import Ui_MainWindow_2
class Ui_MainWindow_1(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(-34, -10, 851, 621))
self.label.setText("")
self.label.setPixmap(QtGui.QPixmap("2.webp"))
self.label.setScaledContents(True)
self.label.setObjectName("label")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
66
self.pushButton.setGeometry(QtCore.QRect(84, 30, 601, 61))
self.pushButton.setStyleSheet("font: 75 14pt \"MS Shell Dlg 2\";\n"
"background-color: rgb(0, 255, 255);")
self.pushButton.setObjectName("pushButton")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(100, 220, 141, 41))
self.label_2.setStyleSheet("background-color: rgb(255, 170, 127);\n"
"font: 75 14pt \"MS Shell Dlg 2\";")
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(100, 290, 141, 41))
self.label_3.setStyleSheet("background-color: rgb(255, 170, 127);\n"
"font: 75 14pt \"MS Shell Dlg 2\";")
self.label_3.setObjectName("label_3")
self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(340, 220, 401, 41))
self.lineEdit.setStyleSheet("font: 75 12pt \"MS Shell Dlg 2\";")
self.lineEdit.setObjectName("lineEdit")
self.lineEdit_2 = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit_2.setGeometry(QtCore.QRect(340, 290, 401, 41))
self.lineEdit_2.setStyleSheet("font: 75 12pt \"MS Shell Dlg 2\";")
self.lineEdit_2.setObjectName("lineEdit_2")
self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_2.setGeometry(QtCore.QRect(280, 460, 201, 61))
self.pushButton_2.setStyleSheet("background-color: rgb(85, 255, 255);\n"
67
"font: 75 16pt \"MS Shell Dlg 2\";")
self.pushButton_2.setObjectName("pushButton_2")
MainWindow.setCentralWidget(self.centralwidget)
self.pushButton_2.clicked.connect(self.next_fun)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def next_fun(self):
user = self.lineEdit.text()
password = self.lineEdit_2.text()
if (user == "12345" and password == "12345"):
self.Mainwindow_2 = QtWidgets.QMainWindow()
self.ui = Ui_MainWindow_2()
68
self.ui.setupUi(self.Mainwindow_2)
self.Mainwindow_2.show()
else:
print("something wrong")
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow_1()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
class Ui_MainWindow_2(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 601)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
69
self.label.setGeometry(QtCore.QRect(-24, -10, 831, 631))
self.label.setText("")
self.label.setPixmap(QtGui.QPixmap("3.jpg"))
self.label.setScaledContents(True)
self.label.setObjectName("label")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(60, 30, 641, 61))
self.pushButton.setStyleSheet("background-color: rgb(0, 255, 255);\n"
"font: 75 14pt \"MS Shell Dlg 2\";")
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_2.setGeometry(QtCore.QRect(290, 240, 171, 51))
self.pushButton_2.setStyleSheet("background-color: rgb(255, 170, 127);\n"
"font: 75 14pt \"MS Shell Dlg 2\";")
self.pushButton_2.setObjectName("pushButton_2")
self.pushButton_3 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_3.setGeometry(QtCore.QRect(290, 350, 171, 51))
self.pushButton_3.setStyleSheet("background-color: rgb(255, 170, 127);\n"
"font: 75 14pt \"MS Shell Dlg 2\";")
self.pushButton_3.setObjectName("pushButton_3")
MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
self.pushButton_2.clicked.connect(self.web1_fun)
70
self.pushButton_3.clicked.connect(self.web2_fun)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.pushButton.setText(_translate("MainWindow", "FOOD CHECKER
PAGE"))
self.pushButton_2.setText(_translate("MainWindow", "Food checker"))
self.pushButton_3.setText(_translate("MainWindow", "Draw graph"))
def web1_fun(self):
Diabetic_food_checker(self)
def web2_fun(self):
draw_graph(self)
10.1.2BACK END
import cv2
from datetime import datetime
import os
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import csv
import time
import pandas as pd
71
def Diabetic_food_checker(self):
thres = 0.45
cap = cv2.VideoCapture(0)
cap.set(3,1280)
cap.set(4,720)
cap.set(10,70)
classNames= []
classFile = 'coco.data'
with open(classFile,'rt') as f:
classNames = f.read().rstrip('\n').split('\n')
configPath = 'ssd_mobilenet_v3_large_coco_2020_01_14.pbtxt'
weightsPath = 'frozen_inference_graph.pb'
net = cv2.dnn_DetectionModel(weightsPath,configPath)
net.setInputSize(320,320)
net.setInputScale(1.0/ 127.5)
net.setInputMean((127.5, 127.5, 127.5))
net.setInputSwapRB(True)
if not os.path.exists('./food.csv'):
with open('food.csv', 'a+') as file_create:
# file_create.write(str(""))
file_create.write(str("type\n"))
72
while True:
success,img = cap.read()
classIds, confs, bbox = net.detect(img,confThreshold=0.45)
if len(classIds) != 0:
i=0
for classId, confidence,box in zip(classIds.flatten(),confs.flatten(),bbox):
object_name=(classNames[classId-1])
object_id=[classId-1]
# print(object_id)
# print(object_name)
if object_id ==[52]:
for i in str(1):
with open('food.csv', 'a+') as file_create:
file_create.write(str(""))
file_create.write(str("good\n"))
73
print("good food")
time.sleep(1)
if object_id == [51]:
cv2.rectangle(img, box, color=(0, 255, 0), thickness=2)
cv2.putText(img, f'{classNames[classId - 1]}', (box[0] + 10, box[1]
+ 30), cv2.FONT_HERSHEY_COMPLEX,1, (0, 255, 0), 2)
cv2.putText(img, str(round(confidence * 100, 2)), (box[0] + 200,
box[1] + 30), cv2.FONT_HERSHEY_COMPLEX, 1, (0, 255, 0), 2)
for i in str(1):
with open('food.csv', 'a+') as file_create:
file_create.write(str("good\n"))
print("good food")
time.sleep(1)
if object_id == [56]:
cv2.rectangle(img, box, color=(0, 255, 0), thickness=2)
cv2.putText(img, f'{classNames[classId - 1]}', (box[0] + 10, box[1]
+ 30), cv2.FONT_HERSHEY_COMPLEX,1, (0, 255, 0), 2)
cv2.putText(img, str(round(confidence * 100, 2)), (box[0] + 200,
box[1] + 30),cv2.FONT_HERSHEY_COMPLEX, 1, (0, 255, 0), 2)
for i in str(1):
with open('food.csv', 'a+') as file_create:
file_create.write(str("good\n"))
print("good food")
74
time.sleep(1)
if object_id == [57]:
cv2.rectangle(img, box, color=(0, 255, 0), thickness=2)
cv2.putText(img, f'{classNames[classId - 1]}', (box[0] + 10, box[1]
+ 30), cv2.FONT_HERSHEY_COMPLEX,1, (0, 255, 0), 2)
cv2.putText(img, str(round(confidence * 100, 2)), (box[0] + 200,
box[1] + 30),cv2.FONT_HERSHEY_COMPLEX, 1, (0, 255, 0), 2)
for i in str(1):
with open('food.csv', 'a+') as file_create:
file_create.write(str("good\n"))
print("good food")
time.sleep(1)
if object_id == [58]:
cv2.rectangle(img, box, color=(0, 255, 0), thickness=2)
cv2.putText(img, f'{classNames[classId - 1]}', (box[0] + 10, box[1]
+ 30), cv2.FONT_HERSHEY_COMPLEX,1, (0, 255, 0), 2)
cv2.putText(img, str(round(confidence * 100, 2)), (box[0] + 200,
box[1] + 30),cv2.FONT_HERSHEY_COMPLEX, 1, (0, 255, 0), 2)
for i in str(1):
with open('food.csv', 'a+') as file_create:
file_create.write(str("bad\n"))
75
print("bad")
time.sleep(1)
if object_id == [59]:
cv2.rectangle(img, box, color=(0, 255, 0), thickness=2)
cv2.putText(img, f'{classNames[classId - 1]}', (box[0] + 10, box[1]
+ 30), cv2.FONT_HERSHEY_COMPLEX,1, (0, 255, 0), 2)
cv2.putText(img, str(round(confidence * 100, 2)), (box[0] + 200,
box[1] + 30),cv2.FONT_HERSHEY_COMPLEX, 1, (0, 255, 0), 2)
for i in str(1):
with open('food.csv', 'a+') as file_create:
file_create.write(str("bad\n"))
print("bad")
time.sleep(1)
cv2.imshow("Output",img)
k = cv2.waitKey(30) & 0xff
if k == 27:
break
cap.release()
cv2.destroyAllWindows()
def draw_graph(self):
76
data = pd.read_csv('./food.csv')
totalVal = data['type'].value_counts().to_dict()
print(totalVal)
name = []
countVal = []
for i, j in totalVal.items():
name.append(i)
countVal.append(j)
plt.bar(name, countVal)
plt.show()
77
OUTPUT
78
CHAPTER 11
REFERENCES
[1]. Rajayogi, J.R., Manjunath, G. and Shobha, G., 2019, December. Indian Food
Image Classification with Transfer Learning. In 2019 4th Inter-national
Conference on Computational Systems and Information Technology for
Sustainable Solution (CSITSS) (Vol. 4, pp. 1-4). IEEE.
[2]. Reddy, V.H., Kumari, S., Muralidharan, V., Gigoo, K. and Thakare, B.S.,
2019, May. Food Recognition and Calorie Measurement using Image Processing
and Convolutional Neural Network. In 2019 4th In-ternational Conference on
Recent Trends on Electronics, Information, Communication & Technology
(RTEICT) (pp. 109-115). IEEE.
[3]. Subhi, M.A. and Ali, S.M., 2018, December. A deep convolutional neural
network for food detection and recognition. In 2018 IEEE-EMBS conference on
biomedical engineering and sciences (IECBES) (pp. 284-287). IEEE.
79
[7] S. Ao and C. X. Ling, “Adapting new categories for food recognition with
deep representation,” in 2020 IEEE International Conference on Data Mining
Workshop (ICDMW). IEEE, 2020, pp. 1196–1203.
[11] T. Ege and K. Yanai, “Image-based food calorie estimation using knowledge
on food categories, ingredients and cooking directions,” in Proceedings of the on
Thematic Workshops of ACM Multimedia 2017. ACM, 2017, pp. 367–375.
[12] Pathanjali, C., Salis, V.E., Jalaja, G. and Latha, A., 2018. A Comparative
Study of Indian Food Image Classification Using K-Nearest-Neighbor and
Support-Vector-Machines. J. Eng. Techno, 7, pp.521-525.
80
[14] P. Sundaravadivel, K. Kesavan, L. Kesavan, S. P. Mohanty, E. Kougianos,
and M. K. Ganapathiraju, “Smart-Log: An Automated, Predictive Nutrition
Monitoring System for Infants Through IoT,” in Proc. IEEE Int. Conf. Consum.
Electron. 2018.
[17] Zakaria Al-Battashi, John Bronlund, Gourab Sen Gupta, “Investigations into
Force Sensor Characteristics for Food Texture Measurements”, IEEE International
Conference on Instrumentation and Measurement Technology (I2MTC), p.p. 2089-
2094, 2019.
81