How can i measure shape elongation feature in matlab or python opencv?
In the Image Processing Toolbox for MATLAB there is a function called regionprops, which may be what you need. It takes a binary image, finds connected components in it, and returns various measurements of each connected component.  Here's a list of things it can compute:

Shape Measurements

  'Area'              'EulerNumber'       'Orientation'               
  'BoundingBox'       'Extent'            'Perimeter'          
  'Centroid'          'Extrema'           'PixelIdxList' 
  'ConvexArea'        'FilledArea'        'PixelList'
  'ConvexHull'        'FilledImage'       'Solidity' 
  'ConvexImage'       'Image'             'SubarrayIdx'            
  'Eccentricity'      'MajorAxisLength' 
  'EquivDiameter'     'MinorAxisLength'                   

Pixel Value Measurements (requires grayscale image as an input)

  'MaxIntensity'
  'MeanIntensity'
  'MinIntensity'
  'PixelValues'
  'WeightedCentroid'