WebCam Capture c# Logitech - c#

I made this program for taking an Image from my Logitech HD Pro WebCam c920.
The program actually work for Integrated Camera, but when i want to take the flow of my Logitech Webcam
i have nothing... (No image, no errors).
I wanted to know if someone have the same problems or something to help me to fix it...
My program is only for taking an picture from my WebCam logitech on c# with aForge.
I have this 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 Accord;
using AForge.Video;
using AForge.Video.DirectShow;
namespace WindowsFormsApp1
{
public partial class Webcam : Form
{
public Webcam()
{
InitializeComponent();
}
FilterInfoCollection filterInfoCollection;
VideoCaptureDevice videoCaptureDevice;
private void btnStart_Click(object sender, EventArgs e)
{
videoCaptureDevice = new VideoCaptureDevice(filterInfoCollection[cboCamera.SelectedIndex].MonikerString);
videoCaptureDevice.NewFrame += VideoCaptureDevice_NewFrame;
videoCaptureDevice.Start();
}
private void VideoCaptureDevice_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
pic.Image = (Bitmap)eventArgs.Frame.Clone();
}
private void Webcam_Load(object sender, EventArgs e)
{
filterInfoCollection = new FilterInfoCollection(FilterCategory.VideoInputDevice);
foreach(FilterInfo filterinfo in filterInfoCollection)
{
cboCamera.Items.Add(filterinfo.Name);
cboCamera.SelectedIndex = 0;
videoCaptureDevice = new VideoCaptureDevice();
}
}
private void Webcam_FormClosing(object sender, FormClosingEventArgs e)
{
if (videoCaptureDevice.IsRunning == true)
videoCaptureDevice.SignalToStop();
}
btnstart is button, cboCamera is a Combobox, and pic is a picturebox.

I had a very similar problem. While I do not know why this occurs I have tested the following solutions:
Using Media Capture API - Seem to work with all web cameras, but I had quite a bit of stability problems.
Using this Versatile WebCam C# library - Seem to work fine.
I have not tested Emgu/OpenCV, but that is another alternative.

Related

Awesomium "LoadingFrameComplete" is firing too many times

Just recently began tinkering with Awesomium, it's very cool and much better than the stock webBrowser for WinForms.
However, when I use the _LoadingFrameComplete method to determine if the page has loaded, it seems to be firing 10+ times (when used on Facebook, 2 times when navigating to google.com)
I am trying to get the comparable method of webBrowser1_DocumentCompleted (which only fires one time, after the document has completed).
Is this a 'me' problem, or am I using the wrong methods to check whether the website has finished loading completely.
I'm using Visual C# 2010 Edition
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 Debugging_Problems
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string searchURL = textBox1.Text;
webControl1.Source = new Uri(searchURL);
}
private void Awesomium_Windows_Forms_WebControl_LoadingFrameComplete(object sender, Awesomium.Core.FrameEventArgs e)
{
richTextBox1.AppendText("Completed.\n");
}
}
}
You need to use IsMainFrame
private void Awesomium_Windows_Forms_WebControl_LoadingFrameComplete(object sender, Awesomium.Core.FrameEventArgs e)
{
if (e.IsMainFrame)
{
richTextBox1.AppendText("Completed.\n");
}
}
Try putting if(e.IsMainFrame) { .... } inside your LoadingFrameComplete event handler and only put your code in there. – Jon
That was the answer. Thank you.

How to start another .exe in C# when the WinFormApp is going to be closed? [duplicate]

