User talk:Ezik
pedestrian detection with a webcam running slow
saya sedang belajar membuat program pedestrian detection dengan webcam namun saya menemukan masalah, saat program dijalankan video berjalan lambat, tolong saya untuk mengatasi masalah ini, terima kasih. source code yang saya gunakan seperti ini:
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 Emgu.CV; using Emgu.CV.Structure; using Emgu.Util; using Emgu.CV.UI; using Emgu.CV.GPU;
namespace PedestrianDetection {
public partial class CameraCapture : Form { //declaring global variables private Capture capture; //takes images from camera as image frames Boolean camFlip = true;
public CameraCapture() { InitializeComponent(); } private void ProcessFrame(object sender, EventArgs arg) { Image<Bgr, Byte> ImageFrame = capture.QueryFrame();
if (ImageFrame != null) // confirm that image is valid { Image<Gray, byte> grayframe = ImageFrame.Convert<Gray, byte>(); long processingTime; Rectangle[] results = FindPedestrian.Find(ImageFrame, out processingTime);
foreach (Rectangle rect in results) ImageFrame.Draw(rect, new Bgr(Color.Red), 10); } CamImageBox.Image = ImageFrame; }
private void btnStart_Click(object sender, EventArgs e) { if (capture != null) { if (btnStart.Text == "Pause") { //if camera is getting frames then pause the capture and set button Text to // "Resume" for resuming capture btnStart.Text = "Resume"; // Application.Idle -= ProcessFrame; } else { //if camera is NOT getting frames then start the capture and set button // Text to "Pause" for pausing capture btnStart.Text = "Pause"; Application.Idle += ProcessFrame; } } }
private void ReleaseData() { if (capture != null) capture.Dispose(); }
private void cbCamIndex_SelectedIndexChanged(object sender, EventArgs e) { //Set the camera number to the one selected via combo box int CamNumber = -1; CamNumber = int.Parse(cbCamIndex.Text);
//Start the selected camera #region if capture is not created, create it now if (capture == null) { try { capture = new Emgu.CV.Capture(CamNumber); } catch (NullReferenceException excpt) { MessageBox.Show(excpt.Message); } } #endregion
//Start showing the stream from camera btnStart_Click(sender, e); btnStart.Enabled = true; if (camFlip == true) { capture.FlipHorizontal = !capture.FlipHorizontal; camFlip = false; } } }
}