0% found this document useful (0 votes)
38 views5 pages

Machine Vision Exp 1 (Mumbai Univesrity)

The document discusses an experiment involving basic image and video processing using OpenCV. It introduces OpenCV and discusses reading and writing image/video files, converting between images and raw bytes, and accessing image data with NumPy arrays. The implementation section demonstrates these concepts by changing an image's format and color, generating images from random byte arrays, and inspecting image properties with NumPy.

Uploaded by

Om Bhamare
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)
38 views5 pages

Machine Vision Exp 1 (Mumbai Univesrity)

The document discusses an experiment involving basic image and video processing using OpenCV. It introduces OpenCV and discusses reading and writing image/video files, converting between images and raw bytes, and accessing image data with NumPy arrays. The implementation section demonstrates these concepts by changing an image's format and color, generating images from random byte arrays, and inspecting image properties with NumPy.

Uploaded by

Om Bhamare
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/ 5

Om Bhamare

BE B 05
Machine Vision

Experiment 1

Title: Handling Files, Cameras, and GUIs

Aim: Basic I/O scripts ,Reading/writing an image file ,Converting between an image
and raw
bytes , Accessing image data with numpy.array ,Reading/writing a video file
,Capturing
camera frames, Displaying images in a window, Displaying camera frames in a
window

Theory:
OpenCV is the huge open-source library for computer vision, machine learning, and
image processing and now it plays a major role in real-time operation which is very
important in today’s systems. By using it, one can process images and videos to
identify objects, faces, or even handwriting of a human. When integrated with various
libraries, such as NumPy, python is capable of processing the OpenCV array
structure for analysis. To Identify image pattern and its various features we use
vector space and perform mathematical operations on these features.
The first OpenCV version was 1.0. OpenCV is released under a BSD licence and
hence it’s free for both academic and commercial use. It has C++, C, Python and
Java interfaces and supports Windows, Linux, Mac OS, iOS and Android. When
OpenCV was designed the main focus was real-time applications for computational
efficiency. All things are written in optimised C/C++ to take advantage of multi-core
processing.
Applications of OpenCV: There are lots of applications which are solved using
OpenCV, some of them are listed below

● face recognition
● Automated inspection and surveillance
● number of people – count (foot traffic in a mall, etc)
● Vehicle counting on highways along with their speeds
● Interactive art installations
● Anomaly (defect) detection in the manufacturing process (the odd
defective products)
● Street view image stitching
● Video/image search and retrieval
● Robot and driver-less car navigation and control
● object recognition
● Medical image analysis
● Movies – 3D structure from motion
● TV Channels advertisement recognition

OpenCV Functionality
● Image/video I/O, processing, display (core, imgproc, highgui)
● Object/feature detection (objdetect, features2d, nonfree)
● Geometry-based monocular or stereo computer vision (calib3d, stitching,
videostab)
● Computational photography (photo, video, superres)
● Machine learning & clustering (ml, flann)
● CUDA acceleration (gpu)

Implementation:

from email.mime import image


import cv2
from cv2 import imread
from cv2 import VideoCapture
import numpy
import os

window_name = 'Image'
#######################################
# 1] Basic I/O scripts ,Reading/writing an image file #
#######################################

#Change file format


imgFormatChange = cv2.imread('/content/drive/MyDrive/4th Year/Sem 7/Machine
Vision/Practicals/Exp 1/Robert1.jpg')
cv2.imwrite('/content/drive/MyDrive/4th Year/Sem 7/Machine Vision/Practicals/Exp
1//1/Robert1Output.png',imgFormatChange)

#Changing Image color to gray lol


grayIamge = cv2.imread('/content/drive/MyDrive/4th Year/Sem 7/Machine
Vision/Practicals/Exp 1/EiHome.jpg',cv2.IMREAD_GRAYSCALE)
cv2.imwrite('/content/drive/MyDrive/4th Year/Sem 7/Machine Vision/Practicals/Exp
1/1/EiHomePicReduceColor8_1.png',grayIamge)

#####################################
# 2]Converting between an image and raw bytes #
#####################################

# Make an array of 120,000 random bytes.


randomByteArray = bytearray(os.urandom(120000))
flatNumpyArray = numpy.array(randomByteArray)

# Convert the array to make a 400x300 grayscale image.


grayIamge2 = flatNumpyArray.reshape(300,400)
cv2.imwrite('/content/drive/MyDrive/4th Year/Sem 7/Machine Vision/Practicals/Exp
1/2/RandomGray.png',grayIamge2)

# Convert the array to make a 400x100 color image.


colorImage2 = flatNumpyArray.reshape(100,400,3)
cv2.imwrite('/content/drive/MyDrive/4th Year/Sem 7/Machine Vision/Practicals/Exp
1/2/ColorImage.png',colorImage2)

#################################
# 4]Accessing image data with numpy.array#
#################################

img3 = imread('/content/drive/MyDrive/4th Year/Sem 7/Machine


Vision/Practicals/Exp 1/Ronaldo1.jpg')
print(img3.item(0,0,0))

img3.itemset((0,0,0),255)
print(img3.item(0,0,0))

print(img3.size)
print(img3.reshape)
print(img3.dtype)
Input File:
EiHome.jpg

Robert1.jpg

Output
Changing Image color to gray: EiHomePicReduceColor8_1.png

Change File Format: Robert1Output.png

Convert the array to make a 400x100 color image.: ColorImage.png


Convert the array to make a 400x300 grayscale image.: RandomGray.png

Accessing image data with numpy.array


186
255
3147264
<built-in method reshape of numpy.ndarray object at 0x7fe1b9169e70>
uint8

Conclusion:
In this we study opencv and Basic I/O scripts ,Reading/writing an image file
,Converting between an image and raw bytes , Accessing image data with
numpy.array ,Reading/writing a video file ,Capturing camera frames, Displaying
images in a window, Displaying camera frames in a window

You might also like