1

在遇到一些问题后,我最近设法让 SimpleCV 启动并运行。我现在安装了一个可以工作的 SimpleCV,并将它与 Eclipse Indigo 一起使用。但是,我从 SimpleCV 导入的所有内容都标记为红色,并且 Eclipse 声明它找不到指定的导入(即使导入的函数工作正常)。

有什么方法可以让 Eclipse 识别来自 SimpleCV 的导入,以便我可以使用它的 Ctrl-Space 代码完整功能?

我尝试将“SimpleCV”添加到 Forced Builtins,但没有成功。(当我对 OpenCV 遇到同样的问题时,我就是这样做的,然后它就起作用了)

感谢您的任何建议!

4

1 回答 1

1

SimpleCV 中的导入非常糟糕。我一直在努力解决您遇到的同样问题。他们不想修复它的原因(根据他们在他们网站上的回答(http://help.simplecv.org/question/472/code-completion-with-eclipse/)并不是因为他们“都使用vim、emacs、vi”,但是因为他们的很多代码都依赖于使用 * 导入将很多库拉入本地命名空间。这充其量是懒惰的编程,否则真的很糟糕。

哎呀,你甚至不能自己导入他们的一些文件,因为它们依赖于 SimpleCV init .py 文件和已经导入的 base.py 文件。这两个文件都有很多一揽子导入。我想知道为什么 import SimpleCV 需要超过 2 秒才能在我的带有 SSD 的电脑上运行。现在我知道了。

他们的 init.py 文件有这些导入:

from SimpleCV.base import *
from SimpleCV.Camera import *
from SimpleCV.Color import *
from SimpleCV.Display import *
from SimpleCV.Features import *
from SimpleCV.ImageClass import *
from SimpleCV.Stream import *
from SimpleCV.Font import *
from SimpleCV.ColorModel import *
from SimpleCV.DrawingLayer import *
from SimpleCV.Segmentation import *
from SimpleCV.MachineLearning import *

他们的 base.py 文件还有更多的导入:

import os
import sys
import warnings
import time
import socket
import re
import urllib2
import types
import SocketServer
import threading
import tempfile
import zipfile
import pickle
import glob #for directory scanning
import abc #abstract base class
import colorsys
import logging
import pygame as pg
import scipy.ndimage as ndimage
import scipy.stats.stats as sss  #for auto white balance
import scipy.cluster.vq as scv    
import scipy.linalg as nla  # for linear algebra / least squares
import math # math... who does that 
import copy # for deep copy
import numpy as np
import scipy.spatial.distance as spsd
import scipy.cluster.vq as cluster #for kmeans
import pygame as pg
import platform
import copy
import types
import time

from numpy import linspace
from scipy.interpolate import UnivariateSpline
from warnings import warn
from copy import copy
from math import *
from pkg_resources import load_entry_point
from SimpleHTTPServer import SimpleHTTPRequestHandler
from types import IntType, LongType, FloatType, InstanceType
from cStringIO import StringIO
from numpy import int32
from numpy import uint8
from EXIF import *
from pygame import gfxdraw
from pickle import *

您知道他们声称要转换所有这些不同的 CV 库并将“Pythonic”方法应用于它们。但是这种进口混乱只是清楚地证明了他们错了。

我修复他们的导入的尝试是从他们的 init.py 文件中删除所有这些 import *,这有助于解决它在 eclipse 中出现的代码完成延迟。然后将SimpleCV egg 目录(C:\Python27\Lib\site-packages\simplecv-1.3-py2.7.egg)作为外部库导入eclipse。在那之后,我能够运行这个:

from SimpleCV.ImageClass import Image

导入颜色也是如此:

from SimpleCV.Color import Color

有周期性进口,所以要小心那些,因为它们可能会咬你。在导入 SimpleCV.ImageClass 之前尝试导入 SimpleCV.Color 时,我自己也有过一个。请注意,通过上述说明,我似乎能够从 Eclipse 获得代码完成。

于 2013-04-05T20:41:23.527 回答