用Python和OpenCV创建一个图片搜索引擎时遇到的坑

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qian1996/article/details/79852322

在学习http://python.jobbole.com/80860/ 中的图片搜索引擎时,遇到一些问题,花费了很长时间解决:


问题一:TypeError: ellipse() takes at most 5 arguments (8 given)

解决:有两个参数不同的ellipse()函数,自动调用了五个参数,需要调用的方法有八个参数的方法。

由于(cX,cY)不是整数类型,需要强制类型转化。

由于教程基于的是python2,在迁移到Python 3.6时,一些原本在Python 2.7中工作得很好的代码出现问题。

原代码:cv2.ellipse(ellipMask,(cX, cY),(axesX,axesY), 0, 0, 360, 255, -1)

更改后:cv2.ellipse(ellipMask,(int(cX), int(cY)),(int(axesX),int(axesY)), 0, 0, 360, 255, -1)

参考:https://stackoverflow.com/questions/25408391/python-opencv-ellipse-takes-at-most-5-arguments-8-given


问题二:

hist = cv2.normalize(hist).flatten()

TypeError: Required argument 'dst' (pos 2) not found 解决

缺少一个参数。

解决:

原代码:hist = cv2.normalize(hist).flatten()
更改后:hist = cv2.normalize(hist,hist).flatten()
需要两个参数

问题三:路径问题

result = cv2.imread(args["resultpath"] + "\\" + resultID)imageID = imagePath[imagePath.rfind("\\") +1:]之前遇到过。。由于显示cv2.imshow("Result", result) 这句出现问题,那么,我想可能是result不对,于是在search中输出了resultID。发现之前的一个操作误将index.csv中的键也就是图片名弄错了,改回去之后成功了。问题四:速度有点慢cd = ColorDescriptor((8, 12, 3)) 参数可适当更改。

猜你喜欢

转载自blog.csdn.net/qian1996/article/details/79852322