# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# ## OpenCV Basics

# ### Loading and displaying a single image
# **Importing the OpenCV library**
#
# **Loading the image into a variable**
#
# **Displaying the image through a window**

#Import OpenCV library
import cv2

#Read and load the image to img variable
img = cv2.imread('5X5_empty_grid.png')

#Resizing the image to required ratio
resize = cv2.resize(img, (240, 240)) 

#Show the image through the window
cv2.imshow("Output" , resize)
#Image stays on the window until a key on the keyboard is pressed
cv2.waitKey(0)

# ### Loading and displaying multiple images
# **Importing the OpenCV library and the numpy library**
#
# **Loading the images into  variables**
#
# **Concatenate images both horizontally and vertically**
#
# **Displaying concatenated images through a single window**

#Import OpenCV library
import cv2
#Import numpy library
import numpy as np

#Read and load the first image to img1 variable
img1 = cv2.imread('5X5_empty_grid.png')
#Read and load the second image to img2 variable
img2 = cv2.imread('5X5_colored_grid.png')

#Resize both the images to the required ratio
resize1 = cv2.resize(img1 , (240, 240)) 
resize2 = cv2.resize(img2 , (240, 240)) 

#Concatanate image horizontally
hori_concatenated = np.concatenate((resize1,resize2),axis=1)
#Concatanate image vertically
verti_concatenated = np.concatenate((resize1,resize2),axis=0)

#Display concatenated images
cv2.imshow('Horizontally_Concatenated' , hori_concatenated)
cv2.imshow('Vertically_Concatenated' , verti_concatenated)
cv2.waitKey(0)



StarcoderdataJupyterScriptsDedupFiltered