title: Measuring the distance between pixels on OpenCv with Python
body: <p>I'm a newbie with Open CV and computer vision so I humbly ask a question. With a pi camera I record a video and in real time I can recognize blue from other colors (I see blue as white and other colors as black).</p>
  
  <p><a href="https://i.stack.imgur.com/dUVyTm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dUVyTm.png" alt="enter image description here"></a></p>
  
  <p>I want to measure the length of the base of the area (because I have a white rectangle and a black rectangle). This two rectangle together create the square frame.</p>
  
  <p><a href="https://i.stack.imgur.com/XAyjrm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XAyjrm.png" alt="enter image description here"></a></p>
  
  <p>Excerpt of code: </p>
  
  <pre><code># Take each frame
  _, frame = cap.read(0)
  
  # Convert BGR to HSV
  hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
  
  # define range of blue color in HSV
  lower_blue = np.array([80,30,30])
  upper_blue = np.array([130,150,210])
  
  # Threshold the HSV image to get only blue colors
  mask = cv2.inRange(hsv, lower_blue, upper_blue)    
  # applica filtri morfologici
  mask = cv2.erode(mask, spotFilter)
  mask = cv2.dilate(mask, maskMorph)
  # ^Now the mask is a black and white image.
  # ^Get height of the black region in this image
  
  # Bitwise-AND mask and original image
  res = cv2.bitwise_and(frame,frame, mask= mask)
  cv2.imshow('frame',frame)
  cv2.imshow('mask',mask)
  cv2.imshow('res',res)
  </code></pre>