0% found this document useful (0 votes)
11 views8 pages

Prac 2 ACV-merged

The document outlines several practical applications of computer vision using Python and OpenCV, including face detection, pencil sketch conversion, image resizing and renaming, and text extraction with barcode reading. Each section provides an introduction, theory, tools, techniques, and sample code for implementing the respective applications. The document emphasizes the use of machine learning models and image processing techniques to achieve the desired outcomes.

Uploaded by

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

Prac 2 ACV-merged

The document outlines several practical applications of computer vision using Python and OpenCV, including face detection, pencil sketch conversion, image resizing and renaming, and text extraction with barcode reading. Each section provides an introduction, theory, tools, techniques, and sample code for implementing the respective applications. The document emphasizes the use of machine learning models and image processing techniques to achieve the desired outcomes.

Uploaded by

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

Practical No.

Aim: Write a Program for face detection.

1. Introduction :-
Face detection is a computer vision technology used to identify human faces in digital images. It
is widely applied in security, surveillance, biometrics, and interactive applications.

2. Theory :-
Face detection involves identifying and locating faces within an image using machine learning
models such as Haar cascades or deep learning-based models like CNNs. OpenCV provides pre-
trained models to detect faces efficiently.

3. Tools :-
- Python
- OpenCV Library
- Haar Cascade Classifier
- Computer with a Webcam (Optional for real-time detection)

4. Technique :-
The program utilizes OpenCV’s Haar cascade classifier to detect faces. The image is converted
to grayscale for better accuracy, and the classifier scans for facial features. Detected faces are
marked with rectangles.

5. Parameters :-
- scaleFactor: Controls image scaling (default 1.1)
- minNeighbors: Specifies neighbor count for detection (default 5)
- minSize: Defines the smallest detectable face size (default 30x30 pixels)
6. Program :-
import cv2
from google.colab.patches import cv2_imshow
def detect_faces(image_path):
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades +
'haarcascade_frontalface_default.xml')
img = cv2.imread(image_path)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY
faces = face_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=5,
minSize=(30, 30))
for (x, y, w, h) in faces:
cv2.rectangle(img, (x, y), (x+w, y+h), (255, 0, 0), 2)
cv2_imshow(img)
cv2.waitKey(0)
cv2.destroyAllWindows()
detect_faces('/content/Rohit.png')

7. Conclusion :-
Face detection is a crucial aspect of computer vision with applications in security, identity
verification, and human-computer interaction.

8. Output :-
Practical No.:- 4
1. Introduction

In this practical, we will convert a colored image into a pencil sketch. Pencil sketches are
artistic drawings created by hand using pencils to mimic the shape and details of an image. In
this experiment, we will automate the conversion process using Python and OpenCV, a
popular computer vision library. The goal is to apply image processing techniques such as
grayscale conversion, Gaussian blur, and image division to create the sketch effect.

2. Theory

Grayscale Conversion: Converts the image from color (RGB) to a single intensity
channel, simplifying its details.

Gaussian Blur: Applies a smoothing filter to reduce high-frequency noise, creating a soft
blur effect.

Image Division: Divides the grayscale image by the blurred version, enhancing light and
dark areas to simulate pencil strokes.

Sketching Effect: Combines the above techniques to create an image that mimics a
traditional pencil sketch.

3. Tools, Library, Technique, and Method

Tools:

• Python: A versatile programming language that supports libraries for image


processing.
• OpenCV: A library for computer vision and image processing tasks.
• Numpy: A library for scientific computing that aids in matrix and array operations
essential for image processing.

Library:

• cv2 (OpenCV): Used for reading, displaying, and processing images.


• numpy: Provides mathematical functions for array manipulations in image
processing.

Technique:

• Grayscale Conversion: Converts the image to shades of gray to simplify its structure.
• Gaussian Blur: Applies a blur to smooth the image and reduce noise.
• Image Division: Enhances the contrast between light and dark regions to mimic
pencil strokes.

Method:

The process involves reading the image, converting it to grayscale, applying Gaussian blur,
and then dividing the grayscale image by the blurred version to create a pencil sketch effect.
4. Program

5. Conclusion
This practical successfully converts a colored image into a pencil sketch using OpenCV's
image processing techniques.
Practical No.:- 3
1. Introduction

Images are a crucial part of digital content, often requiring modifications like resizing for
different platforms and renaming for better organization. This program demonstrates how to
display, resize, and rename an image using Python.

2. Theory

• Image processing involves various operations such as resizing, renaming, and


displaying images.
• Resizing helps in reducing or enlarging an image while maintaining aspect ratio.
Renaming is useful for organizing files systematically.
• Python provides powerful libraries like OpenCV and PIL (Pillow) to perform these
operations efficiently.

3. Library and Technique

Library:

• cv2 (OpenCV) – For image reading, resizing, and displaying.


• os – For renaming the image file

Technique:

• Image resizing using cv2.resize().


• Displaying an image using cv2.imshow().
• Renaming a file using os.rename().

4. Program
Output

Original Image

Resized Image

5. Conclusion
This program successfully reads, displays, resizes, and renames an image using Python's
OpenCV and OS libraries.
Practical No. 1
Aim :- Write a code for "Text Scanner" & Barcode Reader using Python.

1. Introduction:

In this project, we aim to build a Python-based application that can perform two tasks:

1. Text Extraction from an image using OCR (Optical Character Recognition).


2. Barcode Scanning to decode barcodes from an image.

For text extraction, we'll use Tesseract OCR, an open-source OCR engine that can recognize
text in images. For barcode scanning, we'll utilize the pyzbar library, which provides an easy
way to decode various types of barcodes.

2. Parameters:

• Image Path: The path to the image file that contains text or a barcode. This path needs
to be provided as input to the program.
• OCR Engine: Tesseract OCR will be used to process the image and extract text. It
works best with clean, high-contrast images and requires the image to be processed
(e.g., converted to grayscale) for better accuracy.
• Barcode Types: The pyzbar library supports various barcode types, including QR
codes, EAN-13, and Code128.

3. Steps:

Install Libraries:
Install opencv-python, pytesseract, and pyzbar
(pip install opencv-python pytesseract pyzbar)

Text Extraction:

• Read the image with OpenCV.


• Convert to grayscale for better OCR accuracy.
• Use Tesseract OCR to extract and print the text.

Barcode Detection:

• Read the image with OpenCV.


• Use pyzbar to detect and decode barcodes.
• Draw a rectangle around the barcode and print its data.
4. Code ( Text Reader):

5. Code ( Barco Reader):

You might also like