Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

Onvif IP camera remote configuration in C#

C# camera software onvif remote example sdk ip network ptz

  • Please log in to reply

#1
curt.copeland

curt.copeland

    New Member

  • Member
  • Pip
  • 1 posts
Hi there,
 
 
I couple of weeks ago we have installed a new security IP camera (EasyN 187V). In addition to the basic functionalities, it supports Onvif and it has some special features (PTZ, built-in microphone, night vision, motion detection, alarm notification, etc.). 
 
The long and short of it, this is a smart device, but we need some further functionalities, because my boss travels a lot and he wants more control over the surveillance system. I'm in charge of finding out a solution that enables remote configuration.
 
I've done some research and I came across a Codeproject guide that informed me that an Onvif-compliant camera SDK would be the most effective solution. (I'm not secure in my knowledge, so I need some confirmation.)
 
So the point is that I checked out the camera SDK that was recommended by the article, and I found a good Onvif C# example on how to configure the IP camera's network settings. 
 
I thought it's worth to share the code snippet related to this issue, because it can be useful for others as well, so if you'are also interested in the remote configuration, take a look at the code below:
 
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using Ozeki.Media.MediaHandlers;
using Ozeki.Media.MediaHandlers.IPCamera;
using Ozeki.Media.MediaHandlers.IPCamera.Types;
using Ozeki.Media.MediaHandlers.Video;
using Ozeki.Media.IPCamera;
using Ozeki.Media.IPCamera.Network;
using Ozeki.Media.Video;
using Ozeki.Media.Video.Controls;


namespace ConfigureOnvifCameraRemotely07
{
    public partial class Form1 : Form
    {
        private IIPCamera _camera;
        private DrawingImageProvider _imageProvider;
        private MediaConnector _connector;
        private VideoViewerWF _videoViewerWf;


        private List<int> _ports;


        public Form1()
        {
            InitializeComponent();
            _ports = new List<int>();
            _connector = new MediaConnector();
            _imageProvider = new DrawingImageProvider();
            _videoViewerWf = new VideoViewerWF();
            SetVideoViewer();
        }


        private void SetVideoViewer()
        {
            CameraBox.Controls.Add(_videoViewerWf);
            _videoViewerWf.Size = new Size(260, 180);
            _videoViewerWf.BackColor = Color.Black;
            _videoViewerWf.TabStop = false;
            _videoViewerWf.FlipMode = FlipMode.None;
            _videoViewerWf.Location = new Point(30, 30);
            _videoViewerWf.Name = "_videoViewerWf";
        }


        private void button_Connect_Click(object sender, EventArgs e)
        {
            _camera = IPCameraFactory.GetCamera("192.168.115.175:8080", "admin", "admin");


            _camera.CameraStateChanged += _camera_CameraStateChanged;


            _connector.Connect(_camera.VideoChannel, _imageProvider);
            _videoViewerWf.SetImageProvider(_imageProvider);
            _videoViewerWf.Start();


            _camera.Start();
        }


        private void _camera_CameraStateChanged(object sender, CameraStateEventArgs e)
        {
            if (e.State == IPCameraState.Streaming)
            {
                InvokeGuiThread(() => groupBox_Network.Enabled = true);
                ClearGUI();
                GetNetworkSettings();
                if (!_camera.NetworkManager.DefaultConfig.UseDHCP)
                    InvokeGuiThread(() => radioButton_Manual.Checked = true );
            }
        }


        private void ClearGUI()
        {
            InvokeGuiThread(() =>
            {
                textBox_IP.Text = String.Empty;
                textBox_Host.Text = String.Empty;
                textBox_Netmask.Text = String.Empty;
                textBox_Gateway.Text = String.Empty;
                textBox_DNS.Text = String.Empty;
                textBox_NTP_IP.Text = String.Empty;


                textBox_HTTP.Text = String.Empty;
                textBox_HTTPS.Text = String.Empty;
                textBox_RTSP.Text = String.Empty;
                comboBox_HTTP.Items.Clear();
                comboBox_HTTPS.Items.Clear();
                comboBox_RTSP.Items.Clear();
            });
        }


        private void GetNetworkSettings()
        {
            InvokeGuiThread(() =>
            {
                textBox_IP.Text = _camera.NetworkManager.DefaultConfig.IPAddress;
                textBox_Host.Text = _camera.NetworkManager.DefaultConfig.HostName;
                textBox_Netmask.Text = _camera.NetworkManager.DefaultConfig.Netmask;
                textBox_Gateway.Text = _camera.NetworkManager.DefaultConfig.DefaultGateway;
                textBox_DNS.Text = _camera.NetworkManager.DefaultConfig.DNS;
                textBox_NTP_IP.Text = _camera.NetworkManager.DefaultConfig.NTP.IPAddress;


                if (_camera.NetworkManager.HttpPort == null)
                    textBox_HTTP.Enabled = false;
                else
                {
                    foreach (var ports in _camera.NetworkManager.HttpPort.Port)
                    {
                        comboBox_HTTP.Items.Add(ports);
                    }
                }


                if (_camera.NetworkManager.HttpsPort == null)
                    textBox_HTTPS.Enabled = false;
                else
                {
                    foreach (var ports in _camera.NetworkManager.HttpsPort.Port)
                    {
                        comboBox_HTTPS.Items.Add(ports);
                    }
                }


                if (_camera.NetworkManager.RtspPort == null)
                    textBox_RTSP.Enabled = false;
                else
                {
                    foreach (var ports in _camera.NetworkManager.RtspPort.Port)
                    {
                        comboBox_RTSP.Items.Add(ports);
                    }
                }
            });
        }


