0% found this document useful (0 votes)
17 views26 pages

Training Report II

This training report details Sudhansu Maurya's practical training in Python, submitted to Maharaja Ranjit Singh Punjab Technical University for the B.Tech degree in Computer Science & Engineering. The document covers various aspects of Python, including its history, characteristics, data structures, functions, object-oriented programming, and a project on color detection using Python. The report emphasizes the importance of training in understanding industry requirements and enhancing practical knowledge.

Uploaded by

sudhansu maurya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views26 pages

Training Report II

This training report details Sudhansu Maurya's practical training in Python, submitted to Maharaja Ranjit Singh Punjab Technical University for the B.Tech degree in Computer Science & Engineering. The document covers various aspects of Python, including its history, characteristics, data structures, functions, object-oriented programming, and a project on color detection using Python. The report emphasizes the importance of training in understanding industry requirements and enhancing practical knowledge.

Uploaded by

sudhansu maurya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 26

TRAINING REPORT

On

PYTHON
Submitted to MAHARAJA RANJIT SINGH PUNJAB TECHNICAL
UNIVERSITY in partial fulfillment of the requirement for the award of
the degree of

B.TECH
in
COMPUTER SCIENCE &
ENGINEERING

Submitted By
SUDHANSU MAURYA
Roll No. 180280073

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

GIANI ZAIL SINGH CAMPUS COLLEGE OF


ENGINEERING& TECHNOLOGY, MRSPTU, BATHINDA-
151001

JULY 2020

TRAINING REPORT
On

PYTHON
Submitted to MAHARAJA RANJIT SINGH PUNJAB TECHNICAL
UNIVERSITY in partial fulfillment of the requirement for the award of
the degree of

B.TECH
in
COMPUTER SCIENCE &
ENGINEERING

Submitted By

SUDHANSU MAURYA

Roll No. 180280073

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

GIANI ZAIL SINGH CAMPUS COLLEGE OF ENGINEERING


& TECHNOLOGY, MRSPTU, BATHINDA - 151001
JULY 2020

CERTIFICATE OF TRAINING
PREFACE
Training is an integral part of B.Tech and each and every student has to undergo the
training for 6 or 8 weeks in a company.

This record is concerned about our practical training during the 5 th semester of our
B.Tech. We have taken our Practical training in Python. During this training, we got to
learn many new things about the industry and the current requirements of companies.
This training proved to be a milestone in our knowledge of present industry. Every say
and every moment was an experience in itself, an experience which theoretical study
can’t provide.

ACKNOWLEDGEMENT
It is my pleasure to be indebted to various people, who directly or indirectly
contributed in the development of this work and who influenced my thinking, behavior
and acts during the course of study.

I express my sincere gratitude to Dr. Dinesh Kumar worthy HOD and Er. Naresh
Garg and Er. Manpreet Kaur, Training & Placement In-charge for providing me an
opportunity to undergo summer training at INTERNSHALA ONLINE TRAININGS.

I am thankful to for his support, cooperation, and motivation provided to me during


the training for constant inspiration, presence and blessings.

I also extend my sincere appreciation to …………………………who provided his


valuable suggestions and precious time in accomplishing my training report.(if you
want to thank someone else)

Lastly, I would like to thank the almighty and my parents for their moral support and
my friends with whom I shared my day-to-day experience and received lots of
suggestions that my quality of work.

SUDHANSU MAURYA

CANDIDATE’S DECLARATION
I, SUDHANSU MAURYA Roll No. 180280073, B.Tech (Semester- V) of the Gaini
Zail Singh Campus College of Engineering & Technology, Bathinda hereby
declare that the Training Report entitled “PYTHON” is an original work and data
provided in the study is authentic to the best of my knowledge. This report has not
been submitted to any other Institute for the award of any other degree.

SUDHANSU MAURYA

(Roll No. 180280073)

Place: Bathinda

Date: 30 July 2020

INDEX
SR. NO. TOPIC PAGE
NO.

1. INTRODUCTION

2. HISTORY OF PYTHON

3. WHY PYTHON

4. CHARACTERISTICS OF
PYTHON

5. DATA STRUCTURE IN PYTHON

6. FUNCTION

7. OOPs

8. USE NUMPY

9. PROJECT

10. CONCLUSION

