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

Raspberry Pi Section-4

Uploaded by

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

Raspberry Pi Section-4

Uploaded by

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

Basics of Image Processing

• Manipulation of digital image by using computer algorithms to get refined or


enhanced image is Digital Image Processing.

• Digital Image Processing by OpenCV.

• A very powerful image processing platform which is open-source library for


Python as well as C, Function is mainly focuses on real-time computer vision.
Examples of Image Processing

2
Installing OpenCV
• Open terminal and install OpenCV dependencies

• Make sure that pip is installed.


Install pip by “> sudo apt-get install python-pip”

• NumPy, Matplotlib and SciPy


Install NumPy by “> sudo apt-get install python-numpy” or
“pip install numpy”

Install SciPy by “> sudo apt-get install python-scipy” or


“pip install scipy”

Install Matplotlib by “sudo apt-get install python-matplotlib”

• Installing OpenCV libraries to python


“sudo apt-get install python-opencv”

After installation check the version openCV by “cv2.__version__”


3
Basic Image manipulation
• Commands for image manipulation

• Reading an image from file


import cv2
import numpy as np

img = cv2.imread(‘image.jpg’) # reading an image file


img = cv2.imshow(“image” , img) #shows the image with title “image”

• Reading an image from camera


import cv2
import bumpy as np

cam = cv2.VideoCapture(0) #captures the image from camera 0


Size, image = cam.read() #reads the image from captured
cv2.imshow(“Image”, image) #shows the image “image” title
cv2.imwrite(“Image.bmp”,image) #writes the captured image to bmp file

4
Image operation
• Accessing Pixel by Pixel
>>> px = img[100,100]
>>> print px
[157 166 200]

# accessing only blue pixel


>>> blue = img[100,100,0]
>>> print blue
157

• Modifying Each pixel Values


>>> img[100,100] = [255,255,255]
>>> print img[100,100]
[255 255 255]
# accessing RED value
>>> img.item(10,10,2)
59

# modifying RED value


>>> img.itemset((10,10,2),100)
>>> img.item(10,10,2) 5
100
• Accessing image properties

>>> print img.shape


(342, 548, 3) # (rows, columns, no.of. channel)
#channels = blue , green , red

>>> print img.size # image size in bytes


562248

• Region of Image (ROI)


>>> object = img[280:340, 330:390]
>>> img[273:333, 100:160] = object

• Image Channel Splitting and Merging


>>> b,g,r = cv2.split(img)
>>> img = cv2.merge((b,g,r))
6
Capturing LiveFeed from Camera

• Capturing Live feed from camera and displaying

Import cv2
Cap = cv2.VideoCapture(0)

While True :
ret, img= cap.read()
if ret :
cv2.imshow(“Feed”, img)

k = waitkey(100)
if k == 27 :
Break
cap.release()
cv2.destroyAllWindows()
7
End Section - 4
Any Questions ???

You might also like