Artificial Intelligence with Python

Artificial Intelligence – Definition

Artificial Intelligence is the study and design of intelligent agents (computers) which have the ability to analyze the environments and produce actions which maximize success.

A computer is termed as intelligent if it has the ability for gathering information, analyze it to make decisions, and act to complete a task automatically with very little to no human intervention.

Advantages of AI

There are many advantages that an AI machine has over humans. Some of them are:

  1. Speed of execution: Computers have better memories. They can be fed a large amount of information and can retrieve it almost instantaneously. While a doctor makes a diagnosis in ~10 minutes, an AI system can make a million in the same duration.
  2. They are not lazy: Computers don’t require sleep the way humans do. They can calculate, analyze, and perform tasks tirelessly and round the clock without wearing out.
  3. Accuracy: Computers have a very high accuracy in some tasks.
  4. Less Biased: Computers are not affected or influenced by emotions, feelings, wants, needs, and other factors that often cloud our judgment and intelligence.

AI has many applications, which continue to grow by the day. Some of them are:

Application of AI

Computer Vision

AI is used in many popular object recognition systems like self-driving cars, security systems, industrial robots, etc. In this example, the robot identifies the position of the pancakes and segregates them using a robotic arm.

Indutrial Application
Source: Youtube (ABBRobotics)

Face Recognition

AI is widely used to detect and recognize faces from images. Facebook uses it to identify people in photos and tag them.


AI plays an important role in helping a machine think of a large number of possible positions based on deep knowledge in strategic games such as chess or PUBG. An AI system called AlphaZero taught itself from scratch how to master the games of Chess, Shogi, and Go.

Source: Deep Minds

Expert Systems

Machine or software that imitates the decision-making ability of humans and uses it to provide explanations and advice to the users, e.g. Youtube uses it to recommend you new videos.

Youtube Recommendation

Speech Recognition

Some AI-based speech recognition systems can ‘hear’ others, ‘express’ in the form of speech and understand what a person tells it, e.g., Siri, Alexa, and Google Assistant.

Text Recognition from Image

The handwriting recognition software reads the text written on paper and recognizes the shape of the letters and converts them into editable text.

Intelligent Robots

These robots can perform the instructions interactively given by a human.

Activity: Face Emotion Detector

Face Expression Detector Overview

In this project, we will make a script that detects the face using the camera and reports the expression of the faces detected on the stage.


Face Detection

In the past few years, face recognition has become one of the most promising applications of computer vision. Face detection can be considered to be a substantial part of face recognition operations.

The method of face detection in pictures is complicated because, well, human faces are widely different from one another! They can have different poses, expressions, positions, orientation, skin color, have glasses or facial hair or not, etc. Then are also differences in camera gain, lighting conditions, and image resolution.

Face detection is the action of locating human faces in an image and optionally returning different kinds of face-related data.

face detection

Let’s Code!

The code is pretty simple, let’s get straight into it, follow the below steps:

  1. Open Pictoblox and choose the Python (beta) coding interface. Now, select the file from the Project Files section and by default, the syntax will be written in sprite as an object.
    sprite = Sprite('Tobi')
  2. Now create an object named fd to get access to the Face Detection extension and its methods.
    fd = FaceDetection()
  3. Next, we will use the various face detection function to turn on the video, enable the bounding box, and set the threshold."on", 0) #to turn on video with 0% transparency
    fd.enablebox() #to enable bounding box
    fd.setthreshold(0.4) #to set the threshold at 0.4
  4. Now we will code to check the condition to get the expression of the face detected and if none is detected then print “No face detected”. We will use an if-else conditional statement under a while loop. To check if the count of face detected is more than 0 then the Tobi sprite will say the expression detected.
while True:
  if fd.count() > 0:
    sprite.say("No Face Detected")
  1. Here is the complete code:
sprite = Sprite('Tobi') 

fd = FaceDetection()"on", 0) 

while True: 
  if fd.count() > 0: 
    sprite.say("No Face Detected")