I'm trying to build a new SimpleCV FeatureExtractor for openCV's Hough Circle Transform but I'm running into an error during my machine learning script's training phase.
I've provided the error below. It is raised by the Orange machine learning library when creating the self.mDataSetOrange
variable within SimpleCV's TreeClassifier.py. The size of the dataset does not match Orange's expectation for some reason. I looked into Orange's source code and the found that error is thrown here:
orange/source/orange/cls_example.cpp
int const nvars = dom->variables->size() + dom->classVars->size();
if (Py_ssize_t(nvars) != PyList_Size(lst)) {
PyErr_Format(PyExc_IndexError, "invalid list size (got %i, expected %i items)",
PyList_Size(lst), nvars);
return false;
}
Obviously, my feature extractor is not extracting the things as required by Orange but I can't pinpoint what the problem could be. I'm pretty new to SimpleCV and Orange so I'd be grateful if someone could point out any mistakes I'm making.
The error:
Traceback (most recent call last):
File "MyClassifier.py", line 113, in <module>
MyClassifier.run(MyClassifier.TRAIN_RUN_TYPE, trainingPaths)
File "MyClassifier.py", line 39, in run
self.decisionTree.train(imgPaths, MyClassifier.CLASSES, verbose=True)
File "/usr/local/lib/python2.7/dist-packages/SimpleCV-1.3-py2.7.egg/SimpleCV/MachineLearning/TreeClassifier.py", line 282, in train
self.mDataSetOrange = orange.ExampleTable(self.mOrangeDomain,self.mDataSetRaw)
IndexError: invalid list size (got 266, expected 263 items) (at example 2)
HoughTransformFeatureExtractor.py
class HoughTransformFeatureExtractor(FeatureExtractorBase):
def extract(self, img):
bitmap = img.getBitmap()
cvMat = cv.GetMat(bitmap)
cvImage = numpy.asarray(cvMat)
height, width = cvImage.shape[:2]
gray = cv2.cvtColor(cvImage, cv2.COLOR_BGR2GRAY)
circles = cv2.HoughCircles(gray, cv2.cv.CV_HOUGH_GRADIENT, 2.0, width / 2)
self.featuresLen = 0
if circles is not None:
circleFeatures = circles.ravel().tolist()
self.featuresLen = len(circleFeatures)
return circleFeatures
else:
return None
def getFieldNames(self):
retVal = []
for i in range(self.featuresLen):
name = "Hough"+str(i)
retVal.append(name)
return retVal
def getNumFields(self):
return self.featuresLen