INTRODUCTION
Python is a widely used general-purpose, high level programming
language. It was created by Guido van Rossum in 1991 and further
developed by the Python Software Foundation. It was designed with an
emphasis on code readability, and its syntax allows programmers to
express their concepts in fewer lines of code.
Python is a programming language that lets you work quickly and
integrate systems more efficiently.
There are two major Python versions: Python 2 and Python 3. Both
are quite different.
Beginning with Python programming:
1) Finding an Interpreter:
Before we start Python programming, we need to have an interpreter to
interpret and run our programs. There are certain online interpreters
like https://ide.geeksforgeeks.org/ , http://ideone.com/ or
http://codepad.org/ that can be used to run Python programs without
installing an interpreter.
Windows: There are many interpreters available freely to run Python
scripts like IDLE (Integrated Development Environment) that comes
bundled with the Python software downloaded from http://python.org/.
Linux: Python comes preinstalled with popular Linux distros such as
Ubuntu and Fedora. To check which version of Python you’re running,
type “python” in the terminal emulator. The interpreter should start and
print the version number.
macOS: Generally, Python 2.7 comes bundled with macOS. You’ll
have to manually install Python 3 from http://python.org/.

HISTORY OF PYTHON
WHY PYTHON

1. Python is currently the most widely used multi-


purpose, high-level programming language.
2. Python allows programming in Object-Oriented and
Procedural paradigms.
3. Python programs generally are smaller than other
programming languages like Java. Programmers have
to type relatively less and indentation requirement of
the language, makes them readable all the time.
4. Python language is being used by almost all tech-giant
companies like – Google, Amazon, Facebook,
Instagram, Dropbox, Uber… etc.
5. The biggest strength of Python is huge collection of
standard library which can be used for the following:
 Machine Learning
 GUI Applications (like Kivy, Tkinter, PyQt etc. )
 Web frameworks like Django (used by
YouTube, Instagram, Dropbox)
 Image processing (like OpenCV, Pillow)
 Web scraping (like Scrapy, BeautifulSoup,
Selenium)
 Test frameworks
 Multimedia
 Scientific computing
 Text processing and many more..

CHARACTERISTICS OF PYTHON

Features in Python

There are many features in Python, some of which are discussed below

1. Easy to code:
Python is a high-level programming language. Python is very easy to
learn the language as compared to other languages like C, C#,
Javascript, Java, etc. It is very easy to code in python language and
anybody can learn python basics in a few hours or days. It is also a
developer-friendly language.
2. Free and Open Source:
Python language is freely available at the official website and you can
download it from the given download link below click on the Download
Python keyword.
Download Python
Since it is open-source, this means that source code is also available to
the public. So you can download it as, use it as well as share it.
3. Object-Oriented Language:
One of the key features of python is Object-Oriented programming.
Python supports object-oriented language and concepts of classes,
objects encapsulation, etc.
4. GUI Programming Support:
Graphical User interfaces can be made using a module such as
PyQt5, PyQt4, wxPython, or Tk in python.
PyQt5 is the most popular option for creating graphical apps
with Python.
5. High-Level Language:
Python is a high-level language. When we write programs in
python, we do not need to remember the system architecture,
nor do we need to manage the memory.
6. Extensible feature:
Python is a Extensible language. We can write us some Python
code into C or C++ language and also we can compile that
code in C/C++ language.
7. Python is Portable language:
Python language is also a portable language. For example, if we
have python code for windows and if we want to run this code
on other platforms such as Linux, Unix, and Mac then we do not
need to change it, we can run this code on any platform.
8. Python is Integrated language:
Python is also an Integrated language because we can easily
integrated python with other languages like c, c++, etc.
9. Interpreted Language:
Python is an Interpreted Language because Python code is
executed line by line at a time. like other languages C, C++,
Java, etc. there is no need to compile python code this makes it
easier to debug our code. The source code of python is
converted into an immediate form called bytecode.
10. Large Standard Library
Python has a large standard library which provides a rich set of
module and functions so you do not have to write your own
code for every single thing. There are many libraries present in
python for such as regular expressions, unit-testing, web
browsers, etc.
11. Dynamically Typed Language:
Python is a dynamically-typed language. That means the type
(for example- int, double, long, etc.) for a variable is decided at
run time not in advance because of this feature we don’t need
to specify the type of variable.
Attention geek! Strengthen your foundations with the Python
Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data
Structures concepts with the Python DS Course.

