</>
Skip to content
Data Science lessons (39/42)

Data Science — Computer Vision

Image loading

import cv2
import matplotlib.pyplot as plt

# Load image
img = cv2.imread('image.jpg')
img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

plt.imshow(img_rgb)
plt.show()

Image processing

# Resize
img_resized = cv2.resize(img, (224, 224))

# Grayscale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

# Blur
blurred = cv2.GaussianBlur(img, (5, 5), 0)

# Edge detection
edges = cv2.Canny(gray, 100, 200)

Object detection

import tensorflow as tf

# Load pre-trained model
model = tf.keras.applications.MobileNetV2(weights='imagenet')

# Predict
predictions = model.predict(img_preprocessed)

Transfer learning

base_model = tf.keras.applications.VGG16(weights='imagenet', include_top=False)
base_model.trainable = False

model = keras.Sequential([
    base_model,
    keras.layers.GlobalAveragePooling2D(),
    keras.layers.Dense(10, activation='softmax')
])

Mini Practice

  1. Load and display images
  2. Apply filters
  3. Detect edges
  4. Use transfer learning

Up Next

Continue with Recommender Systems - Building recommendation engines.

Related Topics

Frequently Asked Questions about Computer Vision

What is Computer Vision in Data Science?

Computer Vision is a fundamental concept in Data Science. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn Computer Vision?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Computer Vision.

Why is Computer Vision important in Data Science?

Computer Vision is essential for Data Science development. Understanding this concept will help you write better code and solve real-world problems more effectively.