/// <summary> /// Connects to the camera /// </summary> public void Init(long hPictureBox) { m_PictureBoxHwnd = hPictureBox; // if opened before, close now if (m_uc480.IsOpen()) { m_uc480.ExitCamera(); } // open a camera int nRet = m_uc480.InitCamera(0, (int)hPictureBox); if (nRet == uc480.IS_STARTER_FW_UPLOAD_NEEDED) { throw new Exception("The camera requires starter firmware upload"); } if (nRet != uc480.IS_SUCCESS) { throw new Exception("Camera init failed"); } uc480.SENSORINFO sensorInfo = new uc480.SENSORINFO(); m_uc480.GetSensorInfo(ref sensorInfo); // Set the image size int x = 0; int y = 0; unsafe { int nAOISupported = -1; IntPtr pnAOISupported = (IntPtr)((uint*)&nAOISupported); bool bAOISupported = true; // check if an arbitrary AOI is supported //if (m_uc480.ImageFormat(uc480.IMGFRMT_CMD_GET_ARBITRARY_AOI_SUPPORTED, pnAOISupported, 4) == uc480.IS_SUCCESS) //{ // bAOISupported = (nAOISupported != 0); //} // If an arbitrary AOI is supported -> take maximum sensor size if (bAOISupported) { x = 800;// sensorInfo.nMaxWidth; y = 600;// sensorInfo.nMaxHeight; } // Take the image size of the current image format else { x = m_uc480.SetImageSize(uc480.IS_GET_IMAGE_SIZE_X, 0); y = m_uc480.SetImageSize(uc480.IS_GET_IMAGE_SIZE_Y, 0); } m_uc480.SetImageSize(x, y); } // alloc images m_uc480.ClearSequence(); int nLoop = 0; for (nLoop = 0; nLoop < IMAGE_COUNT; nLoop++) { // alloc memory m_uc480.AllocImageMem(x, y, 32, ref m_Uc480Images[nLoop].pMemory, ref m_Uc480Images[nLoop].MemID); // add our memory to the sequence m_uc480.AddToSequence(m_Uc480Images[nLoop].pMemory, m_Uc480Images[nLoop].MemID); // set sequence number m_Uc480Images[nLoop].nSeqNum = nLoop + 1; } m_uc480.SetColorMode(uc480.IS_SET_CM_RGB32); m_uc480.EnableMessage(uc480.IS_FRAME, (int)m_Hwnd); //btnInit.Enabled = false; //btnExit.Enabled = true; //btnLive.Enabled = true; //btnFreeze.Enabled = true; //UpdateInfos(); //// free image //if (DisplayWindow.Image != null) //{ // DisplayWindow.Image.Dispose(); // DisplayWindow.Image = null; //} //m_uc480.SetExternalTrigger(uc480.IS_SET_TRIG_SOFTWARE); //m_uc480.CaptureVideo(uc480.IS_WAIT); // capture a single image m_uc480.FreezeVideo(uc480.IS_WAIT); m_bIsStarted = false; //Refresh(); }
/// <summary> /// Connects to the camera /// </summary> public void Init(long hPictureBox) { m_PictureBoxHwnd = hPictureBox; // if opened before, close now if (m_uc480.IsOpen()) { m_uc480.ExitCamera(); } // open a camera int nRet = m_uc480.InitCamera(0, (int)hPictureBox); if (nRet == uc480.IS_STARTER_FW_UPLOAD_NEEDED) { throw new Exception("The camera requires starter firmware upload"); } if (nRet != uc480.IS_SUCCESS) { throw new Exception("Camera init failed"); } uc480.SENSORINFO sensorInfo = new uc480.SENSORINFO(); m_uc480.GetSensorInfo(ref sensorInfo); // Set the image size int x = 0; int y = 0; unsafe { m_uc480.SetImageSize(800, 600); } // alloc images m_uc480.ClearSequence(); int nLoop = 0; for (nLoop = 0; nLoop < IMAGE_COUNT; nLoop++) { // alloc memory m_uc480.AllocImageMem(x, y, 32, ref m_Uc480Images[nLoop].pMemory, ref m_Uc480Images[nLoop].MemID); // add our memory to the sequence m_uc480.AddToSequence(m_Uc480Images[nLoop].pMemory, m_Uc480Images[nLoop].MemID); // set sequence number m_Uc480Images[nLoop].nSeqNum = nLoop + 1; } double enable = 1, zero = 0; m_uc480.SetColorMode(uc480.IS_SET_CM_RGB32); m_uc480.EnableMessage(uc480.IS_FRAME, (int)m_Hwnd); m_uc480.SetBadPixelCorrection(uc480.IS_BPC_ENABLE_SOFTWARE, 1); //trying to set bad pixel correction, needs to be studied more. m_uc480.SetPixelClock(30); m_uc480.SetAutoParameter(uc480.IS_SET_ENABLE_AUTO_WHITEBALANCE, ref enable, ref zero); m_uc480.SetAutoParameter(uc480.IS_SET_ENABLE_AUTO_GAIN, ref enable, ref zero); m_uc480.FreezeVideo(uc480.IS_WAIT); m_bIsStarted = false; }
/// <summary> /// Connects to the camera /// </summary> public void Init(long hPictureBox) { m_PictureBoxHwnd = hPictureBox; // if opened before, close now if (m_uc480.IsOpen()) { m_uc480.ExitCamera(); } // open a camera int nRet = m_uc480.InitCamera(0, (int)hPictureBox); if (nRet == uc480.IS_STARTER_FW_UPLOAD_NEEDED) { throw new Exception("The camera requires starter firmware upload"); } if (nRet != uc480.IS_SUCCESS) { throw new Exception("Camera init failed"); } uc480.SENSORINFO sensorInfo = new uc480.SENSORINFO(); m_uc480.GetSensorInfo(ref sensorInfo); // Set the image size int x = 0; int y = 0; unsafe { int nAOISupported = -1; IntPtr pnAOISupported = (IntPtr)((uint *)&nAOISupported); bool bAOISupported = true; // check if an arbitrary AOI is supported //if (m_uc480.ImageFormat(uc480.IMGFRMT_CMD_GET_ARBITRARY_AOI_SUPPORTED, pnAOISupported, 4) == uc480.IS_SUCCESS) //{ // bAOISupported = (nAOISupported != 0); //} // If an arbitrary AOI is supported -> take maximum sensor size if (bAOISupported) { x = 800; // sensorInfo.nMaxWidth; y = 600; // sensorInfo.nMaxHeight; } // Take the image size of the current image format else { x = m_uc480.SetImageSize(uc480.IS_GET_IMAGE_SIZE_X, 0); y = m_uc480.SetImageSize(uc480.IS_GET_IMAGE_SIZE_Y, 0); } m_uc480.SetImageSize(x, y); } // alloc images m_uc480.ClearSequence(); int nLoop = 0; for (nLoop = 0; nLoop < IMAGE_COUNT; nLoop++) { // alloc memory m_uc480.AllocImageMem(x, y, 32, ref m_Uc480Images[nLoop].pMemory, ref m_Uc480Images[nLoop].MemID); // add our memory to the sequence m_uc480.AddToSequence(m_Uc480Images[nLoop].pMemory, m_Uc480Images[nLoop].MemID); // set sequence number m_Uc480Images[nLoop].nSeqNum = nLoop + 1; } m_uc480.SetColorMode(uc480.IS_SET_CM_RGB32); m_uc480.EnableMessage(uc480.IS_FRAME, (int)m_Hwnd); //btnInit.Enabled = false; //btnExit.Enabled = true; //btnLive.Enabled = true; //btnFreeze.Enabled = true; //UpdateInfos(); //// free image //if (DisplayWindow.Image != null) //{ // DisplayWindow.Image.Dispose(); // DisplayWindow.Image = null; //} //m_uc480.SetExternalTrigger(uc480.IS_SET_TRIG_SOFTWARE); //m_uc480.CaptureVideo(uc480.IS_WAIT); // capture a single image m_uc480.FreezeVideo(uc480.IS_WAIT); m_bIsStarted = false; //Refresh(); }