DATA STRUCTURE IN PYTHON

1. Lists : Lists in Python are one of the most versatile collection


object types available. The other two types are dictionaries and
tuples, but they are really more like variations of lists.
 Python lists do the work of most of the collection data
structures found in other languages and since they are built-in,
you don’t have to worry about manually creating them.
 Lists can be used for any type of object, from numbers and
strings to more lists.
 They are accessed just like strings (e.g. slicing and
concatenation) so they are simple to use and they’re variable
length, i.e. they grow and shrink automatically as they’re used.
 In reality, Python lists are C arrays inside the Python
interpreter and act just like an array of pointers.

2. Dictionary: In python, dictionary is similar to hash or maps in other


languages. It consists of key value pairs. The value can be accessed by
unique key in the dictionary.
 Keys are unique & immutable objects.
 Syntax:
 dictionary = {"key name": value}

3. Tuple : Python tuples work exactly like Python lists except they
are immutable, i.e. they can’t be
changed in place. They are normally written inside parentheses to
distinguish them from lists (which use square brackets), but as
you’ll see, parentheses aren’t always necessary. Since tuples are
immutable, their length is fixed. To grow or shrink a tuple, a new
tuple must be created.
Here’s a list of commonly used tuples:

4. Sets: Unordered collection of unique objects.


 Set operations such as union (|) , intersection(&), difference(-)
can be applied on a set.
 Sets are immutable i.e once created further data can’t be
added to them
 () are used to represent a set.Objects placed inside these
brackets would be treated as a set.

FUNCTION

Functions are generally the block of codes or statements in a program


that gives user the ability to reuse the same code which ultimately saves
the excessive use of memory, acts as a time saver and more importantly,
provides better readability of the code.
So basically, a function is a collection of statement that
perform some specific task and return the result to the caller.
A function can also perform some specific task without returning
anything.

OOPs

Object oriented programming is a method of structuring a


program by building related properties and behaviors into
individual object.
Class
A class is a blueprint for the object. We can think of class as a
sketch of a parrot with labels. It contains all the details about
the name, colors, size etc.
Object
An object is an instantiation of a class. when class is defined, only the
description for the object is defined. Therefore, no memory or storage is
allocated.
USE NUMPY

Numpy is a general-purpose array-processing package. It


provides a high-performance multidimensional array object, and
tools for working with these arrays. It is the fundamental
package for scientific computing with Python.
Besides its obvious scientific uses, Numpy can also be used as
an efficient multi-dimensional container of generic data.

Arrays in Numpy

Array in Numpy is a table of elements (usually numbers), all of


the same type, indexed by a tuple of positive integers. In
Numpy, number of dimensions of the array is called rank of the
array.A tuple of integers giving the size of the array along each
dimension is known as shape of the array. An array class in
Numpy is called as ndarray. Elements in Numpy arrays are
accessed by using square brackets and can be initialized by
using nested Python Lists.

Creating a Numpy Array


Arrays in Numpy can be created by multiple ways, with various number of
Ranks, defining the size of the Array. Arrays can also be created with the
use of various data types such as lists, tuples, etc. The type of the
resultant array is deduced from the type of the elements in the
sequences.

PROJECT

PYTHON COLOR DETECTION


What is Colour Detection?

Colour detection is the process of detecting the name of any


color. Simple isn’t it? Well, for humans this is an extremely easy
task but for computers, it is not straightforward. Human eyes
and brains work together to translate light into color. Light
receptors that are present in our eyes transmit the signal to the
brain. Our brain then recognizes the color. Since childhood, we
have mapped certain lights with their color names. We will be
using the somewhat same strategy to detect color names.

About the Python Project

In this color detection Python project, we are going to build an


application through which you can automatically get the name
of the color by clicking on them. So for this, we will have a data
file that contains the color name and its values. Then we will
calculate the distance from each color and find the shortest
one.

Colors Dataset

The colors.csv file includes 865 color names along with their
RGB and hex values.

Steps for Building a Project in Python – Color Detection


Here are the steps to build an application in Python that can
detect colors:

1. Download and unzip the zip file