This question already has an answer here:
How to run code before program exit? [duplicate]
(1 answer)
Closed 4 years ago.
When a WinFromApp.exe written in C# is closing,
it finally should start another Prog.exe.
Important, the WinFromApp.exe shouldn't wait for a result of Prog.exe.
The WinFromApp.exe should completly close while Prog.exe runs.
[This is my 2nd using of this forum for place a Question.]
I still have programmed many with Dreamweaver MS-Office-VBA...
Visual Studio (2017) programming is new for me. Because of this, I need also to know where to place the code/code-part(s).
I have as From "Welcome.cs"
["++...++" in Code marks the done including from Anu Viswan.]
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.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
using Microsoft.VisualBasic;
using Microsoft.Win32;
using HardwareHelperLib;
namespace Welcome
{
public partial class Welcome : Form
{
public Welcome()
{
InitializeComponent();
+Application.ApplicationExit += Application_ApplicationExit;+
}
private void wb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
...;
}
private void wb_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
...;
}
private void Welcome_Load(object sender, EventArgs e)
{
...;
}
private void button1_Click(object sender, EventArgs e)
{
...;
}
++private void Application_ApplicationExit(object sender, EventArgs e)
{
var process = new ProcessStartInfo("notepad.exe");
Process.Start(process);
}
private void Welcome_FormClosing(object sender, FormClosingEventArgs e)
{
var process = new ProcessStartInfo("notepad.exe");
Process.Start(process);
}++
}
}
And Program.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Win32;
namespace Welcome
{
static class Program
{
/// <summary>
/// Der Haupteinstiegspunkt für die Anwendung.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Welcome());
}
}
}
I have to place this:
Application.ApplicationExit += Application_ApplicationExit;
by here [+...+], and it is working = THANK YOU VERY MUCH !!!
This question already has an answer here:
How to run code before program exit? [duplicate]
I have looked at this link, but not found the answer of my Question...
Because as I has written in my Question:
Visual Studio (2017) programming is new for me. Because of this, I need also to know where to place the code/code-part(s).
Sorry, until yesterday the last years I used stackoverflow only as a Reader.
So I am also new at stackoverflow doing Questions.
Assuming your application is WinForm app, you can do this with ApplicationExit event.
First you need to subscribe for application exit and FormClosing event.
Application.ApplicationExit += Application_ApplicationExit;
and then, in the event, you can use Process.Start to invoke the second exe.
private void Application_ApplicationExit(object sender, EventArgs e)
{
var process = new ProcessStartInfo("notepad.exe");
Process.Start(process);
}
private void Form2_FormClosing(object sender, FormClosingEventArgs e)
{
var process = new ProcessStartInfo("notepad.exe");
Process.Start(process);
}

How to import/export kml and display in gmap.net

