received the following error for my code:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[6], line 3
1 image = cv.imread('image.jpeg')
2 image = cv.cvtColor(image, cv.COLOR_RGB2GRAY)
----> 3 HarrisCornerDetection(image)
Cell In[5], line 11, in HarrisCornerDetection(image)
8 plt.subplot(1,2,1),plt.imshow(image)
9 plt.title('Original Image')
---> 11 image[dst > 0.01 * dst.max()]=[0, 0, 255]
12 plt.subplot(1,2,2),plt.imshow(dst_norm_scaled)
13 plt.title('Edges')
ValueError: NumPy boolean array indexing assignment cannot assign 3 input values to the 4273 output values where the mask is true
the code used is:
import glob
import cv2 as cv
import numpy as np
import matplotlib.pyplot as plt
def HarrisCornerDetection(image):
image = np.float32(image)
dst = cv.cornerHarris(image, 2, 3, 0.04)
dst = cv.dilate(dst, None)
dst = np.float32(dst)
plt.figure(figsize=(10, 10))
plt.subplot(1,2,1),plt.imshow(image)
plt.title('Original Image')
image[dst > 0.01 * dst.max()]=[0, 0, 255]
plt.subplot(1,2,2),plt.imshow(dst_norm_scaled)
plt.title('Corners')
image = cv.imread('image.jpeg')
image = cv.resize(image, (244, 244))
image = cv.cvtColor(image, cv.COLOR_RGB2GRAY)
HarrisCornerDetection(image)
I have been trying to implement Harris Corner detection using python-opencv and on running the code I received the error mentioned above. The image used has a size of (244,244) and the length of the image array in 244.
The expected result was to get corner detected in the image. Removing line 17 form the code; i.e., image[dst > 0.01 * dst.max()]=[0, 0, 255]
. The output for implementing the above solution is