Core Operations
Function |
Purpose |
---|---|
imread(image_path, flag) | This method is used to read an image from its path |
imshow(window_name, image) | It is used to show the image in the window. |
imwrite(filename, image) | This method is used to write or save an image using OpenCV. |
Reading Images
You can read an image in Python using OpenCV’s cv.2imread() method. By default, OpenCV stores colored images in BGR(Blue, Green, and Red) format.
img = cv2.imread(image_path, flag)
The types of flags are described below:
Image Reading Modes |
Description |
---|---|
cv2.IMREAD_COLOR | Read colored images |
cv2.IMREAD_GRAYSCALE | Read Grayscale images |
cv2.IMREAD_UNCHANGED | Read images with alpha channel |
Showing Images
The cv2.imshow() method is used to display an image in a window.
cv2.imshow(window_name, image)
Image Cropping
Cropping is the removal of unwanted outer areas from an image.
cropped_img = img[100:300, 100:300]
Saving an Image
The cv2.imwrite() method is used to save an image to any storage device. This will save the image according to the specified format in the current working directory.
cv2.imwrite(filename, image)
Python OpenCV Cheat Sheet
The Python OpenCV Cheat Sheet is your complete guide to mastering computer vision and image processing using Python. It’s designed to be your trusty companion, helping you quickly understand the important ideas, functions, and techniques in the OpenCV library. Whether you’re an experienced developer needing a quick reminder or a newcomer excited to start, this cheat sheet has got you covered.
In this article, we’ve gathered all the vital OpenCV concepts and explained them in simple terms. We’ve also provided practical examples to make things even clearer. You’ll learn everything from how to handle images to using advanced filters, spotting objects, and even exploring facial recognition. It’s all here to help you on your journey of discovering the amazing world of computer vision.
Table of Content
- Python OpenCV Cheat Sheet 2023
- Core Operations
- Drawing Shapes and Text on Images
- Arithmetic Operations on Images
- Morphological Operations on Images
- Geometric Transformations on Image
- Image Thresholding
- Edge/Line Detection (Features)
- Image Pyramids
- Changing the Colorspace of Images
- Smoothing Images
- Working With Videos
- Camera Calibration and 3D Reconstruction