0

I'm having the hardest time trying to find a solution for something I think would be very simple. The Capture Constructor (String) in Emgu.CV should "Create a capture from file or a video stream."

However, I cannot capture anything with my code in C# despite my IP camera (Axis) allowing a video stream as follows: Request a Motion JPEG video stream -> http://myserver/axis-cgi/mjpg/video.cgi (By the way, according to the manufacturer, "A successful request returns a continuous flow of JPEG images. The content type is multipart/x-mixed-replace and each image ends with a boundary string .")

FYI, the camera server does require a username and password login, which I haven't been able to figure out how to include with Capture yet, either... Am I supposed to make a HTTPWebRequest first and then do Capture, or am I supposed to do something much more complicated? Not sure if login may be an issue since I didn't get a specific error on this, but suspect a webrequest may be necessay, which I don't know how to include...

Stripped down code in my form.cs:

Capture _capture = null; //Camera
string sourceURL = "http://192.168.0.90/axis-cgi/mjpg/video.cgi";
_capture = new Capture(sourceURL);
Image<Bgr, Byte> imgOriginal = new Image<Bgr, byte>(_capture.RetrieveBgrFrame().ToBitmap());

Then I try to display imgOriginal in an ImageBox. However, at the last step above, it already generates an error that says "unable to create capture..." or something like this.

Shouldn't this be very simple with emguCV or am I mistaken? If someone can help me figure out how to capture the image, I can take it from there with processing my images. Thank you in advance!

JoeC
  • 71
  • 2
  • 6

2 Answers2

2

Might be too late for this post , but hopefully it'll help someone else in the future.

For MJPEG video codec use ==> http://root:pass@172.16.10.38/axis-cgi/mjpg/video.cgi?x.mjpeg

For H.264 codec use ==> rtsp://root:pass@172.16.10.38/axis-media/media.amp?videocodec=h264&resolution=640x480

Please note that these URIs apply only to AXIS brand IP Cameras . For other IP camera brands , I'd suggest you to check the below website , as each manufacturer has a different HTTP or RTSP URI

http://www.soleratec.com/support/rtsp/rtsp_listing

As for the implementation code, here is a headstart :

private static Capture _cameraCapture;

//Windows form button to start the video stream                
private void btn_play_Click(object sender, EventArgs e)
{            
 Run();                            
} 

private void Run()
{
 if (rdbWebcam.Checked == true) //radio button
 {
  _cameraCapture = new Capture(0); //use local webcam
 }
else
  {
  _cameraCapture = new Capture(txtrtsp.Text); //use rtsp or http uri you typed into a textbox
  }
 Application.Idle += ProcessFrame;
}   

private void  ProcessFrame(object sender, EventArgs e)
 {         
   try
       {
        Mat frame = _cameraCapture.QueryFrame();
        imageBox1.Image = frame; //imagebox to  show live video
        }
       catch (Exception ex)
        {
        MessageBox.Show(ex.Message);
         Application.Exit();
         }
}

//Windows Form FormClosing event
private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
{     
 if (_cameraCapture != null)
    {
     _cameraCapture.Stop();
     _cameraCapture.Dispose();
    }

}
rugby2312
  • 1,056
  • 1
  • 10
  • 15
0

There are a few things that you might want to try.

  1. First you can use something like fiddler(its a proxy to monitor your web traffic) to check that when application is making the request to the server what response is coming back.
  2. Second if the server requires authentication its very likely its using HTTP Basic authentication you might want to try to call the url something like

    string sourceURL = "http://username:password@192.168.0.90/axis-cgi/mjpg/video.cgi"; _capture = new Capture(sourceURL);

or else you will have to send the parameters in Authorization Header

  1. You can use the native cvInvoke function to check that if it helps.The code will be something like this.

    Capture _Capture = new Emgu.CV.CvInvoke.cvCreateFileCapture("http://username:password@192.168.0.90/axis-cgi/mjpg/video.cgi");

Please refer to this SO answer more info

Community
  • 1
  • 1
Shiva
  • 6,677
  • 4
  • 36
  • 61
  • Hi Shiva, Thanks for your help. I get the following error: "Emgu.CV.CvInvoke.cvCreateFileCapture(string)' is a 'method' but is used like a 'type'". When I take "new" out, then I get "Cannot implicitly convert type 'System.IntPtr' to 'Emgu.CV.Capture'". Not sure how to do this correctly since the previous reference you provided didn't seem to clearly state how to fix the InPtr issue? – JoeC May 05 '15 at 22:55