问题
Using Visual Basic 2008 and Emgu CV, I can capture the stream of a webcam on my PC. What I want to do is connect to an IP camera, knowing its URL, using Capture = New Capture().
Here is the code I have:
Imports Emgu.CV
Imports Emgu.CV.Util
Imports Emgu.CV.Structure
Public Class Form1
Dim capturez As Capture = New Capture("rtsp://[IP Address]/mpeg4/media.amp")
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim imagez As Image(Of Bgr, Byte) = capturez.QueryFrame()
PictureBox1.Image = imagez.ToBitmap()
End Sub
End Class
I get the following error: Unable to create capture from rtsp://[IP Address]/mpeg4/media.amp
Is it possible to do this using Capture = New Capture? If not, is their any other method?
Thanks.
回答1:
This is the solution I used in the end. It only works with JPEG webcams (not MJPEG) and does not require EmguCV
'Connect To Webcam ----------------------------------------------------------------------
Dim NumberFrames As Integer = 1
Dim imgNum = Convert.ToString(FrameNumber)
Dim sourceURL As String = ("http://91.142.238.200/record/current.jpg?rand=" + imgNum)
'create HTTP request
Dim req As HttpWebRequest = HttpWebRequest.Create(sourceURL)
'get response
Dim res As HttpWebResponse = req.GetResponse
'get response stream
Dim reader As New StreamReader(res.GetResponseStream())
'read data from stream
Dim img As Image = Image.FromStream(res.GetResponseStream())
'get bitmap
PictureBox1.Image = img
'Increment frame
FrameNumber = FrameNumber + 1
'-----------------------------------------------------------------------------------------
回答2:
This camera has ip username and password? if you try something like this:
Imports Emgu.CV
Imports Emgu.CV.Util
Imports Emgu.CV.Structure
Public Class Form1
Dim capturez As Capture = New Capture("rtsp://username:password@[IP Address]/mpeg4/media.amp")
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim imagez As Image(Of Bgr, Byte) = capturez.QueryFrame()
PictureBox1.Image = imagez.ToBitmap()
End Sub
End Class
来源:https://stackoverflow.com/questions/15934961/connect-to-ip-camera-using-emgu-cvs-capture-new-capture