title: Python-Opencv Watershed markers
body: <p>I am trying to create a web based foreground extraction service (similar to <a href="http://clippingmagic.com" rel="nofollow">clippingmagic.com</a>).</p>
  
  <p>I am using marker based watershed image segmentation (opencv, python).
  I am using sketch.js for allowing users to draw the markers on the image.</p>
  
  <p>I need to call the python script from my php code.
  Here's what the script needs to do: </p>
  
  <ol>
  <li>Read the image which has the markers drawn on it.</li>
  <li>Create a matrix of integers where different colored markers are labelled with different integers.</li>
  <li>Feed the markers matrix and input image to the watershed algorithm and store the output to a local file.</li>
  <li>Extract the foreground which is marked with the corresponding marker.</li>
  <li>Display the output to the user.</li>
  </ol>
  
  <p>I am facing problem with step 2.</p>
  
  <p>Here is my code so far</p>
  
  <pre><code>#!/usr/bin/env python
  
  import numpy as np
  import cv2
  from common import Sketcher
  
  img_m = cv2.imread('1_m.jpg'); //my image which has colored marks on it
  
  h, w = img.shape[:2]
  markers = np.zeros((h, w), np.int32)
  
  cv2.imshow("Image",img_m);
  
  //trying to put '1' at all places where image is marked with color (179,230,29)
  markers = np.where((img_m == [179,230,29]),1,0)
  //trying to put '2' at all places where image is marked with color (238,27,34)
  markers = np.where((img_m == [238,27,34]),2,0)
  
  cv2.watershed(img, markers) //gives me error "markers should be 1-channel 32-bit image"
  
  cv2.waitKey(50)
  </code></pre>
  
  <p>Can somebody help me with this. Thanks.</p>