private static int init_camera(int system_count, ref BGAPI.System[] externppSystem, ref int pCurrSystem, ref BGAPI.Camera externppCamera) { int res = BGAPI.Result.FAIL; int i = 0; int cam = 0; int[] cameras = new int[system_count]; int camera_count = 0; BGAPI.BGAPI_FeatureState state = new BGAPI_FeatureState(); BGAPI.BGAPIX_CameraInfo cameradeviceinfo = new BGAPIX_CameraInfo(); int inputVal = 0; for (i = 0; i < system_count; i++) { //this is an example how to count available cameras for all available systems res = externppSystem[i].countCameras(ref cameras[i]); if (res != BGAPI.Result.OK) { MessageBox.Show(string.Format("countCameras Systemnumber {0} Errorcode: {1}\n", i, res)); return(0); } for (cam = 0; cam < cameras[i]; cam++) { camera_count++; //this is an example how to create a camera res = externppSystem[i].createCamera(cam, ref externppCamera); if (res != BGAPI.Result.OK) { MessageBox.Show(string.Format("\n")); MessageBox.Show(string.Format("createCamera Systemnumber {0} Errorcode: {1}\n", i, res)); return(res); } //this is an example how to get the device information for a camera res = externppCamera.getDeviceInformation(ref state, ref cameradeviceinfo); if (res != BGAPI.Result.OK) { MessageBox.Show(string.Format("\n")); MessageBox.Show(string.Format("getDeviceInformation Errorcode: {0}\n", res)); return(0); } MessageBox.Show(string.Format("{0} select Camera {1} of system {2} - {3} SN: {4}\n", camera_count, cam, i, cameradeviceinfo.modelName, cameradeviceinfo.serialNumber)); externppSystem[i].releaseCamera(ref externppCamera); } } do { //[TODO] CUSTOM SELECTOR inputVal = 1; //inputVal = Convert.ToInt32(Console.ReadLine(), 10); }while (inputVal < 0 || inputVal > camera_count); camera_count = 0; for (i = 0; i < system_count; i++) { for (cam = 0; cam < cameras[i]; cam++) { camera_count++; if (camera_count == inputVal) { pCurrSystem = i; //this is an example how to create a camera res = externppSystem[pCurrSystem].createCamera(cam, ref externppCamera); if (res != BGAPI.Result.OK) { MessageBox.Show(string.Format("createCamera Systemnumber {0} Errorcode: {1}\n", i, res)); return(res); } //this is an example how to open a camera res = externppCamera.open(); if (res != BGAPI.Result.OK) { MessageBox.Show(string.Format("open Systemnumber {0} Errorcode: {1}\n", i, res)); return(res); } break; } } } return(res); }
/// <summary> /// Camera 초기화 진행함 /// </summary> /// <param 카메라 번호="iCamNo"></param> /// <param 상위 GigE System="pSystem"></param> /// <returns></returns> public int Initialize(int iCamNo, BGAPI.System pSystem) { m_iCamID = iCamNo; // System 을 받아옴. m_CamSystem = pSystem; m_CamDeviceInfo = new BGAPI.BGAPIX_CameraInfo(); m_CamImage = new BGAPI.Image(); // create camera m_iResult = m_CamSystem.createCamera(iCamNo, ref m_Camera); if (m_iResult != BGAPI.Result.OK) { //"System create camera failed!" return(GenerateErrorCode(ERR_VISION_CAMERA_CREATE_FAIL)); } // get camera device information m_iResult = m_Camera.getDeviceInformation(ref m_CamState, ref m_CamDeviceInfo); m_cCameraData.m_CamDeviceInfo = m_CamDeviceInfo; if (m_iResult != BGAPI.Result.OK) { // "Camera get Device Information failed!" return(GenerateErrorCode(ERR_VISION_CAMERA_GET_INFO_FAIL)); } // get camera Image information m_iResult = m_Camera.getImageFormatDescription(1, ref m_CamImageInfo); if (m_iResult != BGAPI.Result.OK) { // "Camera get Device Information failed!" return(GenerateErrorCode(ERR_VISION_CAMERA_GET_INFO_FAIL)); } else { // Camera Pixel Size을 적용한다. m_CamPixelSize.Width = (int)(m_CamImageInfo.iScaleRoiX * m_CamImageInfo.iSizeX); m_CamPixelSize.Height = (int)(m_CamImageInfo.iScaleRoiY * m_CamImageInfo.iSizeY); } // camera open m_iResult = m_Camera.open(); if (m_iResult != BGAPI.Result.OK) { //"Camera open failed!" return(GenerateErrorCode(ERR_VISION_CAMERA_CONNECT_FAIL)); } // image create m_iResult = BGAPI.EntryPoint.createImage(ref m_CamImage); if (m_iResult != BGAPI.Result.OK) { // Create Image failed return(GenerateErrorCode(ERR_VISION_CAMERA_CREATE_IMAGE_FAIL)); } // camera & image connect m_iResult = m_Camera.setImage(ref m_CamImage); if (m_iResult != BGAPI.Result.OK) { // Camera set Image failed! return(GenerateErrorCode(ERR_VISION_CAMERA_GET_IMAGE_FAIL)); } // System Init 결과 저장 m_iResult = SUCCESS; return(SUCCESS); }