private void btnVideo_Click(object sender, EventArgs e) { double vidWidth, vidHeight; if (btnVideo.Text.Equals("Start Video")) { train_data(); videoCapture = highgui.CvCreateCameraCapture(0); //check bila valid if (videoCapture.ptr == IntPtr.Zero) { MessageBox.Show("Pengambilan gambar gagal"); return; } btnVideo.Text = "Stop Video"; highgui.CvSetCaptureProperty(ref videoCapture, highgui.CV_CAP_PROP_FRAME_WIDTH, 640); highgui.CvSetCaptureProperty(ref videoCapture, highgui.CV_CAP_PROP_FRAME_HEIGHT, 320); highgui.CvQueryFrame(ref videoCapture); vidWidth = highgui.cvGetCaptureProperty(videoCapture, highgui.CV_CAP_PROP_FRAME_WIDTH); vidHeight = highgui.cvGetCaptureProperty(videoCapture, highgui.CV_CAP_PROP_FRAME_HEIGHT); picBoxMain.Width = (int)vidWidth; picBoxMain.Height = (int)vidHeight; WriteLine("Pengambilan gambar dari webcam dengan resolusi: " + vidWidth.ToString() + " x " + vidHeight.ToString(), true, false); timerGrab.Interval = 42; timerFPS.Interval = 1100; timerGrab.Enabled = true; timerFPS.Enabled = true; hc = new HaarClassifier(this); abs = new AbsDiff(this); } else { btnVideo.Text = "Start Video"; timerFPS.Enabled = false; timerGrab.Enabled = false; if (videoCapture.ptr != IntPtr.Zero) { highgui.CvReleaseCapture(ref videoCapture); videoCapture.ptr = IntPtr.Zero; } } }