Skip to content

tarunaditya91/open-cv

Repository files navigation

open-cv

image

Drawing

image

contours

image

colorspaces

image

blurring

image

resizing

crop

Chapter 1 read IMAGE-VIDEO-WEBCAM

IMAGE

to read an image first we have to import cv2 package which has a function imread that helps us to read an image then you have to place the image

to show the image you have to use the function imshow() this function has two attributes 1-> The first one is the name of the image 2-> One is the image variable

to delay the image time we have to use waitkey() function if we add 0 it i infinitely if we add 1 one millisecond delay

VIDEO

now first we have to import cv2 again then we use function VideoCapture()

then we have to read it frame by frame

cv2.imshow("img",img) cv2.waitKey(0)

img2=cv2.VideoCapture('sample.mp4')

while True: img,suu=img2.read() cv2.imshow('v',suu) if cv2.waitKey(1) & 0xFF==ord('q'): break

A webcam is also similar to a video cam just replace it with video location with the webcam number and we can also re-size it using this

img2.set(3,340)this is 3->width,340->width size img2.set(4,380)this is 4->height,380->height size

we can also change the brightness by using

img2.set(10,100) 10->is id for brightness

Basic Functions

Now first thing we will do that to convert it into gray scale

first you have to import cv2

and use a function cvtColor() function .for creating a image we use rgb but in cv2 it is bgr to covert it into gray we use the following code

import cv2

img=cv2.imread('images.jpg')

imgGray=cv2.cvtColor(img,cv2.COLOR_BGRA2GRAY) imgblur=cv2.GaussianBlur(imgGray,(7,7),0)

cv2.imshow('imgGray',imgGray) cv2.imshow('imgblur',imgblur) cv2.waitKey(0)

image

Next we work on canny edge dettection

imgcanny=cv2.Canny(img,100,100)

image

to reduse the edges change the threshold values

imgcanny=cv2.Canny(img,150,250) you can seethe diffrence image

Dilation -> some times the edges are not connected we can increase the thickness useing dilation

KERNAL IS NOTING BUT A MATRIX VALUE WHICH WE HAV TO EEFINE MATRIX VALUE AND SIZE FOR THIS WE NEED THE MATRIX VALUE AS ONE

For doing this we need numpy which we have to import it

np.uint8 refers to an 8-bit unsigned integer data type in the NumPy library in Python. It stands for "NumPy unsigned integer 8-bit". This data type can represent integers ranging from 0 to 255. It is commonly used for storing image data, especially in grayscale images, where pixel values typically range from 0 (black) to 255 (white).

Now we have to create s Kernal =np.onse((5,5),np.unit8)

image after applying Dialation image

The next function is Erode

Erode is the reverse process of Dialation

imgEroded=cv2.erode(imgDialation,kernal,iterations=1)

image

chapter 3

Resizeing_and_cropping

opencv convention

imgresize=cv2.resize(img(200,300)) first width and then height

image

in open cv fuction width will come first then height

for croping we wont need cv2 we cann do it useing matrix image

imgcrop=img[0:300,50:100]

Chapter 4

SHAPES_AND_TEXT

cv2.line(img,(0,0),(300,300),(0,255,0),3) for drawing a line

image

cv2.rectangle(imgr,(0,0),(200,200),(0,0,255),3) for drawing rectangle

image

cv2.rectangle(imgr,(0,0),(200,200),(0,0,255),cv2.FILLED)

image

cv2.circle(imgr,(150,150),8,(255,0,0),cv2.FILLED)

image

cv2.putText(imgr,"opencv text",(200,100),cv2.FONT_HERSHEY_PLAIN,1,(0,150,0),1)

image

chapter 5

WARP_PERSPECTIVE

image

cHAPTER 6

JOINING_IMAGES

import numpy as np import cv2

img=cv2.imread('images.jpg')

imghor=np.hstack((img,img)) imgver=np.vstack((img,img))

cv2.imshow("horizontal",imghor) cv2.imshow("vertical",imgver) cv2.waitKey(0)

image

image

#Chapter 7 COLOR_DETECTION

imghsv=cv2.cvtColor(img,cv2.COLOR_BGR2HSV)

image

We are creating a trackbar

first, we have to create a named window then we have to resize the window then from cv2 use the function createTrackbar first enter the value you want then the window name starting and ending, then a function

image

image

image

Chapter 8

CONTOURS/SHAPE DETECTION

image

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages