Tugas Pertemuan 3 Capture Camera

Nama : Yusuf Hasan Nazila 

NRP : 5025211225

PBKK A


Tugas membuat Video Capture


    Tugas ini dibuat dengan Microsoft Visual Studio 2022. Dalam pembuatan Capture Camera dibuutuhkan kamera baik external maupun yang sudah terdapat di laptop. Pembuatan ini juga diperlukan library yang dapat di download di Aforge.Net. Library yang dipakai antara lain

1. Aforge.Video.dll ,

2. Aforge.dll 

 3. Aforge.VideoDirectionShow.dll

Camera Capture memiliki fitur yaitu, tombol start untuk memulai camera start, lalu ada Capture untuk menangkap gambar yang di clone dari picture box 1. Ada pula tombol switch untuk mengganti camera dipaling ujung atas kiri, serta ada tombol untuk save image untuk menyimpan gambar. Tak lupa ada tombol exit untuk keluar dari program. Cara untuk memindah camera dengan cara berikut:

1. Pilih kamera 

2. Start

3. Pilih Camera yang akan di ganti 

4. Start Kembali

Berikut adalah Dokumetasi dan Source Code

Memulai Program
Ganti Camera + Capture Sebelumnya
Save Image
Hasil Capture
Switch Ganti Camera

Capture









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;
using System.Drawing;
using System.Drawing.Imaging;
namespace Camera
{
public partial class Form1 : Form
{
private FilterInfoCollection captureDevice;
private VideoCaptureDevice videoSource;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
captureDevice = new FilterInfoCollection(FilterCategory.VideoInputDevice);
foreach (FilterInfo deviceList in captureDevice)
{
comboBoxWebcamList.Items.Add(deviceList.Name);
}
comboBoxWebcamList.SelectedIndex = 0;
videoSource = new VideoCaptureDevice();
}
private void buttonStart_Click(object sender, EventArgs e)
{
if (videoSource.IsRunning)
{
videoSource.SignalToStop();
videoSource.WaitForStop();
pictureBox1.Image = null;
pictureBox1.Invalidate();
}
videoSource = new VideoCaptureDevice(captureDevice[comboBoxWebcamList.SelectedIndex].MonikerString);
videoSource.NewFrame += new NewFrameEventHandler(VideoSource_NewFrame);
videoSource.Start();
}
private void VideoSource_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
pictureBox1.Image = (Bitmap)eventArgs.Frame.Clone();
}
private void buttonCapture_Click(object sender, EventArgs e)
{
pictureBox2.Image = (Bitmap)pictureBox1.Image.Clone();
}
private void buttonSaveImage_Click(object sender, EventArgs e)
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Title = "Save Image As";
saveFileDialog.Filter = "Image files (*.jpg, *.png | *.jpg, *.png";
ImageFormat imageFormat = ImageFormat.Png;
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
string ext = System.IO.Path.GetExtension(saveFileDialog.FileName);
switch (ext)
{
case ".jpg":
imageFormat = ImageFormat.Jpeg;
break;
case ".png":
imageFormat = ImageFormat.Png;
break;
}
pictureBox2.Image.Save(saveFileDialog.FileName, imageFormat);
}
}
private void buttonExit_Click(object sender, EventArgs e)
{
if (videoSource.IsRunning)
{
videoSource.SignalToStop();
videoSource.WaitForStop();
pictureBox1.Image = null;
pictureBox1.Invalidate();
pictureBox2.Image = null;
pictureBox2.Invalidate();
}
Application.Exit(null);
}
}
}
view raw gistfile1.txt hosted with ❤ by GitHub

Comments

Popular posts from this blog

QUIZ 1 PBKK A Yusuf Hasan Nazila 5025211225

Tugas 2 PBKK Kalkulator