Displaying feed from ip camera using OpenCV(Emgu) - c#

I'm trying to create program which display video from IP Camera.
This is my code :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Emgu.CV; //
using Emgu.CV.CvEnum; // usual Emgu Cv imports
using Emgu.CV.Structure; //
using Emgu.CV.UI;
using System.IO;
using System.Reflection;
using System.Windows;
using System.Runtime.InteropServices;
using Emgu.Util;
using System.Net;
namespace WindowsFormsApplication1
{
public partial class Main : Form
{
public Main()
{
InitializeComponent();
}
public Capture _capture;
public Mat imgOriginal;
private void imageBox2_Click(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
public void button1_Click(object sender, EventArgs e)
{
_capture = new Capture("http://192.168.1.148:8080/video");
_capture.ImageGrabbed += ProcessFrame;
_capture.Start();
}
public void ProcessFrame(object sender, EventArgs arg)
{
imgOriginal= _capture.QueryFrame();
ibOriginal.Image = imgOriginal;
}
}
}
It's getting stuck on this step (without expectation):
imgOriginal= _capture.QueryFrame();
Maybe i should you invoke method but i don't know how.
Im using Emgu 3.1.0 Link to Doc

I managed to troubleshoot this . I made some canonical and syntax mistakes.
I provide working code for community:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Emgu.CV; //
using Emgu.CV.CvEnum; // usual Emgu Cv imports
using Emgu.CV.Structure; //
using Emgu.CV.UI;
using System.IO;
using System.Reflection;
using System.Windows;
using System.Runtime.InteropServices;
using Emgu.Util;
using System.Net;
namespace WindowsFormsApplication1
{
public partial class Main : Form
{
public Main()
{
InitializeComponent();
Run();
}
public Capture _capture;
public Mat imgOriginal;
private void imageBox2_Click(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
void Run()
{
try
{
_capture = new Capture("http://192.168.1.148:8080/video");
}
catch (Exception e)
{
MessageBox.Show(e.Message);
return;
}
Application.Idle += ProcessFrame;
}
void ProcessFrame(object sender, EventArgs e)
{
Mat frame = _capture.QueryFrame();
ibOriginal.Image = frame;
}
public void button1_Click(object sender, EventArgs e)
{
}
}
}

Related

LostFocus txtBox.text changed by a button

what I'm trying to do is to change the text of the "last" lost focussed TxtBox by using a button. I know about the LostFocus method, but what are the actual paramaters that we have to give to that fuction?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.IO;
namespace WindowsFormsApp2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
// this.ActiveControl = textBox2;
}
private Control _focusedControl;
private void button1_Click(object sender, EventArgs e)
{
SubmitData();
}
private void SubmitData()
{
if (_focusedControl != null)
{
_focusedControl.Text = "hi";
}
}
private void TextBox2_GotFocus(object sender, EventArgs e)
{
MessageBox.Show("Got focus.");
_focusedControl = (Control)sender;
}
}
}
So, what is happening is, no messagebox is popping and the _focusedCOntrol varable doesn't contain the last focus.

Real time web camera and capture frame from webcam

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using AForge;
using AForge.Video;
using AForge.Video.DirectShow;
namespace Sample
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private FilterInfoCollection CaptureDevice;
private VideoCaptureDevice FinalFrame;
private void Form1_Load(object sender, EventArgs e)
{
CaptureDevice = new FilterInfoCollection(FilterCategory.AudioCompressorCategory);
foreach (FilterInfo Device in CaptureDevice)
{
comboBox1.Items.Add(Device.Name);
}
comboBox1.SelectedIndex = 0;
FinalFrame = new VideoCaptureDevice();
}
private void button1_Click(object sender, EventArgs e)
{
FinalFrame = new VideoCaptureDevice(CaptureDevice[comboBox1.SelectedIndex].MonikerString);
FinalFrame.NewFrame+= new NewFrameEventHandler (FinalFrame_NewFrame);
FinalFrame.Start();
}
private void FinalFrame_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
pictureBox1.Image = (Bitmap)eventArgs.Frame.Clone();
}
}
}
This code is used to getting for open my web camera, this code is worked properly. I want to add a little code part to convert REAL TIME VIDEO into GRAY-SCALE VIDEO, if anyone knows the algorithm, Please help me to do that.

How can i parse some java script part from a web page as text to a text file?

The web page is:
Google Tennis Results
What i'm trying to get as text is the tennis results in the top of the page.
Tried using webBrowser now but not getting it at all.
Not sure if it's also java script in the page or not but i can't parse it.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Net;
using System.Threading;
using System.Runtime.InteropServices;
namespace Test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
test1();
}
private void test1()
{
this.webBrowser1.ObjectForScripting = new MyScript();
}
[ComVisible(true)]
public class MyScript
{
public void CallServerSideCode()
{
var doc = ((Form1)Application.OpenForms[0]).webBrowser1.Document;
var renderedHtml = doc.GetElementsByTagName("HTML")[0].OuterHtml;
}
}
private void Form1_Load(object sender, EventArgs e)
{
webBrowser1.Navigate("https://www.google.co.il/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=australian%20open%20atp");
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
webBrowser1.Navigate("javascript: window.external.CallServerSideCode();");
}
}
}

inherit textBox_MouseMove event from class in form1 c#

I have created class in which i have defined methods which i need to call in forms .I need to call this methods from class Test in many forms.Below is my code how i try, but without success.I dont see here where i'm wrong.
//class Test.cs
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Printing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Linq;
namespace Restaurant
{
public class Test : Form
{
public void MouseMove(object sender, MouseEventArgs e)
{
TextBox txt = sender as TextBox;
foreach (TextBox text in this.Controls.OfType<TextBox>())
{
if (e.Button == MouseButtons.Left)
{
if (txt.Name == text.Name)
{
txt.Left = e.X + txt.Left - MouseDownLocation.X;
txt.Top = e.Y + txt.Top - MouseDownLocation.Y;
}
}
}
}
public void MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
MouseDownLocation = e.Location;
}
}
}
}
// form in which i need to call methods from Test class
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Printing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Linq;
namespace Restaurant
{
public partial class Form1 : Test
{
public Form1()
{
InitializeComponent();
}
private void textBox_MouseMove(object sender, MouseEventArgs e)
{
Test b = new Test();
b.MouseMove1(sender,e);
}
private void textBox_MouseDown(object sender, MouseEventArgs e)
{
Test b = new Test();
b.MouseDown(sender,e);
}
}
}
Since Form1 inherits from Test, you should be able to change Form1 as follows:
private void textBox_MouseMove(object sender, MouseEventArgs e)
{
MouseMove1(sender,e);
}
This way you are calling the method on the form you are on, rather than a new form that you are instantiating and acting against in your code sample.

C# web browser randomly freezes when trying to login to check e-mail?

I have a C# Web Browser, I am trying to access: my.screenname.aol.com for mail, but it won't even load, I don't have much code...as you can see:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace EmailViewer
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
timer1.Enabled = false;
webBrowser1.Navigate("my.screenname.aol.com");
}
}
}
It's worth a shot to try WebBrowser.ScriptErrorsSuppressed Property to true.

Categories