Trying to count number of objects in .npy image file
import numpy as np
img=np.load('A03_00Ac_Object Identities.npy')
from matplotlib import pyplot as plt
plt.imshow(img,cmap='gray')
import cv2
plt.imshow(img, cmap='gray')
blur = cv2.GaussianBlur(gray, (11, 11), 0)
canny = cv2.Canny(blur, 30, 40, 3)
plt.imshow(canny, cmap='gray')
dilated = cv2.dilate(canny, (1, 1), iterations=0)
plt.imshow(dilated, cmap='gray')
(cnt, hierarchy) = cv2.findContours(
dilated.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
cv2.drawContours(rgb, cnt, -1, (0, 255, 0), 2)
plt.imshow(rgb)
print("No of circles: ", len(cnt))
Received Error
Traceback (most recent call last)
Input In [32], in <cell line: 1>()
----> 1 blur = cv2.GaussianBlur(img, (11, 11), 0)
error: OpenCV(4.5.4) :-1: error: (-5:Bad argument) in function 'GaussianBlur'
> Overload resolution failed:
> - src data type = 8 is not supported
> - Expected Ptr<cv::UMat> for argument 'src'
Please help me on this...Opencv Ref: How to count objects in image using python?