I have an image that I want to show using pcolormesh
but I do not really understand how this should work exactly. I have the X and corresponding Y for a certain color but if I enter a normal array as C in pcolormesh
I get an error.
My code:
# load image
img = cv2.imread('Distorted_resized_50.jpg')
img_array = np.asarray(img)
height, width, channels = img.shape
gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# create vector matrix
U, V = np.meshgrid(range(gray_img.shape[1]),
range(gray_img.shape[0]))
UV = np.vstack((U.flatten(),
V.flatten())).T
H, mask = cv2.findHomography(UV_cp, XYZ_gcp)
UV_warped = cv2.perspectiveTransform(np.array([UV]).astype(np.float32), H)
UV_warped = UV_warped[0]
UV_warped = UV_warped.astype(np.int)
X_warped = UV_warped[:,0].reshape((height, width))
Y_warped = UV_warped[:,1].reshape((height, width))
fig, axs = plt.subplots(figsize=(15,10))
axs.pcolormesh(X_warped, Y_warped, img_array)
Anybody that can help me? The explanation on the website isn't very clear to me.
It all works fine until fig, axs = plt.subplots(figsize=(15,10))
Traceback:
Traceback (most recent call last):
File "C:\Users\Yorian\Desktop\TU\Stage Shore\python_files\Rectificatie dmv foto thuis\rectify.py", line 53, in <module>
ax.pcolormesh(X_warped, Y_warped, img_array)
File "C:\Python27\lib\site-packages\matplotlib\axes.py", line 7734, in pcolormesh
X, Y, C = self._pcolorargs('pcolormesh', *args, allmatch=allmatch)
File "C:\Python27\lib\site-packages\matplotlib\axes.py", line 7350, in _pcolorargs
numRows, numCols = C.shape
ValueError: too many values to unpack