title: reading an opencv image in python through a socket
body: <p>I am trying to read an opencv image in a python socket that is sent from c++.</p>
  
  <p>I am able to read the image into another c++ program or VB program and build an image but with python I don't understand what's happening.</p>
  
  <p>The sending code where I send the mat.data:</p>
  
  <pre><code>char *start_s = "&lt;S&gt;&lt;size&gt;43434234&lt;cols&gt;64&lt;rows&gt;64&lt;SE&gt;";//plus I send the image size, cols, rows, which varies, not like the static char string shown
  char *end_e = "&lt;E&gt;";
  cv::Mat image_send = some_mat;
  iResult = send( ConnectSocket, start_s, (int)strlen(start_s), 0 );
  iResult = send( ConnectSocket, (const char *) image_send.data, i_buffer_size, 0 );
  iResult = send( ConnectSocket, end_e, (int)strlen(end_e), 0 );
  </code></pre>
  
  <p>This is what I have tried with the python, but haven't had any success yet. The image_cols and Image_rows are filtered from the socket, not shown here, and only the image_mat.data from the c++ mat is in the socket that I am trying to put into the image:</p>
  
  <pre><code>data = conn.recv(4757560)
          if(i_Read_Image == 2) &amp; (image_cols != 0) &amp; (image_rows != 0):
              print ("Entering")
              #print(data)
              data2 = np.fromstring(data, dtype='uint8')
              img_np = cv2.imdecode(data2,cv2.IMREAD_COLOR )
              cv2.imshow('image',img_np)
              cv2.waitKey(0)
  
              #Also tried this
              #img = Image.new('RGB', (image_cols, image_rows))
              #img.putdata(data)
  
          #img5 = np.reshape(data2,(image_rows,image_cols))
          i_Read_Image = 0
  </code></pre>