Skip to content

Ishaq0385/Computer-Visions-openCV-with-Python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

This repository includes computer vision openCV in python Starting from basics

Import opencv:

import cv2 as cv

1- chap1.py & chap2.py:

Reading and displaying an image in a window and Also resizing a window

  • code:
    import cv2 as cv
    #resizing the image
    img = cv.imread("resources/img1.jpeg")
    img1 = cv.resize(img,(400,300))
    cv.imshow("first image", img)
    cv.imshow("first image", img1)
    cv.waitKey(0)
    cv.destroyWindow()*

3- Chap3.py:

Converting image into gray scale

  • code:
    gray_img = cv.cvtColor(img, cv.COLOR_BGR2GRAY)*

c1

4- chap4.py:

converting image into black and white image

  • code:
    import cv2 as cv
    #resizing the image
    img = cv.imread("resources/img1.jpeg")
    img1 = cv.resize(img,(400,300))
    cv.imshow("first image", img)
    cv.imshow("first image", img1)
    cv.waitKey(0)
    cv.destroyWindow()*

c2

5- chap5.py:

writing an image/ storing and image into a folder

  • code:
    import cv2 as cv
    from cv2 import imwrite
    img = cv.imread("resources/img1.jpeg")
    img = cv.resize(img,(400,300))
    gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
    imwrite('resources/image_gray.png', gray)
    cv.waitKey(0)
    cv.destroyWindow()*

c3

6- chap6.py:

reading video from a folder and display in window

  • code:
    import cv2 as cv
    cap = cv.VideoCapture('resources/video.mp4')


    #indicator(are we reading video or not)
    if (cap.isOpened() == False):
    print("ERROR IN READING VIDEO")
    #reading and playing video
    while(cap.isOpened()):
    ret,frame = cap.read()
    if ret == True:
    cv.imshow("video", frame)
    #quiting form window by pressing 'q'
    if cv.waitKey(1) & 0xFF == ord('q'):
    break
    else:
    break
    cap.release()
    cv.destroyAllWindows()*

7- chap7.py:

Converting video into gray scale

  • code:
    import cv2 as cv
    cap = cv.VideoCapture('resources/video.mp4')
    while(True):
    ret, frame = cap.read()
    grayframe = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
    #(thresh, binary) = cv.threshold(gray, 127, 255, cv.THRESH_BINARY)
    if ret == True:
    cv.imshow("video", grayframe)
    #quiting form window by pressing 'q'
    if cv.waitKey(1) & 0xFF == ord('q'):
    break
    else:
    break
    cap.release()
    cv.destroyAllWindows()*

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages