As the title says. I wrote an article because there was no page where the error message and the cause were simply linked.
If you want to concatenate one image with another (although the same image is fine), it is convenient to use OpenCV hconcate
or vconcat
. For example, when doing hconat
(horizontal connection), it is naturally necessary to align the number of vertical pixels with each other, but sometimes even after aligning it, an error may occur for some reason.
Like this.
python
combined_image = cv2.hconcat([left_image,right_image])
output
Exception has occurred: error
OpenCV(4.1.2) C:\projects\opencv-python\opencv\modules\core\src\matrix_operations.cpp:68: error: (-215:Assertion failed) src[i].dims <= 2 && src[i].rows == src[0].rows && src[i].type() == src[0].type() in function 'cv::hconcat'
It seems that there is no size for matrix calculation. Did you make a mistake in resizing? Debug with print
.
print(left_image.shape)
print(right_image.shape)
output
(256, 256)
(256, 256)
Isn't it hot!
In conclusion, it's because ** the data types don't match **. Let's match using numpy.
left_image = np.array(left_image)
left_image = out.astype('int32')
right_image = np.array(right_image)
right_image = canny.astype('int32')
Now you can connect.
Other common errors.
Let's resize. You can do it with cv2.resize (img, (x, y))
.
It's rudimentary, but it tends to be. With ʻimread, even if you make a mistake in specifying the path, no error will occur and
Nonewill be returned. After
print, check if it is
None`.
This is also common. The gray image also needs to be a color image on the data. You can do it with cv2.cvtColor (img, cv2.COLOR_GRAY2BGR)
.
Recommended Posts