sightmachine / SimpleCV

The Open Source Framework for Machine Vision
http://simplecv.org
BSD 3-Clause "New" or "Revised" License
2.69k stars 798 forks source link

TypeError When Got No Descriptors in ImageClass.py #597

Closed qbx2 closed 3 years ago

qbx2 commented 10 years ago

ERROR: object of type 'NoneType' has no len() Traceback (most recent call last): File "C:\Users\Administrator\Desktop\1.py", line 22, in img = img.drawKeypointMatches(Image("box.jpg")) File "C:\Users\qbx2\Python27\lib\site-packages\SimpleCV\ImageClass.py", line 7496, in drawKeypointMatches skp,sd = self._getRawKeypoints(thresh) File "C:\Users\qbx2\Python27\lib\site-packages\SimpleCV\ImageClass.py", line 7370, in _getRawKeypoints if( len(self._mKPDescriptors) == 0 ): TypeError: object of type 'NoneType' has no len()

around line 7370:

        elif( new_version >=1  and flavor in ["ORB", "SIFT", "SURF"] ):
           FeatureDetector = cv2.FeatureDetector_create(flavor)
           DescriptorExtractor = cv2.DescriptorExtractor_create(flavor)
           self._mKeyPoints = FeatureDetector.detect(self.getGrayNumpy())
           self._mKeyPoints,self._mKPDescriptors = DescriptorExtractor.compute(self.getGrayNumpy(),self._mKeyPoints)
           if( len(self._mKPDescriptors) == 0 ):
                return None, None     
           self._mKPFlavor = flavor

I have changed if( len(self._mKPDescriptors) == 0 ): to if( self._mKPDescriptors == None or len(self._mKPDescriptors) == 0 ): and now it works well

richajain commented 10 years ago

Does the above code still exists in the latest version? I tried to fix it but I cannot find any such code in ImageClass.py

jayrambhia commented 10 years ago

This issue has been resolved.