Skip to content

Latest commit

 

History

History
116 lines (69 loc) · 8.67 KB

File metadata and controls

116 lines (69 loc) · 8.67 KB

Introduction to Computer Vision

Computer Vision na area wey dey try make computer sabi wetin dey happen for digital pictures. Dis definition dey wide well-well, because understanding fit mean plenty things, like to find object for picture (object detection), sabi wetin dey happen (event detection), describe picture with text, or even build scene for 3D. E still get special work wey concern human pictures: age and emotion estimation, face detection and identification, and 3D pose estimation, among others.

One of di simplest work for computer vision na image classification.

People dey see computer vision as one part of AI. Nowadays, most of di work for computer vision dey use neural networks. We go learn more about di special type of neural networks wey dem dey use for computer vision, convolutional neural networks, for dis section.

But before you go pass image enter neural network, e go make sense to use some algorithmic techniques to make di image better.

Plenty Python libraries dey wey fit help for image processing:

  • imageio fit help you read/write different image formats. E still support ffmpeg, wey be tool wey fit change video frames to images.
  • Pillow (dem dey call am PIL too) get more power, and e fit do some image manipulation like morphing, palette adjustments, and more.
  • OpenCV na strong image processing library wey dem write with C++, and e don turn di de facto standard for image processing. E get Python interface wey dey easy to use.
  • dlib na C++ library wey get plenty machine learning algorithms, including some Computer Vision algorithms. E get Python interface too, and e fit help for hard work like face and facial landmark detection.

OpenCV

OpenCV na di de facto standard for image processing. E get plenty useful algorithms wey dem write with C++. You fit use OpenCV with Python too.

If you wan learn OpenCV well, check dis Learn OpenCV course. For our curriculum, we no dey focus to learn OpenCV fully, but to show you some examples of how e fit work and wetin e fit do.

Loading Images

Images for Python dey easy to represent as NumPy arrays. For example, grayscale images wey get size of 320x200 pixels go dey as 200x320 array, and color images wey get di same size go get shape of 200x320x3 (for 3 color channels). To load image, you fit use dis code:

import cv2
import matplotlib.pyplot as plt

im = cv2.imread('image.jpeg')
plt.imshow(im)

Normally, OpenCV dey use BGR (Blue-Green-Red) encoding for color images, but di rest Python tools dey use RGB (Red-Green-Blue). To make di image look correct, you go need change am to RGB color space, either by swapping dimensions for di NumPy array, or by using OpenCV function:

im = cv2.cvtColor(im,cv2.COLOR_BGR2RGB)

Di same cvtColor function fit help you do other color space transformations like changing image to grayscale or to HSV (Hue-Saturation-Value) color space.

You fit still use OpenCV to load video frame-by-frame - example dey for di exercise OpenCV Notebook.

Image Processing

Before you go give image to neural network, e good to do some pre-processing steps. OpenCV fit do plenty things, like:

  • Resizing di image with im = cv2.resize(im, (320,200),interpolation=cv2.INTER_LANCZOS)
  • Blurring di image with im = cv2.medianBlur(im,3) or im = cv2.GaussianBlur(im, (3,3), 0)
  • To change di brightness and contrast of di image, you fit use NumPy array manipulations, as dem explain for dis Stackoverflow note.
  • Use thresholding by calling cv2.threshold/cv2.adaptiveThreshold functions, wey dey better pass to adjust brightness or contrast.
  • Do different transformations for di image:
    • Affine transformations fit help you if you wan combine rotation, resizing and skewing for di image and you sabi di source and destination location of three points for di image. Affine transformations dey keep parallel lines parallel.
    • Perspective transformations fit help you if you sabi di source and destination positions of 4 points for di image. For example, if you snap picture of rectangular document with smartphone camera from angle, and you wan make di document look rectangular for di image.
  • Sabi movement inside di image by using optical flow.

Examples of using Computer Vision

For our OpenCV Notebook, we show some examples of how computer vision fit help do specific work:

  • Pre-processing photograph of Braille book. We dey focus on how we fit use thresholding, feature detection, perspective transformation and NumPy manipulations to separate Braille symbols for classification by neural network.
Braille Image Braille Image Pre-processed Braille Symbols

Image from OpenCV.ipynb

  • Detecting motion for video using frame difference. If camera no dey move, di frames from di camera feed suppose dey similar. Since frames dey as arrays, if you subtract di arrays for two frames wey follow each other, you go get di pixel difference, wey suppose dey small for static frames, and go big if motion dey for di image.

Image of video frames and frame differences

Image from OpenCV.ipynb

  • Detecting motion using Optical Flow. Optical flow dey help us sabi how individual pixels for video frames dey move. E get two types of optical flow:

    • Dense Optical Flow dey calculate vector field wey show where each pixel dey move go.
    • Sparse Optical Flow dey use some special features for di image (like edges), and e dey build their movement from frame to frame.

Image of Optical Flow

Image from OpenCV.ipynb

✍️ Example Notebooks: OpenCV try OpenCV in Action

Make we try experiment with OpenCV by checking OpenCV Notebook

Conclusion

Sometimes, work wey dey hard like movement detection or fingertip detection fit dey solved only with computer vision. So e good to sabi di basic techniques for computer vision, and wetin libraries like OpenCV fit do.

🚀 Challenge

Watch dis video from di AI show to learn about di Cortic Tigers project and how dem build block-based solution to make computer vision work easy via robot. Do research on other projects like dis wey dey help new learners enter di field.

Review & Self Study

Read more about optical flow for dis better tutorial.

For dis lab, you go take video wey get simple gestures, and your work na to find up/down/left/right movements using optical flow.

Palm Movement Frame


Disclaimer:
Dis document don use AI translation service Co-op Translator take translate am. Even though we dey try make e accurate, abeg sabi say automated translations fit get mistake or no correct well. Di original document for di native language na di main correct source. For important information, e better make una use professional human translation. We no go fit take blame for any misunderstanding or wrong interpretation wey fit happen because of dis translation.