模块未找到错误(imutils.paths)

时间:2018-04-15 02:55:01

标签: python opencv3.0

这是我尝试在python3.6中运行虚拟环境的代码。我使用ubuntu最新版本17.10,我运行代码为python3 gather_annotations.py

import numpy as np  
import cv2 
import argparse  
from imutils.paths import list_images
from selectors import BoxSelector  
#parse arguments
ap = argparse.ArgumentParser()  
ap.add_argument("-d","--dataset",required=True,help="path to images dataset...")  
ap.add_argument("-a","--annotations",required=True,help="path to save annotations...")  
ap.add_argument("-i","--images",required=True,help="path to save images")  
args = vars(ap.parse_args())  
#annotations and image paths  
annotations = []  
imPaths = []  
#loop through each image and collect annotations  
for imagePath in list_images(args["dataset"]):  
    #load image and create a BoxSelector instance  
    image = cv2.imread(imagePath)  
    bs = BoxSelector(image,"Image")  
    cv2.imshow("Image",image)  
    cv2.waitKey(0)  
    #order the points suitable for the Object detector  
    pt1,pt2 = bs.roiPts  
    (x,y,xb,yb) = [pt1[0],pt1[1],pt2[0],pt2[1]]  
    annotations.append([int(x),int(y),int(xb),int(yb)])  
    imPaths.append(imagePath)  
#save annotations and image paths to disk  
annotations = np.array(annotations)  
imPaths = np.array(imPaths,dtype="unicode")  
np.save(args["annotations"],annotations)  
np.save(args["images"],imPaths)  

And I get the following errors

我将此文件夹命名为' 2'我有所有脚本和其他文件夹命名选择器,其中有2个脚本init和box_selector

  • 2(文件夹)

  • ----选择器/

  • ------------_ init _.py
  • ------------ box_selector.py
  • ---- detector.py
  • ---- gather_annotations.py
  • ---- test.py
  • ---- train.py

我如何解决这个问题,在我收到代码的帖子中说了一些关于“相对进口”的信息。但是我无法解决它,谢谢你。

2 个答案:

答案 0 :(得分:1)

你需要使用。访问文件夹内文件的符号..

所以

from folder.python_file import ClassOrMethod

在你的情况下

from selectors.box_selector import BoxSelector

在selectors文件夹中使用__init__.py对于实现此功能至关重要。

您可以根据需要添加任意数量的文件夹,并且可以按如下方式访问,但每个文件夹必须包含__init__.py才能正常工作

from folder.folder1.folder2.python_file import ClassOrMethod

答案 1 :(得分:0)

一个可能引起混淆的领域是,有一个名为“选择器”的不同python库,它与本代码示例的选择器不同。

https://docs.python.org/3/library/selectors.html

我最终将该示例的“选择器”(包括目录)重命名为“ boxselectors”

此示例来自http://www.hackevolve.com/create-your-own-object-detector/