【问题标题】:importing installed python module x.features2d from Opencv从 Opencv 导入已安装的 python 模块 x.features2d
【发布时间】:2016-04-01 13:24:03
【问题描述】:

我已经在我的 Ubuntu 14.04 系统上安装了 Opencv3 模块,并且子模块的安装没有问题。但是当我在导入cv2后在我的代码中调用x.features2d时,如下代码所示

import sys
import cv2
import cv2.xfeatures2d
import numpy as np
sys.path.append('/usr/local/lib/python2.7/site-packages')
img_bgr=cv2.imread('sc2.png')
img_gray=cv2.cvtColor(img_bgr,cv2.COLOR_BGR2GRAY)
template=cv2.imread('template.png',0)
w, h=template.shape[::-1]
res=cv2.matchTemplate(img_gray,template,cv2.TM_CCOEFF_NORMED)
threshold=0.7
loc = np.where(res >= threshold)
for pt in zip(*loc[::-1]):
 cv2.rectangle(img_bgr, pt, (pt[0]+w, pt[1]+h), (0,255,0), 2)
freakExtractor=cv2.xfeatures2d.FREAK_create()
keypoints,descriptors=freakExtractor.compute(img_bgr,keypoints)
cv2.imshow('detected', img_bgr)
cv2.waitKey(0)

它给了我无法找到 x.features2d 模块的错误,如下所示

Traceback (most recent call last):
File "test.py", line 3, in <module>
import cv2.xfeatures2d
ImportError: No module named xfeatures2d

我尝试重新安装它并安装了opencv-contrib,但同样的问题发生了。 有什么办法解决吗?

【问题讨论】:

  • 你安装xfeatures2d模块吗?

标签: python opencv


【解决方案1】:

你没有提供很多关于你的安装过程的细节。

所有 contrib 功能(例如 xfeatures2d)不再是预构建库的一部分。这意味着 xfeatures2d 只有在您自己编译 openCV 时才能工作。

此处提供了如何执行此操作的示例(例如对于 Windows):

https://putuyuwono.wordpress.com/2015/04/23/building-and-installing-opencv-3-0-on-windows-7-64-bit/

【讨论】:

    猜你喜欢
    • 2018-01-21
    • 1970-01-01
    • 1970-01-01
    • 2018-04-23
    • 2021-03-31
    • 2020-07-05
    • 2020-12-26
    • 1970-01-01
    相关资源
    最近更新 更多