Q: How to measure the length (in pixel) for each pole in an image I want to measure the height and width of each individual pole in pixel. 
But because the poles are not always stand straight, but i need the height of pole from the horizontal ground. Can anyone guide me how to handle this?
Note: I might need to get the angle it has slanted later on. Not sure I can ask so many question in here. But greatly appreciate if someone can help. 
The image sample i have is at below link:


A: This should give you a good idea how to do it:
#!/usr/local/bin/python3
import cv2

# Open image in greyscale mode
img = cv2.imread('poles.png',cv2.IMREAD_GRAYSCALE)

# Threshold image to pure black and white AND INVERT because findContours looks for WHITE objects on black background
_, thresh = cv2.threshold(img,127,255,cv2.THRESH_BINARY_INV)

# Find contours
_, contours, _ = cv2.findContours(thresh,cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)

# Print the contours 
for c in contours:
   x,y,w,h = cv2.boundingRect(c)  
   print(x,y,w,h)

The output is this, where each line corresponds to one vertical bar in your image:
841 334 134 154   <--- bar 6 is 154 pixels tall
190 148 93 340    <--- bar 2 is 340 pixels tall
502 79 93 409     <--- bar 4 is 409 pixels tall
633 55 169 433    <--- bar 5 is 433 pixels tall
1009 48 93 440    <--- bar 7 is 490 pixels tall
348 48 93 440     <--- bar 3 is 440 pixels tall
46 46 93 442      <--- bar 1 is 442 pixels tall (leftmost bar)

The first column is the distance from the left edge of the image and the last column is the height of the bar in pixels.

As you seem unsure about whether you want to do this in Python or C++, you may prefer not write any code at all - in which case you can simply use ImageMagick which is included in most Linux distros and is available for macOS and Windows.
Basically, you use "Connected Component" analysis by typing this into the Terminal:
convert poles.png -colorspace gray -threshold 50% \
   -define connected-components:verbose=true      \
   -connected-components 8 null:

Output
Objects (id: bounding-box centroid area mean-color):
  0: 1270x488+0+0 697.8,216.0 372566 srgb(255,255,255)
  1: 93x442+46+46 92.0,266.5 41106 srgb(0,0,0)
  2: 93x440+348+48 394.0,267.5 40920 srgb(0,0,0)
  3: 93x440+1009+48 1055.0,267.5 40920 srgb(0,0,0)
  4: 169x433+633+55 717.3,271.0 40269 srgb(0,0,0)
  5: 93x409+502+79 548.0,283.0 38037 srgb(0,0,0)
  6: 93x340+190+148 236.0,317.5 31620 srgb(0,0,0)
  7: 134x154+841+334 907.4,410.5 14322 srgb(0,0,0)

That gives you a header line which tells you what all the fields are, then a line for each of the blobs it found in the image. Disregard the first one because that is the white background - you can see that from the last field which is rgb(255,255,255). 
So, if we look at the last line, it is a blob that is 134 pixels wide and 154 pixels tall, starting at x=841 and y=334 from the top-left corner, i.e. it corresponds to the first contour that OpenCV found.
