- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我想在给定目录中的所有图像中搜索冲浪,并保存它们的关键点和描述符以供将来使用。我决定使用pickle,如下所示:
#!/usr/bin/env python
import os
import pickle
import cv2
class Frame:
def __init__(self, filename):
surf = cv2.SURF(500, 4, 2, True)
self.filename = filename
self.keypoints, self.descriptors = surf.detect(cv2.imread(filename, cv2.CV_LOAD_IMAGE_GRAYSCALE), None, False)
if __name__ == '__main__':
Fdb = open('db.dat', 'wb')
base_path = "img/"
frame_base = []
for filename in os.listdir(base_path):
frame_base.append(Frame(base_path+filename))
print filename
pickle.dump(frame_base,Fdb,-1)
Fdb.close()
当我尝试执行时,出现以下错误:
File "src/pickle_test.py", line 23, in <module>
pickle.dump(frame_base,Fdb,-1)
...
pickle.PicklingError: Can't pickle <type 'cv2.KeyPoint'>: it's not the same object as cv2.KeyPoint
有谁知道,这是什么意思以及如何解决?我正在使用 Python 2.6 和 Opencv 2.3.1
非常感谢
最佳答案
问题是您不能将 cv2.KeyPoint 转储到 pickle 文件。我遇到了同样的问题,并设法通过自己序列化和反序列化关键点来解决它,然后再用 Pickle 倾倒它们。
所以用元组表示每个关键点及其描述符:
temp = (point.pt, point.size, point.angle, point.response, point.octave,
point.class_id, desc)
将所有这些点附加到一些列表中,然后用 Pickle 转储。
然后当你想再次检索数据时,用 Pickle 加载所有数据:
temp_feature = cv2.KeyPoint(x=point[0][0],y=point[0][1],_size=point[1], _angle=point[2],
_response=point[3], _octave=point[4], _class_id=point[5])
temp_descriptor = point[6]
使用上面的代码从这个数据中创建一个 cv2.KeyPoint,然后你可以使用这些点来构造一个特征列表。
我怀疑有一种更简洁的方法可以做到这一点,但上述方法对我来说效果很好(而且速度很快)。您可能需要稍微调整一下您的数据格式,因为我的功能存储在特定格式的列表中。我试图在其通用基础上使用我的想法来呈现上述内容。希望对您有所帮助。
关于python - Pickling cv2.KeyPoint 导致 PicklingError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10045363/
我想将 KeyPoint 缓存在一个 JSON 文件中,然后稍后检索它们以用于 FlannBasedMatcher。有没有办法将 KeyPoint 转换为可以存储然后从 JSON 文件中检索的字符串或
根据 OpenCV KeyPoint文档中,每个关键点都有 response 字段: float response: The response, by which the strongest keyp
根据该文档,SIFT对象可以使用以下函数来计算多个图像的描述符: virtual void compute (InputArrayOfArrays images, std::vector > &key
所以我正在使用 Java 和 OpenCV 进行图像识别,但我一直在尝试将 Arraylist 转换回 MatOfKeyPoint。 List newList = new ArrayList(poin
我正在开发一个涉及使用 Freak 的应用程序描述符,刚刚在OpenCV2.4.2版本中发布。 在documentation只出现两个函数: 类构造函数 一个令人困惑的方法selectPairs()
我想在给定目录中的所有图像中搜索冲浪,并保存它们的关键点和描述符以供将来使用。我决定使用pickle,如下所示: #!/usr/bin/env python import os import pick
我正在尝试在 SVG 上使用非线性动画速率 通过使用 keyTimes="…" 和 keyPoints="…" 属性。它似乎不起作用:动画运动尽可能是线性的。 这是测试文件 try it!
这里尝试使用 opencv 的类:SURF_GPU。 testSURFGPU.cpp: #include int main(int argc, char* argv[]) { cv::gpu
我正在尝试使用 opencv for android 的 stereouncalibratedrectify 而且我没有找到在 Java 中将 List 转换为 Mat 的方法,但是在 opencv
我有一张 50x50 的小图片。我找到 ORB 关键点: (请注意,我必须将 patchSize 的默认参数从 31 更改为 14 才能检测到一些关键点): OrbFeatureDetector d
最近一直在使用一些 OpenCV,但是我遇到了一个有趣的问题。我有一个简单的类来存储数据并将数据读取和写入文件。 这是写函数: cv::Mat descriptors; vector keypoint
我正在尝试用这个计算输入云的筛选关键点代码: #include #include #include #include #include #include #include #includ
有什么方法可以使用 Point3f 而不是 Point2f 作为 KeyPoint 参数? 在这里 OpenCV Documentation他们只提到 Point2f,但我仍然想知道是否有任何方法可以
我可以看到我们可以转换 Keypoint来自 Point通过以下方法: vector points1; KeyPoint::convert(keypoints1, points1); 如果有人可以建议
在我的代码中,我将关键点插入到 vector 中,如代码所示,谁能告诉我如何将其保存到文本文件中。 Mat object = imread("face24.bmp", CV_LOAD_IMAGE_G
我是 OpenCv 和 StackOverflow 的新手,对 Android 编程几乎是新手,所以如果我的问题很愚蠢,请原谅。 我正在尝试将从相机获取的图像与某些图像文件进行匹配,以查看哪个图像文件
亲爱的1-我知道 Point 类是关于两个 channel 整数值坐标(点):就像 MatOfPoint 是整数点的 vector 。与KeyPoint类一样吗?我知道这是一个包含显着点的类。将它们视
我尝试使用以下代码: xCoordinate=point.x (点是 cv2.keyPoint 的类型)它给我错误说 cv2.keyPoint 没有属性 'x' 最佳答案 point.pt 是
前几天,我不得不继续使用 OpenCV 3 和 Python 2.7 的旧项目。 在这段代码中,加载 cv2.KeyPoint 我是这样做的: import numpy as np i
我是一名优秀的程序员,十分优秀!