title: How to detect doors and windows from a floor plan image?
body: <p>I am working on floor plan analysis where I want to detect the number of doors and windows in floor plan images. How can I pull this off using OpenCV in Python?</p>
  
  <p>I have already tried detecting walls in the images and below is the code for the same.</p>
  
  <pre><code>img_bw = 255*(cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) &gt; 20).astype('uint8')
  
  se1 = cv2.getStructuringElement(cv2.MORPH_RECT, (3,3))
  se2 = cv2.getStructuringElement(cv2.MORPH_RECT, (1,1))
  mask = cv2.morphologyEx(img_bw, cv2.MORPH_CLOSE, se1)
  mask = cv2.morphologyEx(mask, cv2.MORPH_OPEN, se2)
  
  mask = np.dstack([mask, mask, mask]) / 255
  out = img * mask
  plt.figure(figsize=(15,10))
  plt.imshow(out, cmap="gray")
  </code></pre>
  
  <p>Now I am looking to extract the number of doors and windows (probably in CSV or XML sheet).</p>
  
  <p><a href="https://i.stack.imgur.com/2hTbh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2hTbh.png" alt="enter image description here"></a></p>