private void button1_Click(object sender, EventArgs e) { if (CameraOpened && FSDK.FSDKE_OK != FSDKCam.CloseVideoCamera(cameraHandle)) { MessageBox.Show("Error closing camera", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); } if (FSDK.FSDKE_OK != FSDKCam.OpenIPVideoCamera(FSDKCam.FSDK_VIDEOCOMPRESSIONTYPE.FSDK_MJPEG, AddressBox.Text, UsernameBox.Text, PasswordBox.Text, 50, ref cameraHandle)) { MessageBox.Show("Error opening IP camera", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); } CameraOpened = true; }
private void startDetectToolStripMenuItem_Click(object sender, EventArgs e) { label1.Visible = true; bFirstRun = true; needClose = true; if (mThread != null) { mThread.Abort(); } if (CameraOpened) { CameraOpened = false; if (FSDK.FSDKE_OK != FSDKCam.CloseVideoCamera(cameraHandle)) { MessageBox.Show("Error closing camera", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); } } if (usbCamera) { FSDKCam.InitializeCapturing(); string[] cameraList; int count; FSDKCam.GetCameraList(out cameraList, out count); if (0 >= count) { MessageBox.Show("Please attach a camera", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); label1.Visible = false; Application.Exit(); } cameraName = cameraList[0]; FSDKCam.VideoFormatInfo[] formatList; FSDKCam.GetVideoFormatList(ref cameraName, out formatList, out count); int r = FSDKCam.OpenVideoCamera(ref cameraName, ref cameraHandle); if (r != FSDK.FSDKE_OK) { MessageBox.Show("Error opening the first camera", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); label1.Visible = false; //Application.Exit(); } else { CameraOpened = true; } } else { if (FSDK.FSDKE_OK != FSDKCam.OpenIPVideoCamera(FSDKCam.FSDK_VIDEOCOMPRESSIONTYPE.FSDK_MJPEG, ipcam_addr, ipcam_username, ipcam_password, 50, ref cameraHandle)) { MessageBox.Show("Error opening IP camera", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); label1.Visible = false; //Application.Exit(); } else { CameraOpened = true; } } needClose = false; mThread = new Thread(new ThreadStart(MainLoop)); mThread.Start(); }