Skip to content

Latest commit

Β 

History

History
64 lines (41 loc) Β· 1.74 KB

File metadata and controls

64 lines (41 loc) Β· 1.74 KB

Getting Started With OpenCV


OpenCV Basics and Image Handling

  1. Installation
  2. Mini Task Color to Grayscale
  3. Image Handling (Reading Image , Displaying , Saving , Image Dimensions, Color Channels , Grayscale Conversion)

Basic Term to have Knowledge About

  1. Image -> A 2D grid of pixels (matrix of numbers)
  2. Pixel -> Smallest unit of Image , a colored pixel will hold 3 values : Red Green Blue in range of 0 - 255
  3. Width & Height -> Horizontal total pixels & Vertical total pixels
  4. Color Channel -> A channel that stores a part of the color information for each pixel (Grayscale : 1 , RGB : 3)
  5. Image Format -> the way image is compressed and stored in our device.

Code Lines

  1. Loading Image: image = cv2.imread("path", flag)
  • image -> Variable
  • cv2.imread -> load and read image
  • path -> image path
  • flag -> default 1 = color , 0 = grayscale , -1 = unchanged
  1. Display Image : cv2.imshow("Title", image) cv2.waitKey(0) cv2.destroyAllWindows()
  • waitKey(0) -> to keep the image display on pause , 0 to keep the window till any key is
    pressed on keyboard
  • destroyAllWindows() -> to close that created window
  1. Saving Image: cv2.imwrite("output.jpg", image)
  • imwrite() -> saves the image to hard disk
  1. Image Dimension: image.shape
  • .shape -> will return height , width , and channel.
  1. GrayScale Conversion: gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
  • .cvtColor -> convert color to change color of image
  • cv2.COLOR_BGR2GRAY -> change BGR to GRAY