Joining Multiple Images To Display Using Open CV Python With Source Code

Introduction :

Joining Multiple Images to Display is a very helpful feature . We will make this by using Open CV , A Powerful Computer vision Library . Open CV provides various tools to combine multiple images . Joining of Multiple Images is allows for a more efficient and organized presentation . This is useful for those , who presenting image processing workflows or debugging . Open cv provides user to join images in any format like horizontally or vertically or grid format , etc . Understanding the joining images using Open CV is a valuable skills , especially for those who develop the app involves image processing workflows . Overall mastering this technique in Open CV improves the efficiency of image processing workflows and enhance the visual experience of developers .

Language And Interface :-

Joining Multiple Images To Display Using Python , A Versatile Programming Language With Source Code .

Required Modules Or Packages :-

You Need The Packages List Given Below :-
1. cv2 :- It is a library to use in Computer Vision task. You will get basic image processing tools while using cv2 for example, Image Reading and Writing .
2. Numpy :- It is a core library for numerical computation in python and it can handle Large array of numbers .

How To Run The Code :-

Step 1 . First , You Download and Install Visual Studio Code or VS Code In your PC or Laptop by VS Code Official Website .
Step 2 . Now Open CMD As Administrator and install the above packages using pip .
Step 3 . Now Open Visual Studio Code .
Step 4.  Now Make The file named as joining_multiple_images.py .
Step 5 . Now Copy And Paste The Code from the Link Given Below ⬇️
Step 6 . After pasting The code , Save This & Click On Run Button .
Step 7 . Now You will See The Output .

Code Explanation :-

This Python code is used to Joining the multiple images to Display .

Step-by-Step Guide Given Below :-
Imports :
cv2 :- It is a library to use in Computer Vision task. You will get basic image processing tools while using cv2 for example, Image Reading and Writing .

Numpy :- It is a core library for numerical computation in python and it can handle Large array of numbers.

The stackimages Function :
				
					def stackImages(imgArray, scale, labels=[]):
This function takes an array of images (imgArray) .
				
			
Resizing and Converting the Images :
				
					sizeW = imgArray[0][0].shape[1]
sizeH = imgArray[0][0].shape[0]

rows = len(imgArray)
cols = len(imgArray[0])
rowsAvailable = isinstance(imgArray[0], list)
width = imgArray[0][0].shape[1]
height = imgArray[0][0].shape[0]
				
			

This code determines the width and height of images . Rows and columns are used to
identify the numbers of images in array .

Image Stacking :

If array is a 2D list :

				
					if rowsAvailable:
    for x in range(0, rows):
        for y in range(0, cols):
            imgArray[x][y] = cv2.resize(imgArray[x][y], (sizeW, sizeH), None, scale, scale)
            if len(imgArray[x][y].shape) == 2:
                imgArray[x][y] = cv2.cvtColor(imgArray[x][y], cv2.COLOR_GRAY2BGR)
    imageBlank = np.zeros((height, width, 3), np.uint8)
    hor = [imageBlank] * rows
    hor_con = [imageBlank] * rows
    for x in range(0, rows):
        hor[x] = np.hstack(imgArray[x])
        hor_con[x] = np.concatenate(imgArray[x])
    ver = np.vstack(hor)
    ver_con = np.concatenate(hor)

				
			

This code is used to resizing and Converting the Images into BGR Grayscale.

If array is a 1D List :

				
					else:
for x in range(0, rows):

imgArray[x] = cv2.resize(imgArray[x], (sizeW, sizeH), None, scale, scale)
if len(imgArray[x].shape) == 2:
imgArray[x] = cv2.cvtColor(imgArray[x], cv2.COLOR_GRAY2BGR)
hor = np.hstack(imgArray)
hor_con = np.concatenate(imgArray)
ver = hor
				
			
Displaying the stacked images :
				
					while True:
success, img = cap.read()
kernel = np.ones((5,5), np.uint8)
imgGray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
imgBlur = cv2.GaussianBlur(imgGray, (7, 7), 0)
imgCanny = cv2.Canny(imgBlur, 100, 200)
imgDilation = cv2.dilate(imgCanny, kernel, iterations=2)
imgEroded = cv2.erode(imgDilation, kernel, iterations=2)

StackedImages = stackImages(([img, imgGray, imgBlur], [imgCanny, imgDilation,
imgEroded]), 0.6)
cv2.imshow("Stacked Images", StackedImages)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
				
			

This code captures the frames of images from the webcam and processes them . The images are converted into a grayscale , blurred. These processed images are stacked by using stack images Function .

Source Code :-

Your download is starting now...

Output :-

Find More Projects

Drawing Ganesha Using Python Turtle Graphics[Drawing Ganapati Using Python] Introduction In this blog post, we will learn how to draw Lord Ganesha …

Contact Management System in Python with a Graphical User Interface (GUI) Introduction: The Contact Management System is a Python-based application designed to …

KBC Game using Python with Source Code Introduction : Welcome to this blog post on building a “Kaun Banega Crorepati” (KBC) game …

Basic Logging System in C++ With Source Code Introduction : It is one of the most important practices in software development. Logging …

Snake Game Using C++ With Source Code Introduction : The Snake Game is one of the most well-known arcade games, having its …

C++ Hotel Management System With Source Code Introduction : It is very important to manage the hotels effectively to avail better customer …

Get Huge Discounts
More Python Projects

Download From Telegram