0% found this document useful (0 votes)
529 views

Webcam Coding C#

This document contains code for a C# application that uses a webcam for video capture. It defines classes for the main window form, the camera, and the webcam. The main form initializes the webcam, and allows the user to start, stop, and continue video capture. It also allows capturing individual images, saving captures, and changing resolution and device settings. The camera class is nearly identical but allows switching to a separate image processing form.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
529 views

Webcam Coding C#

This document contains code for a C# application that uses a webcam for video capture. It defines classes for the main window form, the camera, and the webcam. The main form initializes the webcam, and allows the user to start, stop, and continue video capture. It also allows capturing individual images, saving captures, and changing resolution and device settings. The camera class is nearly identical but allows switching to a separate image processing form.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

WEBCAM CAPTURE:

MODULE-1:

using System;
using System.Linq;
using System.Text;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;
using System.Collections.Generic;

namespace WinFormCharpWebCam
{

public partial class mainWinForm : Form


{
public mainWinForm()
{
InitializeComponent();
}
WebCam webcam;
private void mainWinForm_Load(object sender, EventArgs e)
{
webcam = new WebCam();
webcam.InitializeWebCam(ref imgVideo);
}

private void bntStart_Click(object sender, EventArgs e)


{
webcam.Start();
}

private void bntStop_Click(object sender, EventArgs e)


{
webcam.Stop();
}

private void bntContinue_Click(object sender, EventArgs e)


{
webcam.Continue();
}

private void bntCapture_Click(object sender, EventArgs e)


{
imgCapture.Image = imgVideo.Image;
}

private void bntSave_Click(object sender, EventArgs e)


{
Helper.SaveImageCapture(imgCapture.Image);
}

private void bntVideoFormat_Click(object sender, EventArgs e)


{
webcam.ResolutionSetting();
}

private void bntVideoSource_Click(object sender, EventArgs e)


{
webcam.AdvanceSetting();
}

}
}

CAMERA.cs

using System;

using System.Linq;

using System.Text;
using System.Data;

using System.Drawing;

using System.Windows.Forms;

using System.ComponentModel;

using System.Collections.Generic;

using sobel_filtering;

namespace WinFormCharpWebCam

public partial class CAMERA : Form

public CAMERA()

InitializeComponent();

WebCam webcam;

private void CAMERA_Load(object sender, EventArgs e)

webcam = new WebCam();

webcam.InitializeWebCam(ref imgVideo);
}

private void bntStart_Click(object sender, EventArgs e)

webcam.Start();

private void bntStop_Click(object sender, EventArgs e)

webcam.Stop();

private void bntContinue_Click(object sender, EventArgs e)

webcam.Continue();

private void bntCapture_Click(object sender, EventArgs e)

imgCapture.Image = imgVideo.Image;

private void bntSave_Click(object sender, EventArgs e)

{
Helper.SaveImageCapture(imgCapture.Image);

private void bntVideoFormat_Click(object sender, EventArgs e)

webcam.ResolutionSetting();

private void bntVideoSource_Click(object sender, EventArgs e)

webcam.AdvanceSetting();

private void button1_Click(object sender, EventArgs e)

Form1 an = new Form1();

an.Show();

this.Hide();

//Bitmap a = new Bitmap(imgCapture.Image);

//an.pic(a);

}
private void imgVideo_Click(object sender, EventArgs e)

WEBCAM.cs

using System;

using System.IO;

using System.Linq;

using System.Text;

using System.Collections.Generic;

using WebCam_Capture;
namespace WinFormCharpWebCam

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);

public void Stop()

webcam.Stop();

public void Continue()

// change the capture time frame

webcam.TimeToCapture_milliseconds = FrameNumber;

// resume the video capture from the stop


webcam.Start(this.webcam.FrameNumber);

public void ResolutionSetting()

webcam.Config();

public void AdvanceSetting()

webcam.Config2();

You might also like