Joining Multiple Images to Display [5] | OpenCV Python Tutorials for Beginners

preview_player
Показать описание
In this video, we look at how images and webcam feed can be joined together. This can be done using Matplotlib but it does not provide a decent frame rate for webcams. Therefore we use the NumPy library to join images together. Moreover to simply this process a function is created that will help images with just 1 line of code.

🚀🚀 My Urdu/Hindi AI YouTube Channel 🚀🚀

Code & Complete Course:

Premium Courses:
✔️ Computer Vision Game Development Course:
✔️ Computer Vision with Arduino Course:
✔️ Advanced Drone Programming Course:
✔️ Learn to Build Computer Vision Mobile Apps:
✔️ Jetson Nano Premium Course:

⚙️⚙️⚙️—-My Gear — ⚙️⚙️⚙️

Follow Me:

#ComputerVision
#OpenCV
#CVZone
Рекомендации по теме
Комментарии
Автор

For anyone looking for this version of the function here it is:

def stackImages(scale, imgArray):
rows = len(imgArray)
cols = len(imgArray[0])
rowsAvailable = isinstance(imgArray[0], list)
width = imgArray[0][0].shape[1]
height = imgArray[0][0].shape[0]
if rowsAvailable:
for x in range ( 0, rows):
for y in range(0, cols):
if imgArray[x][y].shape[:2] == imgArray[0][0].shape [:2]:
imgArray[x][y] = cv2.resize(imgArray[x][y], (0, 0), None, scale, scale)
else:
imgArray[x][y] = cv2.resize(imgArray[x][y], (imgArray[0][0].shape[1], imgArray[0][0].shape[0]), 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])
ver = np.vstack(hor)
else:
for x in range(0, rows):
if imgArray[x].shape[:2] == imgArray[0].shape[:2]:
imgArray[x] = cv2.resize(imgArray[x], (0, 0), None, scale, scale)
else:
imgArray[x] = cv2.resize(imgArray[x], (imgArray[0].shape[1], imgArray[0].shape[0]), None, scale, scale)
if len(imgArray[x].shape) == 2: imgArray[x] = cv2.cvtColor(imgArray[x], cv2.COLOR_GRAY2BGR)
hor = np.hstack(imgArray)
ver = hor
return ver

sahoromiyaki
Автор

dude your channel is GOLD!! thank you so much!

sinozino
Автор

wooo! I just realized that you have steam! :D ... gamer and programming teacher = AWESOME

GJ-iykj
Автор

"FIVE HUNDRED DIFFERENT IMAGES... It really heated up my PC but still it works" :) Thanks for the tutorial Murtaza.

tkinter
Автор

I love your tutorial. It would be great if you can create tutorial for the math topics which is used in open Cv?

samadams
Автор

awesome, please tell me how to get the code of this function.

AhmedAli-jjcq
Автор

videos are so expressive....can anyone share the exact function code...because 6:17 is different in Github.

maYYidtS
Автор

You can use this function which is same as his but is simple to understand.

def stackImage(scale, images):
width = images[0][0].shape[1]
height = images[0][0].shape[0]
ver = None
for img in images:
hor = None
for i in img:
if i.shape[:2] == images[0][0].shape[:2]:
i = cv2.resize(i, (0, 0), None, scale, scale)
else:
i = cv2.resize(i, (width, height), None, scale, scale)

if len(i.shape) == 2:
i = cv2.cvtColor(i, cv2.COLOR_GRAY2BGR)

if hor is not None:
hor = np.hstack((hor, i))
else:
hor = i
if ver is not None:
ver = np.vstack((ver, hor))
else:
ver = hor
return ver

yubrajupadhayaplays
Автор

Hi, what if we wanted to overlap all the photos, lets say I have different functions drawing rectangles around different objects, but then I wanted to show everything

eljangoolak
Автор

Hi, how can I fix (ValueError: all the input arrays must have same number of dimensions, but the array at index 0 has 3 dimension(s) and the array at index 2 has 2 dimension(s))

moustafamahmoud
Автор

Thanks... Scaling not working in video stacking then i make (sizeW, sizeH) to (0, 0) in stacking function. is it ok????

irfan
Автор

Hello my friend, I do not found the definition by you for multi images.
please help me

robot
Автор

I have some problem when I tried the code. This is the following problem:
cv2.imshow('Stacked Images', StackedImages)
TypeError: 'tuple' object is not callable
[ WARN:1] terminating async callback

Could you help me how to fix the tuple object is not callable ?
As your information, I used Windows 10, python 3.7...

risnandar
Автор

This tutorial was great, hope u'll create more video ~

maihongngoc
Автор

what if i get this error error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'

rzubruweczka
Автор

Sir, from where to get the stacking function?

koraksengupta
Автор

Can you apply this technic for webcam source? For example, there are two camera sources in one horizontal frame or four sources in one square frame... I have two webcam sources in different frames separately at the same time. I try to connect them in one frame or else I try to adjust position of the frames via mouse again and again, it is boring. Thanks again.

tkinter
Автор

How do we get access to the code you wrote that does the stacking?

relationshipdestiny
Автор

sit there is no source code in your channel link
we have to sighin the go

funlearn
Автор

Amazing tutorials, gj friend.

I have a question: "When I try to add more images, I still get x6 joint display; instead of 12 joints display. Do you know where do I do wrong"? thank you.

StackedImages = myUtlis.stackImages(([img, imgGray, imgBlur], # add more images horizontally inside of the array
[imgCanny, imgDilation, imgEroded],
[imgCanny, imgDilation, imgEroded],
[imgCanny, imgDilation, imgEroded]), 0.3) # Add more images vertically, and 0.3 is the scale

aykutsirma