Abnormal interpretation
When using OpenCV to write code, there will be a valueerror: all the input arrays must have the same number of dimensions error
The error is a value error. For example, the following code will report an error
import cv2 as cv
import numpy as np
# Read the grayscale image
image1 = cv.imread("11.jpg", 0)
# Read the color image
image2 = cv.imread("11.jpg")
# Error location
image = np.hstack((image1, image2))
cv.imshow("img", image)
cv.waitKey()
The reason for this bug is that [image dimensions are different], and the influence functions are NP. Hstack ((M1, M2)) , NP. Column_ stack((m1,m2)),np.concatenate([m1, m2])
Exception resolution
Modify the image dimension, check the different positions of the image dimension, and adjust it
The specific code is different, we can adjust it by ourselves
Appendix
This series of articles is only for recording the bugs encountered in the process of Python daily development and providing them to students as reference data and solutions. It belongs to the recording blog, and readers who are destined to see it hope to solve your problems
Error prompt template can be compared with your error
Traceback (most recent call last):
File "e:/crawl100/opencv_ppt/error.py", line 10, in <module>
image = np.hstack((image1, image2)).toarray()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\numpy\core\shape_base.py", line 340, in hstack
return _nx.concatenate(arrs, 1)
ValueError: all the input arrays must have same number of dimensions