Currently My Program is able to turn on the webcam, but right now I have no idea how to turn the webcam off by code.
Here's the code I use to capture some pictures:
private void webcamStart_Click(object sender, EventArgs e)
{
image = new Capture();
image.QueryFrame();
Application.Idle += new EventHandler(FrameGrabber);
}
PS: I using emguCV
Try This,not sure may be help you
Camera.Dispose()
I think this might work for you
image.Close()
Related
I hope someone will be able to help me with my issue. i want to take a screenshot of the video at a specific time index, however when i try to change the time all i get is a blank black screen. i added buttons which play and pause, it allows me to play and pause the video, if i do that and then change the time index, i get an image. im confused as to why it doesn’t work using code. i even preform btnplay.PeformClick(); to play the video and when i do btnpause.PerformClick() to pause the video it doesn’t.
it seems that i can only get an image of the video if i have to physically hit the play and then pause button on my form, im trying to achieve this using code
private void Form1_Load(object sender, EventArgs e)
{
////////////////////LC4 VLC Settings///////////////////////////////////////////////////////////////////////////////////////////
control = new VlcControl();
var currentAssembly = Assembly.GetEntryAssembly();
var currentDirectory = new FileInfo(currentAssembly.Location).DirectoryName;
var libDirectory = new DirectoryInfo(Path.Combine(currentDirectory, "libvlc", IntPtr.Size == 4 ? "win-x86" : "win-x64"));
control.BeginInit();
control.VlcLibDirectory = libDirectory;
control.Dock = DockStyle.Fill;
control.EndInit();
panel1.Controls.Add(control);
main_form_LC4_data();
}
void main_form_LC4_data()
{
long vOut3 = 20;
playfile("path to file");
First_Frame(vOut3);
}
void playfile(string final)
{
control.SetMedia(new Uri(final).AbsoluteUri);
control.Time = 0;
control.Update();
}
void First_Frame(long vOut3)
{
control.Time = vOut3;
}
private void button9_Click(object sender, EventArgs e)
{
control.Play();
Console.WriteLine("PLAY");
}
private void button8_Click(object sender, EventArgs e)
{
control.Pause();
Console.WriteLine("PAUSE");
}
Above is my code in a nut shell
i have tried things like this
private void button10_Click(object sender, EventArgs e)
{
First_Frame(first_frame); // jump to index
}
and then calling up button10.PerformClick(); however it doesnt seem to work. once again if i physically hit the buttons on my form it works perfectly, however not in the way of coding it.
as an example :
play.PeformClick();
Pause.PeformClick();
time = vOut3;
I do hope this isnt to confusing im really stuck and am still hoping someone can help me
Thank you
A few things:
control.Update();
this does nothing.
You need to wait for the Playing event to be raised after setting the time, otherwise libvlc doesn't have the time to decode the frame and display it (setting the time is asynchronous)
Morning all,
I have a c# app where if you press a start button a dialog box will open and the OK button will be automatically pressed. The problem is I don't know how to do this.
The code is below:
private void Start_Click(object sender, EventArgs e)
{
if (captureDevice.ShowDialog(this) == DialogResult.OK)
{
var videoSource = captureDevice.VideoDevice;
FinalVideo = captureDevice.VideoDevice;
FinalVideo.NewFrame += new NewFrameEventHandler(FinalVideo_NewFrame);
FinalVideo.Start();
}
}
I have tried:
Removing the if statement to directly run whats inside it
Put DialogResult.OK = true before the if statement
CaptureDevice.DialogResult.OK = true before the if statement;
Image shows the dialogbox when start is pressed
This dialog let you select the source capturing device. If you want to bypass this dialog you should specify source device in your code. if you use AForge.Net this link help you. if not search for appropriate solution in documentation of component or library you use.
Add a new button to your form. Call it "Settings". In the event handler for this button, you roughly put the first half of what you have now for the Start button. Create a Settings object in your MainForm in which you will store the camera chosen.
private void Settings_Click(object sender, EventArgs e)
{
if (captureDevice.ShowDialog(this) == DialogResult.OK)
{
settings.VideoSource = captureDevice.VideoDevice;
}
}
private void Start_Click(object sender, EventArgs e)
{
FinalVideo = settings.VideoSource;
FinalVideo.NewFrame += new NewFrameEventHandler(FinalVideo_NewFrame);
FinalVideo.Start();
}
Hope this helps.
I have sort of found a solution to the question and it was to use:
SendKeys.Send("{ENTER}");
I used it before the if statement and it works with the Start_Click method but when i use it in a method called Start_Vid(), I get the error:
'SendKeys cannot run inside this application because the application is not handling Windows messages. Either change the application to handle messages, or use the SendKeys.SendWait method'
I have no idea why it should not work and what the error message means so should I be creating another question to have this answered or can it be solved in here do you think?
I have the the following code in a normal windows form application with EmguCV 3.1
public Form1()
{
InitializeComponent();
_capture = new Capture("http://root:pass#192.168.1.27:80/axis-cgi/mjpg/video.cgi");
_capture.ImageGrabbed += ProcessFrame;
}
private void Form1_Load(object sender, EventArgs e)
{
_capture.Start();
}
private void ProcessFrame(object sender, EventArgs e)
{
Mat image = new Mat();
_capture.Retrieve(image);
imageBox1.BackgroundImage = image.Bitmap;
}
I have tested the above link in a browser it worked, I have also tested this using iSpy it also works there but using EmguCV ProcessFrame is never reached
I have also tried to connect to the camera using Luxand and it worked well but Luxand is not free so I have to use EmguCV to do face detection & recognition
Looking at this post, try adding ?x.mjpeg after .cgi in your url.
the title may sound confusing but ill explain it better here. Im making a program which displays the webcam capture in a picturebox using the "easy web cam" external reference. If i turn on my computer, go into VS, open the project and run, it will work, displaying my webcam capture. If i stop the program and then run it again, when i try to display it, i get a popup asking me to select a video source, none of the options is even my webcam and then another popup will appear saying
"An error ocurred while capturing the video image. The video capture will now be terminated.
Object reference not set to ann instance of an object"
The only thing i can think of is that the first time its setting up the camera but when i close it im not turning it off properly so when i run it again, it wont work. anyway heres the relevant code, bare in mind if answering, im not that experienced when coding so sometimes you might have to spell stuff out
using WebCam_Capture;
namespace WindowsWebRef
{
public partial class Frm_Main : Form
{
public Frm_Main()
{
InitializeComponent();
}
WebCam webcam;
private void button1_Click(object sender, EventArgs e)
{
webcam.Start();
}
private void Frm_Main_Load(object sender, EventArgs e)
{
webcam = new WebCam();
webcam.InitializeWebCam(ref WebCamIMG);
}
And the webcam class...
class WebCam
{
private WebCamCapture webcam;
private System.Windows.Forms.PictureBox _FrameImage;
private int FrameNumber = 30;
public void InitializeWebCam(ref System.Windows.Forms.PictureBox ImageControl)
{
webcam = new WebCamCapture();
webcam.FrameNumber = ((ulong)(0ul));
webcam.TimeToCapture_milliseconds = FrameNumber;
webcam.ImageCaptured += new WebCamCapture.WebCamEventHandler(webcam_ImageCaptured);
_FrameImage = ImageControl;
}
void webcam_ImageCaptured(object source, WebcamEventArgs e)
{
_FrameImage.Image = e.WebCamImage;
}
public void Start()
{
webcam.TimeToCapture_milliseconds = FrameNumber;
webcam.Start(0);
}
Restart your computer and be sure to add in webcam.Stop(); otherwise your program will hold on to the webcam and make it unavailable to use in any other application (or a different instance of the program.)
I want to add an audio file to my form so that when any button event occurs, if anything is clicked then the audio file will play.
How can I do this?
code for adding audio?
private void playSoundFromResource(){
SoundPlayer sndPing = new SoundPlayer(SoundRes.GetType(), "Ping.wav");
sndPing.Play();
}
Well, a much more better way to write your code is to put the following code in form1.cs
private void Form1_Load(object sender, EventArgs e)
{
SoundPlayer Mcd = new SoundPlayer(#"C:\Users\Mcd\Desktop\abcd.wav");
Mcd.PlayLooping();
}