Hello guys ! This tutorial is in continuation to the Smile Detection using OpenCV(I) tutorial.If you have not went through the previous tutorial,I highly recommend you to go through it before proceeding with this one.

Assuming that you have gone through the last part, we start right from where we left. In brief way we have reached upto this mark :

1. Created opencv algorithm which can detect your face and your smile.

2. We were able to store our smile ratio and its respective time in a csv file.

Now moving further we will read this csv file and create attractive visuals for it.

Lets create a new file named graph.py in your project folder and add below lines.

import pandas as pd
from bokeh.plotting import figure, show, output_file
from datetime import datetime

Now that our libraries are imported lets use pandas to read our csv file created in the last tutorial.

df = pd.read_csv('smile_records.csv')

Assuming that the csv file is in the same directory.Now since our dataframe is created we can start  with our manipulation on it.

smile_ratios = list(df['smile_ratio'])
sm = [round(s, 3) for s in smile_ratios]
times = list(df['times'])
date_time = [datetime.strptime(d, '%Y-%m-%d %H:%M:%S.%f') for d in times]

Now thats done and congrats we have reached upto halfway of our goal.

We now need to plot these data on a graph using our bokeh library( Its a data visualisation library which can be used to plot interactive graphs).

p = figure(plot_width=800, plot_height=400, x_axis_type='datetime')
p.line(date_time, sm, alpha=0.5)
for s, d in zip(sm, date_time):
    if s > 2:
        p.circle(d, s, color="red", alpha=0.5, size=10)

Now that our program is complete, its time to execute it.For this move to your project directory, hold shift and right click to open command window.Once the command window is open type python graph.py to run the ‘graph.py’ script.

Thats it, we have reached the end of this tutorial and also the end of this tutorial series.

Leave a Reply

Your email address will not be published. Required fields are marked *