        private void button_Apply_Click(object sender, EventArgs e)
        {
            if (radioButton_DHCP.Checked)
            {
                _camera.NetworkManager.DefaultConfig.UseDHCP = true;
            }


            if (radioButton_Manual.Checked)
            {
                _camera.NetworkManager.DefaultConfig.UseDHCP = false;


                _camera.NetworkManager.DefaultConfig.IPAddress = textBox_IP.Text;
                _camera.NetworkManager.DefaultConfig.HostName = textBox_Host.Text;
                _camera.NetworkManager.DefaultConfig.Netmask = textBox_Netmask.Text;
                _camera.NetworkManager.DefaultConfig.DefaultGateway = textBox_Gateway.Text;
                _camera.NetworkManager.DefaultConfig.DNS = textBox_DNS.Text;




                if (_camera.NetworkManager.HttpPort != null)
                {
                    _ports.Clear();
                    foreach (var item in comboBox_HTTP.Items)
                    {
                        var ports = Int32.Parse(item.ToString());
                        _ports.Add(ports);
                    }                 
                    _camera.NetworkManager.HttpPort = new CameraPort(CameraProtocolType.HTTP, true, _ports.ToArray());
                }


                if (_camera.NetworkManager.HttpsPort != null)
                {
                    _ports.Clear();
                    foreach (var item in comboBox_HTTPS.Items)
                    {
                        var ports = Int32.Parse(item.ToString());
                        _ports.Add(ports);
                    }
                    _camera.NetworkManager.HttpsPort = new CameraPort(CameraProtocolType.HTTPS, true, _ports.ToArray());
                }


                if (_camera.NetworkManager.RtspPort != null)
                {
                    _ports.Clear();
                    foreach (var item in comboBox_RTSP.Items)
                    {
                        var ports = Int32.Parse(item.ToString());
                        _ports.Add(ports);
                    }
                    _camera.NetworkManager.RtspPort = new CameraPort(CameraProtocolType.RTSP, true, _ports.ToArray());
                }
            }


            _camera.NetworkManager.ApplyConfig();
        }


        private void button_HTTP_Add_Click(object sender, EventArgs e)
        {
            if (!comboBox_HTTP.Items.Contains(textBox_HTTP.Text))
                comboBox_HTTP.Items.Add(textBox_HTTP.Text);
        }


        private void button_HTTPS_Add_Click(object sender, EventArgs e)
        {
            if (!comboBox_HTTPS.Items.Contains(textBox_HTTPS.Text))
                comboBox_HTTPS.Items.Add(textBox_HTTPS.Text);
        }


        private void button_RTSP_Add_Click(object sender, EventArgs e)
        {
            if (!comboBox_RTSP.Items.Contains(textBox_RTSP.Text))
                comboBox_RTSP.Items.Add(textBox_RTSP.Text);
        }


        private void button_HTTP_Delete_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < comboBox_HTTP.Items.Count; i++)
            {
                if (comboBox_HTTP.Items[i].ToString() == textBox_HTTP.Text)
                    comboBox_HTTP.Items.Remove(comboBox_HTTP.Items[i]);
            }
        }


        private void button_HTTPS_Delete_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < comboBox_HTTPS.Items.Count; i++)
            {
                if (comboBox_HTTPS.Items[i].ToString() == textBox_HTTPS.Text)
                    comboBox_HTTPS.Items.Remove(comboBox_HTTPS.Items[i]);
            }
        }


        private void button_RTSP_Delete_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < comboBox_RTSP.Items.Count; i++)
            {
                if (comboBox_RTSP.Items[i].ToString() == textBox_RTSP.Text)
                    comboBox_RTSP.Items.Remove(comboBox_RTSP.Items[i]);
            }
        }


        private void radioButton_Manual_CheckedChanged(object sender, EventArgs e)
        {
            groupBox_Basic.Enabled = true;
            groupBox_Ports.Enabled = true;
        }


        private void radioButton_DHCP_CheckedChanged(object sender, EventArgs e)
        {
            groupBox_Basic.Enabled = false;
            groupBox_Ports.Enabled = false;
        }


        private void InvokeGuiThread(Action action)
        {
            BeginInvoke(action);
        }
    }
}
 
It works well, but unfortunately this SDK is not free. Now I use its free trial version, but it will expire soon. Can anybody recommend me an alternative SDK to this one? Or any other C#-based suggestion would be appreciated related to remote IP camera configuration.
 
I’m looking forward to your answers here or please send me an e-mail to xxxxxxxxxxxxxxxxxx Thank you so much in advance!
 
All the best,
Curt

Edited by phillpower2, 18 October 2014 - 12:09 PM.
email address removed for security.

  • 0

Advertisements


#2
marspd

marspd

    New Member

  • Member
  • Pip
  • 1 posts

Hi Curt

Did you manage to find an alternative to the SDK you used in your tests? I have a similar issue but I can see the SDK is very expensive.

Regards

Paul


  • 0






Similar Topics


Also tagged with one or more of these keywords: C#, camera, software, onvif, remote, example, sdk, ip, network, ptz

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP