我正在尝试从此URL执行代码.但是,我开始收到此错误:
des = np.array(des,np.float32).reshape((1,128))
ValueError: total size of new array must be unchanged
Run Code Online (Sandbox Code Playgroud)
我没有做过任何重大改变.但我会粘贴我所做的:
import scipy as sp
import numpy as np
import cv2
# Load the images
img =cv2.imread("image1.png")
# Convert them to grayscale
imgg =cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
# SURF extraction
surf = cv2.FeatureDetector_create("SURF")
surfDescriptorExtractor = cv2.DescriptorExtractor_create("SURF")
kp = surf.detect(imgg)
kp, descritors = surfDescriptorExtractor.compute(imgg,kp)
# Setting up samples and responses for kNN
samples = np.array(descritors)
responses = np.arange(len(kp),dtype = np.float32)
# kNN training
knn = cv2.KNearest()
knn.train(samples,responses)
modelImages = …
Run Code Online (Sandbox Code Playgroud) 我编写了一个代码,用于存储文本文件中出现的单词并将其存储到字典中:
class callDict(object):
def __init__(self):
self.invertedIndex = {}
Run Code Online (Sandbox Code Playgroud)
然后我写了一个方法
def invertedIndex(self):
print self.invertedIndex.items()
Run Code Online (Sandbox Code Playgroud)
这就是我打电话的方式:
if __name__ == "__main__":
c = callDict()
c.invertedIndex()
Run Code Online (Sandbox Code Playgroud)
但它给了我错误:
Traceback (most recent call last):
File "E\Project\xyz.py", line 56, in <module>
c.invertedIndex()
TypeError: 'dict' object is not callable
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?