I want to create a simple database viewer using Microsoft Visual Studio and GMaps.NET which can (1) do a specific search and update the list, (2) export the list as KML, and (3) upload the KML file to be viewed in the embedded gmap. Step 1 is already resolved but I cannot find reference to proceed with steps 2 and 3. Any help will be highly appreciated!
Here 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 GMap.NET;
using GMap.NET.WindowsForms;
using GMap.NET.WindowsForms.Markers;
using GMap.NET.MapProviders;
//if these GMap statements are not enabled, these will have to be typed with the namespaces e.g. GMap.Net.MapProviders.GoogleMap
namespace KDMI_DBViewer_v1._0
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void existingPermitsBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
this.Validate();
this.existingPermitsBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.permits_2016DataSet);
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'permits_2016DataSet.ExistingPermits' table. You can move, or remove it, as needed.
this.existingPermitsTableAdapter.Fill(this.permits_2016DataSet.ExistingPermits);
}
private void gMapControl1_Load(object sender, EventArgs e)
{
gMapControl1.MapProvider = GMapProviders.GoogleTerrainMap;
//gMapControl1.ShowCenter = false; if enabled, this will remove the red cross
gMapControl1.Position = new PointLatLng(12.0725555, 122.895494);
gMapControl1.DragButton = MouseButtons.Left;
gMapControl1.Zoom = 5;
gMapControl1.MinZoom = 5;
gMapControl1.MaxZoom = 12;
}
private void specificSearchToolStripButton_Click(object sender, EventArgs e)
{
try
{
this.existingPermitsTableAdapter.SpecificSearch(this.permits_2016DataSet.ExistingPermits, provinceToolStripTextBox.Text, municipalityToolStripTextBox.Text, typeToolStripTextBox.Text);
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
Unfortunetly, no KML parser yet implemented as the creator of GMap.Net said gmap.net issues.
But instead you can create the import \ export KML\KMZ methods yourself using a library called SharpKML
SharpKML is an implementation of the Open Geospatial Consortium (OGC)
KML 2.2 standard developed in C#, able to read/write both KML files
and KMZ files.
Getting Started:
The easiest way to use the library is to install the SharpKml.Core
NuGet package, however, you can also download the binaries/source code
from this project page.

C# , pull sites from TXT, pull datafrom website, output data to lists and CSV

Good morning guys I'm new to this place and have been having a lot of issues getting any of the findings to work.
I'm currently using C# inside visual studio community and was using a you tube video as reference but I'm stuck getting it to work efficiently (i think its in a loop) and to do other actions.
Im trying to get a list of urls from a text file in desktop or by user inputting it to a field:
EG: program opens HE puts IP in one text box and hits submit program runs and iots done.
or if it pulls a list of IP's from Desktop C: then it will add it to the website while using a loop?
eg:
my current code is similar to this as follows:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace HTTPcollect_Windows_Form_App
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
List<string> IPs = new List<string>();
WebClient web = new WebClient();
String html = web.DownloadString("http://www.ipvoid.com/scan/8.8.8.8/");
MatchCollection m1 = Regex.Matches(html, #"IP Address.*<strong>(.+?) <\/strong>", RegexOptions.Singleline);
foreach (Match m in m1)
{
string IP = m.Groups[1].Value;
IPs.Add(IP);
}
listBox1.DataSource = IPs;
}
private void label1_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}
}

How to structure speech recognition code in an executable c# WinForms App?

link to original code - please look at it first.
I'm not sure how to write this code so that it runs properly. So far my attempt:
The code in the website is using System Speech Recognition from Microsoft to record audio from microphone and turn it into text. Except, I don't know how to format that code on the website properly. The below certainly does not work. I get red underlines everywhere. I'm also not sure how 'event-handler' code is supposed to look like.
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;
using System.Speech.Recognition;
namespace SystemSpeechRecognition_winForms
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
SpeechRecognitionEngine _speechRecognitionEngine = new SpeechRecognitionEngine();
_speechRecognitionEngine.SetInputToDefaultAudioDevice();
DictationGrammar _dictationGrammar = new DictationGrammar();
_speechRecognitionEngine.LoadGrammar(_dictationGrammar);
_speechRecognitionEngine.RecognizeAsync(RecognizeMode.Multiple);
ERROR for the four lines
This is the error:
.
"delegate System.EventHandler"
"Represents the method that will handle an event that has no event data"
"Error: No overload for 'SpeechRecognized' matches delegate 'System.EventHanndler'
_speechRecognitionEngine.SpeechRecognized -= new EventHandler(SpeechRecognized);
_speechRecognitionEngine.SpeechHypothesized -= new EventHandler(SpeechHypothesizing);
_speechRecognitionEngine.SpeechRecognized += new EventHandler(SpeechRecognized);
_speechRecognitionEngine.SpeechHypothesized += new EventHandler(SpeechHypothesizing);
}
private void SpeechHypothesizing(object sender, SpeechHypothesizedEventArgs e)
{
///real-time results from the engine
string realTimeResults = e.Result.Text;
}
private void SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
///final answer from the engine
string finalAnswer = e.Result.Text;
}
}
You're having compilation issues because - to take one of the events as an example - the SpeechRecognized event is of type EventHandler<SpeechRecognizedEventArgs> and you are attempting to assign it an instance of the non-generic EventHandler class.
_speechRecognitionEngine.SpeechRecognized -= new EventHandler<SpeechRecognizedEventArgs>(SpeechRecognized);

Categories

Resources