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

Build a Quiz Game Using HTML CSS and JavaScript Introduction Hello coders, you might have played various games, but were you aware …

Emoji Catcher Game Using HTML CSS and JavaScript Introduction Hello Coders, Welcome to another new blog. In this article we’ve made a …

Typing Challenge Using HTML CSS and JavaScript Introduction Hello friends, all you developer friends are welcome to our new project. If you …

Breakout Game Using HTML CSS and JavaScript With Source Code Introduction Hello friends, welcome to today’s new blog post. All of you …

Digital and Analog Clock using HTML CSS and JavaScript Introduction : This project is a digital clock and stopwatch system, which allows …

Coffee Shop Website using HTML, CSS & JavaScript Introduction : This project is a website for coffee house business. It uses HTML …

Get Huge Discounts
More Python Projects

All Coding Handwritten Notes