Color Detection Zip File

The project folder contains 3 files:

Color_detection.py – main source code of our project.

Colorpic.jpg – sample image for experimenting.

Colors.csv – a file that contains our dataset.


2. Taking an image from the user

We are using argparse library to create an argument parser.


We can directly give an image path from the command prompt:

import argparse

ap = argparse.ArgumentParser()

ap.add_argument('-i', '--image', required=True, help="Image


Path")

args = vars(ap.parse_args())

img_path = args['image']

#Reading image with opencv

img = cv2.imread(img_path)

3. Next, we read the CSV file with pandas

The pandas library is very useful when we need to perform


various operations on data files like CSV. pd.read_csv() reads
the CSV file and loads it into the pandas DataFrame. We have
assigned each column with a name for easy accessing.

#Reading csv file with pandas and giving names to each


column

index=["color","color_name","hex","R","G","B"]

csv = pd.read_csv('colors.csv', names=index, header=None)

4. Set a mouse callback event on a window

First, we created a window in which the input image will


display. Then, we set a callback function which will be called
when a mouse event happens.
cv2.namedWindow('image')

cv2.setMouseCallback('image',draw_function)

With these lines, we named our window as ‘image’ and set a


callback function which will call the draw_function() whenever a
mouse event occurs.

Want to revise the Python concepts?

Check out 270+ Python Tutorials & brush up your basics

5. Create the draw_function

It will calculate the rgb values of the pixel which we double


click. The function parameters have the event name, (x,y)
coordinates of the mouse position, etc. In the function, we
check if the event is double-clicked then we calculate and set
the r,g,b values along with x,y positions of the mouse.

def draw_function(event, x,y,flags,param):

if event == cv2.EVENT_LBUTTONDBLCLK:

global b,g,r,xpos,ypos, clicked

clicked = True

xpos = x

ypos = y

b,g,r = img[y,x]

b = int(b)

g = int(g)

r = int(r)
6. Calculate distance to get color name

We have the r,g and b values. Now, we need another function


which will return us the color name from RGB values. To get the
color name, we calculate a distance(d) which tells us how close
we are to color and choose the one having minimum distance.

Our distance is calculated by this formula:

d = abs(Red – ithRedColor) + (Green – ithGreenColor) + (Blue –


ithBlueColor)

def getColorName(R,G,B):

minimum = 10000

for i in range(len(csv)):

d = abs(R- int(csv.loc[i,"R"])) + abs(G- int(csv.loc[i,"G"]))+


abs(B- int(csv.loc[i,"B"]))

if(d<=minimum):

minimum = d

cname = csv.loc[i,"color_name"]

return cname

7. Display image on the window

Whenever a double click event occurs, it will update the color


name and RGB values on the window.

Using the cv2.imshow() function, we draw the image on the


window. When the user double clicks the window, we draw a
rectangle and get the color name to draw text on the window
using cv2.rectangle and cv2.putText() functions.

while(1):

cv2.imshow("image",img)

if (clicked):

#cv2.rectangle(image, startpoint, endpoint, color,


thickness) -1 thickness fills rectangle entirely

cv2.rectangle(img,(20,20), (750,60), (b,g,r), -1)

#Creating text string to display ( Color name and RGB


values )

text = getColorName(r,g,b) + ' R='+ str(r) + ' G='+ str(g)


+ ' B='+ str(b)

#cv2.putText(img,text,start,font(0-7), fontScale, color,


thickness, lineType, (optional bottomLeft bool) )

cv2.putText(img, text,(50,50),2,0.8,
(255,255,255),2,cv2.LINE_AA)

#For very light colours we will display text in black colour

if(r+g+b>=600):

cv2.putText(img, text,(50,50),2,0.8,
(0,0,0),2,cv2.LINE_AA)

clicked=False
#Break the loop when user hits 'esc' key

if cv2.waitKey(20) & 0xFF ==27:

break

cv2.destroyAllWindows()

8. Run Python File

The beginner Python project is now complete, you can run the
Python file from the command prompt. Make sure to give an
image path using ‘-i’ argument. If the image is in another
directory, then you need to give full path of the image:

python color_detection.py -i <add your image path here>


SCREENSHOT
OUTPUT
Double click on the window to know the name of the pixel color

You might also like