Reputation: 429
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:
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:
Dim image As Image(Of Bgr, Byte) = capturez.QueryFrame()
And I know that the method QueryFrame() has 3 ways of use:
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)
I am trying to do this:
Dim image As Image(Of Bgr, Byte) = capturez.QueryFrame("rtsp://192.168.1.3/img/video.sav")
Many people say that this works, but not for me. I've seen in other forums also this:
Dim image As Image(Of Bgr, Byte) = capturez.QueryFrame("rtsp://user:[email protected]/img/video.sav")
In case that the IP camera has an user and password attached (which is my case), but still doesn't work.
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)'
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.
If I am right, I dont know how to save that image taken by the Capture.QueryFrame()
If I'm not right, then I don't know why I am getting that error.
I have seen other people using things like this:
Dim image As Image(Of Bgr, Byte) = capturez.QueryFrame("http://192.168.1.3:port/img/video.sav")
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.
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.
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
To finish, if it is possible, could someone tell me what means that
../img/video.sav
that everybody put in the string? It is a directory I must have in my computer or something like this?
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:
Private Sub StartButtonTimer_Tick() Handles StartButtonTimer.Tick
Dim X As Integer
Dim Y As Integer
If timeLeft > 0 Then
timeLeft -= 1
timeLabel.Text = timeLeft & " 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 >= 200 And pixelColor.Blue <= 255) And
(pixelColor.Green >= 200 And pixelColor.Green <= 255) And
(pixelColor.Red >= 200 And pixelColor.Red <= 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
Thanks a lot for any help!! I am getting crazy with this!!
EDIT: 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.
This is the thread: http://emgu.com/forum/viewtopic.php?t=4199
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:
// 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 );
}
}
I am studying how it works, but I don't understand why it use this lines in that way:
"http://195.243.185.195/axis-cgi/mjpg/video.cgi?camera=4",
"http://195.243.185.195/axis-cgi/mjpg/video.cgi?camera=3",
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:
"http://192.168.1.3/axis-cgi/mjpg/video.cgi?camera=4"
But, about the rest of the line, i mean, this:
.../axis-cgi/mjpg/video.cgi?camera=4
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?
EDIT: 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?
Thanks a lot!!
Tools I am using: EmguCV 2.4.0, vs2012, IP Camera: ETROVISION EV6131HW, Visual Basic
Upvotes: 0
Views: 5953
Reputation: 429
LAST EDIT - SOLUTION: Hi everyone! Finally I get the solution for al my questions, so I post it here if someone could see this useful.
About my first question, where I ask about the url inside of the method QUeryFrame():
Dim image As Image(Of Bgr, Byte) = capturez.QueryFrame("rtsp://192.168.1.3/img/video.sav")
I have read a lot about this and my conclusion is that this url is specified by the manufacturer, usually is specified in the datasheet of the camera, so it is neither an invented url, nor a folder were the image is stored. To see an example, you can see in the url below, some of the urls used by different cameras:
Link for url of different cameras
So, writting only the specifid url of the camera inside of the declaration of the variable, must be enough to achieve the connection with your camera. I achieve this by using an Axis camera, checking its datasheet. In my case, was this url:
Dim capturez As Capture
capturez = New Capture("rtsp://192.168.0.90/axis-media/media.amp?videocodec=H264")
For the next question I did:
If I am right, I dont know how to save that image taken by the Capture.QueryFrame()
It is easy. The image returned by the QueryFrame method, must be stored in a variable of type Image, like this:
Dim img As Image(Of Bgr, Byte) = capturez.QueryFrame
PictureBox1.Image = img.ToBitmap()
'If you want to store the image of the PictureBox
PictureBox1.Image.Save("f:\picture.bmp")
'If you want to store the image stored in the variable img
imageToProcess.Save("f:\picture.bmp")
The file stored, must have the extension .bmp, because what you are storing is a bitmap image (I am not sure at all about this so if someone can confirm, i will edit this if needed)
About what i said here:
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.
It is not necessary to have the camera or the computer connected to internet to achieve this. You can do it by using internet, of course, but if you have your camera connected in the same network of your computer, or connected directly by Ethernet cable no using a switch or router, it will be enough by changing the IP address of your computer or the IP address of your camera to have them working in the same network (in the case of the computer, using an static IP). For example:
IP address PC: 192.168.0.2 IP address camera: 192.168.0.3
You can change the IP address of your camera in its settings using the software provided by its manufacturer, and the IP address of your computer by going to the Network and Sharing Center of your PC.
About the next question:
To finish, if it is possible, could someone tell me what means that
../img/video.sav
This is answered above, where I explained that this line is part of the url provided by the manufacturer.
About what I asked here:
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:
I didn't need it finally, but the code shown there could be useful if someone has more that one camera, so using this url:
"http://195.243.185.195/axis-cgi/mjpg/video.cgi?camera=4",
"http://195.243.185.195/axis-cgi/mjpg/video.cgi?camera=3"
In this part:
?camera=3
You will be specifying the camera you are going to use. The rest of the string, is the url provided by the manufacturer.
i HOPE THIS HELP SOMEONE, i HAVE SPENT A LOT OF TIME IN THIS AND I AM VERY PROUD TO GET IT, SO IF SOMEONE HAS ANY QUESTION, AND I COULDBE USEFUL, DON'T HESITATE TO ASK ME IN THIS THREAD OR BY DIRECT MESSAGE.
Thanks to everyone!
Upvotes: 1