title: Capture frames from IP camera using EmguCV
body: <p>Maybe the title has been used a lot of times, but any answer I found on Google gives me the correct answer, so I'm going to explain my problem here:</p>
  
  <p>I have an IP camera, which works perfectly using it's own program, so I know that the camera works fine. I have set the IP camera to have an static IP, so it always has the same IP address. I succeed taking frames from the webcam, using:</p>
  
  <pre><code>Dim image As Image(Of Bgr, Byte) = capturez.QueryFrame()
  </code></pre>
  
  <p>And I know that the method QueryFrame() has 3 ways of use:</p>
  
  <pre><code>Dim image As Image(Of Bgr, Byte) = capturez.QueryFrame()
  Dim image As Image(Of Bgr, Byte) = capturez.QueryFrame(int)
  Dim image As Image(Of Bgr, Byte) = capturez.QueryFrame(string)
  </code></pre>
  
  <p>I am trying to do this:</p>
  
  <pre><code>Dim image As Image(Of Bgr, Byte) = capturez.QueryFrame("rtsp://192.168.1.3/img/video.sav")
  </code></pre>
  
  <p>Many people say that this works, but not for me. I've seen in other forums also this:</p>
  
  <pre><code>Dim image As Image(Of Bgr, Byte) = capturez.QueryFrame("rtsp://user:pass@192.168.1.3/img/video.sav")
  </code></pre>
  
  <p>In case that the IP camera has an user and password attached (which is my case), but still doesn't work.</p>
  
  <p>The error I get with this is:
  'a value with type emgu.CV.Image(Of Emgu.CV.Structure.Gray, Byte) can not be converted in Emgu.CV.Image(Of Emgu.CV.Image(Of Emgu.CV.Structure.Bgr, Byte)'</p>
  
  <p>I dont know why I get this error. I think that I get this because the Capture.QueryFrame() is taking a capture with type Emgu.CV.Structure.Gray and it can not be converted to the other one, but I have not idea if I am right.</p>
  
  <p>If I am right, I dont know how to save that image taken by the Capture.QueryFrame()</p>
  
  <p>If I'm not right, then I don't know why I am getting that error.</p>
  
  <p>I have seen other people using things like this:</p>
  
  <pre><code>Dim image As Image(Of Bgr, Byte) = capturez.QueryFrame("http://192.168.1.3:port/img/video.sav")
  </code></pre>
  
  <p>But the IP camera is not connected by internet. It is connected by LAN, directly to my computer. I have configured the IPv4 config of my computer, and the settings of my IP camera, to make it works without an Internet connection, and as I said before, it is working using its own program.</p>
  
  <p>I hope you have all the details needed to make you understand my problem. If not, please tell me and I try to explain it in another way.</p>
  
  <p>Resuming: I have an IP camera, I want to take a picture with it (not a video streaming, only a picture when I decide to do it), I am using Emgu 2.4.0, Visual Basic and VS2012. I don't know how to do that using the QueryFrame() method</p>
  
  <p>To finish, if it is possible, could someone tell me what means that </p>
  
  <pre><code>../img/video.sav
  </code></pre>
  
  <p>that everybody put in the string? It is a directory I must have in my computer or something like this?</p>
  
  <p>I put the method where I am trying to do this capture if it could help. In it I am trying to capture a frame and display in the PictureBox the white colours of the image in white, and the rest in black:</p>
  
  <pre><code> Private Sub StartButtonTimer_Tick() Handles StartButtonTimer.Tick
      Dim X As Integer
      Dim Y As Integer
  
      If timeLeft &gt; 0 Then
          timeLeft -= 1
          timeLabel.Text = timeLeft &amp; " seconds"
  
          'DLE prueba tomar foto después del tiempo especificado - pongo a negro el fondo del picturebox
          PictureBox1.BackColor = Color.Black
      Else
  
          'DLE prueba tomar foto después del tiempo especificado - hago foto de lo que ve la camara
          Dim img As Image(Of Bgr, Byte) = capturez.QueryFrame()
  
  
          For X = 0 To img.Width - 1
              For Y = 0 To img.Height - 1
                  Dim pixelColor As Bgr = img(Y, X)
  
                  If (pixelColor.Blue &gt;= 200 And pixelColor.Blue &lt;= 255) And
                     (pixelColor.Green &gt;= 200 And pixelColor.Green &lt;= 255) And
                     (pixelColor.Red &gt;= 200 And pixelColor.Red &lt;= 255) Then
                      pixelColor.Blue = 255
                      pixelColor.Green = 255
                      pixelColor.Red = 255
                      img(Y, X) = pixelColor
                  Else
                      pixelColor.Blue = 0
                      pixelColor.Green = 0
                      pixelColor.Red = 0
                      img(Y, X) = pixelColor
                  End If
              Next
          Next
          StartButtonTimer.Stop()
          PictureBox1.Image = img.ToBitmap
          startButton.Enabled = True
          SetParameters.Enabled = True
          SetDefaultTimeButton.Enabled = True
          SetForm()
      End If
  
      'Old frame is overwritten so that the most current image is always ready to retrieve
      Dim image As Image(Of Bgr, Byte) = capturez.QueryFrame()
  
  
  End Sub
  </code></pre>
  
  <p>Thanks a lot for any help!! I am getting crazy with this!!</p>
  
  <p><strong>EDIT:</strong>
  Researching a little bit in the AForge libraries and forums, I have seen thisthread, where a guy explains how he could take images from an IP camera using that libraries. I have that libraries installed in my computer for other projects, but I didn't know that I could use this libraries for my purpose.</p>
  
  <p>This is the thread:
  <a href="http://emgu.com/forum/viewtopic.php?t=4199" rel="nofollow noreferrer">http://emgu.com/forum/viewtopic.php?t=4199</a></p>
  
  <p>I went there and I have seen the projects he suggest to see, and I have found in the Samples directory, a project called Player, which use this method to open the url of a camera to display what is it watching:</p>
  
  <pre><code>// Open MJPEG URL
      private void openMJPEGURLToolStripMenuItem_Click( object sender, EventArgs e )
      {
          URLForm form = new URLForm( );
  
          form.Description = "Enter URL of an MJPEG video stream:";
          form.URLs = new string[]
              {
                  "http://195.243.185.195/axis-cgi/mjpg/video.cgi?camera=4",
                  "http://195.243.185.195/axis-cgi/mjpg/video.cgi?camera=3",
              };
  
          if ( form.ShowDialog( this ) == DialogResult.OK )
          {
              // create video source
              MJPEGStream mjpegSource = new MJPEGStream( form.URL );
  
              // open it
              OpenVideoSource( mjpegSource );
          }
      }
  </code></pre>
  
  <p>I am studying how it works, but I don't understand why it use this lines in that way:</p>
  
  <pre><code>"http://195.243.185.195/axis-cgi/mjpg/video.cgi?camera=4",
  "http://195.243.185.195/axis-cgi/mjpg/video.cgi?camera=3",
  </code></pre>
  
  <p>I mean, I know that I have to put the url of my camera, in the url of this example. In my case, my IP camera is 192.168.1.3, so it must look like this:</p>
  
  <pre><code>"http://192.168.1.3/axis-cgi/mjpg/video.cgi?camera=4"
  </code></pre>
  
  <p>But, about the rest of the line, i mean, this:</p>
  
  <pre><code>.../axis-cgi/mjpg/video.cgi?camera=4
  </code></pre>
  
  <p>why they put this? I don't know how to find this information in my camera. I only have one camera connected via IP so, what I must put there? It is a directory I have to create or something like that?</p>
  
  <p><strong>EDIT:</strong>
  About the above, after investigate a little more I have seen that the rest of the url specifies the path where my image is store. After trying to find the path where my camera leaves the images, I am not able to find it, nor the user's guide, nor surfing by internet. I am not able to find that path =(. Anyone has an idea about how to find it?</p>
  
  <p>Thanks a lot!!</p>
  
  <p>Tools I am using: EmguCV 2.4.0, vs2012, IP Camera: ETROVISION EV6131HW, Visual Basic</p>