I am currently trying to display an image in tkinter and identify its body using mediapipe. I use Opencv, mediapipe and tkinter for this. I have also implemented something for this, but unfortunately I am not getting anywhere.
The type of the first argument of mpDraw.draw_landmarks should be NumPy array, but you are passing and object of type PhotoImage.
You may replace landmarks(photo, results) with:
landmarks(image, results)
The following code:
photo = ImageTk.PhotoImage(image=Image.fromarray(image))
landmarks(photo, results)
Converts image from NumPy array to PhotoImage object, and passes the object as argument to landmarks method (that passes it to mpDraw.draw_landmarks).
Take a look at the error message:
if image.shape[2] != RGB_CHANNELS:
AttributeError: 'PhotoImage' object has no attribute 'shape'
That means the image type is 'PhotoImage'.
That also implies that image must have a 'shape' attribute, and we some experience we know that NumPy arrays have a 'shape' attribute.
You may also look at drawing_utils.py.
Args:
image: A three channel RGB image represented as numpy ndarray.
Note:
It's hard to tell if there are other errors (it's hard to follow the code).
My answer address only the posted error messgae.
Related
I am implementing unscented kalman filter and getting this error "numpy.ndarray object is not callable" for the non-linear function 'g' in the prediction step.
enter image description here
I have also attached my code where I got this error. Any assistance would be highly appreciated. Thanks!
Just like the error message says, gx is a numpy array:
gx = np.array([g_E, g_R])
But you are trying to call it as if it were a function:
self.sigmas_x[:,i] = gx(self.sigmas[:,i],dt, u)
Hence the error.
I am dealing with error
"AttributeError: 'numpy.ndarray' object has no attribute 'nipy_spectral'"
while running silhouette analysis.
The original code was taken from here. I have added the line that shows the error:
color = cm.nipy_spectral(float(i) / n_clusters)
The problem was that you were assigning cm to some other array. Correct way is not to assign cm to any other array or change the code to
matplotlib.cm.nipy_spectral(float(i) / n_clusters)
Change it at all the places where cm is used.
Here is the snippet of the input data and the result of running print(type(cm)).
Screenshot
I'm using Python to work with networkx and draw some graphs.
I ran into a problem raising:
TypeError: 'dict' object is not callable
on this line of code:
set_node_color(num, list(Graph.node()))
I searched to find that this error is raised when I'm using a variable name dict.
The problem is, I'm not using any variables with the name dict, nor am I using any dictionary types anywhere in the code.
In case it's necessary, printing the type of Graph gives <class 'networkx.classes.digraph.Digraph'>.
I also tried printing the type for Graph.node() only to receive the same error, telling me 'dict' object is not callable.
So I suspect Graph.node() to be a dict type variable, but using (Graph.node()).items() raises the same TypeError.
Any help or advices would be nice. Thanks.
Maybe Graph.node is a dict object, so Graph.node() is not callable.
I'm trying to extract the descriptors using BRISK, as follows:
cv2.DescriptorExtractor_create('BRISK')
But, getting the following error:
AttributeError: 'module' object has no attribute 'DescriptorExtractor_create'
Why is that? How can I fix the issue?
Thanks.
Using the help command will clear the air on using the BRISK feature descriptor. To use it type the following in the terminal console:
help(cv2.BRISK)
In order to obtain the descriptors, there are certain pre-requisites:
Create the BRISK object, here f is the object of class BRISK:
f = cv2.BRISK_create()
Find the keypoints for a given image img using detect() method:
keypoints = f.detect(img)
Now using the image and the keypoints you can obtain the descriptors:
descriptors = f.compute(img, keypoints)
So I have been writing a code to standardize the elements of a matrix and the function I used is as follows:
def preprocess(Data):
if stdn ==True:
st=np.empty((Data.shape[0],Data.shape[1]))
for i in xrange(0,Data.shape[0]):
st[i,0]=Data[i,0]
for i in xrange(1,Data.shape[1]):
st[:,i]=((Data[:,i]-np.min(Data[:,i]))/(np.ptp(Data[:,i])))
np.random.shuffle(st)
return st
else:
return Data
It works very well outside the class but when used inside of it it gives me this error:
AttributeError: 'tuple' object has no attribute 'shape'
Any idea on how I can fix it??
P.S. This is a KNN classification code
According to the error you posted, Data is of type tuple and there is no attribute shape defined for data. You could try casting Data when you call your preprocess function, e.g.:
preprocess(numpy.array(Data))