#include "OPTCamera.h" #include #include #include "../config/ConfigManager.h" #include #include #include "../SystemInfo.h" #include "../utils/MathHelper.h" OPTCamera::OPTCamera() :HBDCamera() , m_System(NULL) , m_Camera(NULL) , m_StreamSource(NULL) , m_IsCatpure(false) , m_IsConnect(false) , m_EventSubscribe(NULL) { InitializeCriticalSection(&m_ConnectCS); } OPTCamera::~OPTCamera() { StopCamera(); if (m_EventSubscribe)m_EventSubscribe->unsubscribeConnectArgsEx(m_EventSubscribe, OnDeviceLinkNotify, (void*)this); if (m_StreamSource)m_StreamSource->detachGrabbingEx(m_StreamSource, OnGetFrame, (void*)this); if (m_StreamSource)m_StreamSource->stopGrabbing(m_StreamSource); ReleaseSource(); if (m_OriginalData)delete[] m_OriginalData; DeleteCriticalSection(&m_ConnectCS); Uninit(); } void OPTCamera::Uninit() { if (m_System)m_System->release(m_System); m_System = NULL; } bool OPTCamera::Init() { int32_t ret = 0; ret = GENICAM_getSystemInstance(&m_System); if (-1 == ret) { return false; } return true; } void OPTCamera::ReleaseSource() { if (m_EventSubscribe != NULL) { m_EventSubscribe->unsubscribeConnectArgsEx(m_EventSubscribe, OnDeviceLinkNotify, (void*)this); m_EventSubscribe->release(m_EventSubscribe); m_EventSubscribe = NULL; } if (m_StreamSource != NULL) { m_StreamSource->release(m_StreamSource); m_StreamSource = NULL; } if (m_Camera != NULL) { m_Camera->disConnect(m_Camera); m_Camera->release(m_Camera); m_Camera = NULL; } } bool OPTCamera::ConnectCamera() { ReleaseSource(); uint32_t cameraCnt = 0; DeviceInfo* pDeviceInfoList = NULL; if (m_System->enumDevicesInfo(m_System, &pDeviceInfoList, &cameraCnt, typeAll) < 0) { return false; } if (cameraCnt == 0) { return false; } DeviceInfo *pDeviceInfo = &pDeviceInfoList[0]; if (m_System->createDevice(m_System, pDeviceInfo, &m_Camera) < 0) { return false; } if (m_Camera->connect(m_Camera, accessPermissionControl) < 0) { ReleaseSource(); return false; } GENICAM_AcquisitionControl *pAcquisitionCtrl = NULL; GENICAM_AcquisitionControlInfo acquisitionControlInfo = { 0 }; acquisitionControlInfo.pCamera = m_Camera; GENICAM_createAcquisitionControl(&acquisitionControlInfo, &pAcquisitionCtrl); if (m_ExtCfg->m_IsExposureAuto) { GENICAM_EnumNode exposureNode; exposureNode = pAcquisitionCtrl->exposureAuto(pAcquisitionCtrl); exposureNode.setValue(&exposureNode, 2); exposureNode.release(&exposureNode); } else { GENICAM_EnumNode exposureNode; exposureNode = pAcquisitionCtrl->exposureAuto(pAcquisitionCtrl); exposureNode.setValue(&exposureNode, 0); exposureNode.release(&exposureNode); GENICAM_DoubleNode doubleNode; doubleNode = pAcquisitionCtrl->exposureTime(pAcquisitionCtrl); doubleNode.setValue(&doubleNode, m_ExtCfg->m_ExposureTime); doubleNode.getValue(&doubleNode, &m_ExtCfg->m_ExposureTime); doubleNode.release(&doubleNode); } if (m_ExtCfg->m_FrameRateEnable) { GENICAM_BoolNode frameRateEnableNode; frameRateEnableNode = pAcquisitionCtrl->acquisitionFrameRateEnable(pAcquisitionCtrl); frameRateEnableNode.setValue(&frameRateEnableNode, 1); frameRateEnableNode.release(&frameRateEnableNode); GENICAM_DoubleNode frameRateNode; frameRateNode = pAcquisitionCtrl->acquisitionFrameRate(pAcquisitionCtrl); frameRateNode.setValue(&frameRateNode, m_ExtCfg->m_FrameRate); frameRateNode.release(&frameRateNode); } else { GENICAM_BoolNode frameRateEnableNode; frameRateEnableNode = pAcquisitionCtrl->acquisitionFrameRateEnable(pAcquisitionCtrl); frameRateEnableNode.setValue(&frameRateEnableNode, 0); frameRateEnableNode.release(&frameRateEnableNode); } pAcquisitionCtrl->release(pAcquisitionCtrl); pAcquisitionCtrl = NULL; GENICAM_ImageFormatControlInfo IFControlInfo = { 0 }; GENICAM_ImageFormatControl* pIFControl = NULL; IFControlInfo.pCamera = m_Camera; GENICAM_createImageFormatControl(&IFControlInfo, &pIFControl); GENICAM_EnumNode formatNode; formatNode = pIFControl->pixelFormat(pIFControl); formatNode.setValue(&formatNode, 0x1080001); //mono8 formatNode.release(&formatNode); pIFControl->release(pIFControl); pIFControl = NULL; GENICAM_EventSubscribeInfo eventSubscribeInfo; memset(&eventSubscribeInfo, 0, sizeof(GENICAM_EventSubscribeInfo)); eventSubscribeInfo.pCamera = m_Camera; if (GENICAM_createEventSubscribe(&eventSubscribeInfo, &m_EventSubscribe) < 0) { ReleaseSource(); return false; } if (m_EventSubscribe->subscribeConnectArgsEx(m_EventSubscribe, OnDeviceLinkNotify, (void*)this) < 0) { ReleaseSource(); return false; } GENICAM_StreamSourceInfo streamSourceInfo; memset(&streamSourceInfo, 0, sizeof(GENICAM_StreamSourceInfo)); streamSourceInfo.pCamera = m_Camera; streamSourceInfo.channelId = 0; if (GENICAM_createStreamSource(&streamSourceInfo, &m_StreamSource) < 0) { ReleaseSource(); return false; } if (m_StreamSource->attachGrabbingEx(m_StreamSource, OnGetFrame, (void*)this) < 0) { ReleaseSource(); return false; } GENICAM_EGrabStrategy eGrabStrategy = grabStrartegyLatestImage; if (m_StreamSource->startGrabbing(m_StreamSource, 0, eGrabStrategy) < 0) { ReleaseSource(); return false; } SetConnect(true); m_IsCatpure = true; return true; } void OPTCamera::SetConnect(bool isc) { EnterCriticalSection(&m_ConnectCS); m_IsConnect = isc; LeaveCriticalSection(&m_ConnectCS); } void OPTCamera::OnDeviceLinkNotify(const GENICAM_SConnectArg* pConnectArg, void* _this) { if (!_this)return; OPTCamera* cam = (OPTCamera*)_this; if (offLine == pConnectArg->m_event) { cam->m_StreamSource->detachGrabbingEx(cam->m_StreamSource, OnGetFrame, (void*)cam); cam->m_StreamSource->stopGrabbing(cam->m_StreamSource); cam->SetConnect(false); // ×¢Ïú»Øµ÷ } return; } void OPTCamera::OnGetFrame(GENICAM_Frame* pFrame, void* pUser) { if (!pUser)return; OPTCamera* cam = (OPTCamera*)pUser; int rel = pFrame->valid(pFrame); if ((rel == 0) && (cam->m_DemandFlag || cam->m_ShowFlag)) { uint32_t datasize = pFrame->getImageSize(pFrame); cam->m_OriginalWidth = pFrame->getImageWidth(pFrame); cam->m_OriginalHeight = pFrame->getImageHeight(pFrame); if (datasize > 0) { EnterCriticalSection(&cam->m_OriginalDataCS); if (!cam->m_OriginalData) { cam->m_OriginalData = new unsigned char[datasize]; } else { if (cam->m_OriginalDataSize != datasize) { if (cam->m_OriginalData)delete[]cam->m_OriginalData; cam->m_OriginalData = new unsigned char[datasize]; } } cam->m_OriginalDataSize = datasize; memcpy_s(cam->m_OriginalData, cam->m_OriginalDataSize, pFrame->getImage(pFrame), cam->m_OriginalDataSize); if (!cam->m_ExtCfg->m_UseShowImageWarpPerspective) { int cols = (cam->m_OriginalWidth - 1); int rows = (cam->m_OriginalHeight - 1); cv::Point2f center(cols / 2.0, rows / 2.0); double rad = MathHelper::DegreesToRadians(cam->m_ExtCfg->m_ShowImageAngle); int topLeftx = (0 - center.x) * cos(rad) - (0 - center.y) * sin(rad) + center.x; int topLefty = (0 - center.y) * cos(rad) + (0 - center.x) * sin(rad) + center.y; if (topLeftx < 0)topLeftx = 0; if (topLeftx > cols)topLeftx = cols; if (topLefty < 0)topLefty = 0; if (topLefty > rows)topLefty = rows; int topRightx = (cols - center.x) * cos(rad) - (0 - center.y) * sin(rad) + center.x; int topRighty = (0 - center.y) * cos(rad) + (cols - center.x) * sin(rad) + center.y; if (topRightx < 0)topRightx = 0; if (topRightx > cols)topRightx = cols; if (topRighty < 0)topRighty = 0; if (topRighty > rows)topRighty = rows; int btnRightx = (cols - center.x) * cos(rad) - (rows - center.y) * sin(rad) + center.x; int btnRighty = (rows - center.y) * cos(rad) + (cols - center.x) * sin(rad) + center.y; if (btnRightx < 0)btnRightx = 0; if (btnRightx > cols)btnRightx = cols; if (btnRighty < 0)btnRighty = 0; if (btnRighty > rows)btnRighty = rows; int btnLeftx = (0 - center.x) * cos(rad) - (rows - center.y) * sin(rad) + center.x; int btnLefty = (rows - center.y) * cos(rad) + (0 - center.x) * sin(rad) + center.y; if (btnLeftx < 0)btnLeftx = 0; if (btnLeftx > cols)btnLeftx = cols; if (btnLefty < 0)btnLefty = 0; if (btnLefty > rows)btnLefty = rows; cv::Point2f srcTri[4]; srcTri[0] = cv::Point2f(topLeftx, topLefty); srcTri[1] = cv::Point2f(topRightx, topRighty); srcTri[2] = cv::Point2f(btnRightx, btnRighty); srcTri[3] = cv::Point2f(btnLeftx, btnLefty); cv::Point2f tempTri[4]; tempTri[0] = cv::Point2f(0.0f, 0.0f); tempTri[1] = cv::Point2f((float)cam->m_ExtCfg->m_ShowImagePerspectiveWidth, 0.0f); tempTri[2] = cv::Point2f((float)cam->m_ExtCfg->m_ShowImagePerspectiveWidth, (float)cam->m_ExtCfg->m_ShowImagePerspectiveHeigh); tempTri[3] = cv::Point2f(0.0f, (float)cam->m_ExtCfg->m_ShowImagePerspectiveHeigh); cv::Mat warp_mat = cv::getPerspectiveTransform(srcTri, tempTri); cv::Mat im = cv::Mat(cam->m_OriginalHeight, cam->m_OriginalWidth, CV_8U, cam->m_OriginalData); cam->m_ShowImage.release(); cam->m_ShowImage = cv::Mat(cv::Size(cam->m_ExtCfg->m_ShowImagePerspectiveWidth, cam->m_ExtCfg->m_ShowImagePerspectiveHeigh), CV_8U); warpPerspective(im, cam->m_ShowImage, warp_mat, cam->m_ShowImage.size()); im.release(); } else { cv::Mat im = cv::Mat(cam->m_OriginalHeight, cam->m_OriginalWidth, CV_8U, cam->m_OriginalData); cv::Point2f srcTri[4]; srcTri[0] = cv::Point2f((float)cam->m_ExtCfg->m_ShowImageTopLeftX, (float)cam->m_ExtCfg->m_ShowImageTopLeftY); srcTri[1] = cv::Point2f((float)cam->m_ExtCfg->m_ShowImageTopRightX, (float)cam->m_ExtCfg->m_ShowImageTopRightY); srcTri[2] = cv::Point2f((float)cam->m_ExtCfg->m_ShowImageBottomRightX, (float)cam->m_ExtCfg->m_ShowImageBottomRightY); srcTri[3] = cv::Point2f((float)cam->m_ExtCfg->m_ShowImageBottomLeftX, (float)cam->m_ExtCfg->m_ShowImageBottomLeftY); cv::Point2f tempTri[4]; tempTri[0] = cv::Point2f(0.0f, 0.0f); tempTri[1] = cv::Point2f((float)cam->m_ExtCfg->m_ShowImagePerspectiveWidth, 0.0f); tempTri[2] = cv::Point2f((float)cam->m_ExtCfg->m_ShowImagePerspectiveWidth, (float)cam->m_ExtCfg->m_ShowImagePerspectiveHeigh); tempTri[3] = cv::Point2f(0.0f, (float)cam->m_ExtCfg->m_ShowImagePerspectiveHeigh); cv::Mat warp_mat = cv::getPerspectiveTransform(srcTri, tempTri); cam->m_ShowImage.release(); cam->m_ShowImage = cv::Mat(cv::Size(cam->m_ExtCfg->m_ShowImagePerspectiveWidth, cam->m_ExtCfg->m_ShowImagePerspectiveHeigh), CV_8U); //warpPerspective(image, tempImage, warp_mat, tempImage.size()); warpPerspective(im, cam->m_ShowImage, warp_mat, cam->m_ShowImage.size()); im.release(); } cam->m_ImageChanged = true; LeaveCriticalSection(&cam->m_OriginalDataCS); } } pFrame->release(pFrame); } bool OPTCamera::IsConnect() { bool isconnect = false; EnterCriticalSection(&m_ConnectCS); isconnect = m_IsConnect; LeaveCriticalSection(&m_ConnectCS); return isconnect; } void OPTCamera::CatpureRun() { while (m_RunFlag) { //g_SystemInfo->SetCameraConnect(IsConnect()); while (m_RunFlag && !IsConnect()) { int count = 0; while (m_RunFlag && count < 20) { count++; Sleep(200); } ConnectCamera(); } int count = 0; while (m_RunFlag && count < 15) { count++; Sleep(200); } } } GLuint OPTCamera::GetShowImage() { if (!m_Camera) return 0; if (!IsConnect())return 0; EnterCriticalSection(&m_OriginalDataCS); if (m_ShowImage.empty() || !m_ImageChanged) { LeaveCriticalSection(&m_OriginalDataCS); return m_GLTex; } LeaveCriticalSection(&m_OriginalDataCS); if (TryEnterCriticalSection(&m_OriginalDataCS)) { if (m_GLTex == 0) { m_ImgWidth = m_ShowImage.cols; m_ImgHeight = m_ShowImage.rows; m_Aspect = (float)m_ImgWidth / m_ImgHeight; GenTex(&m_GLTex, m_ImgWidth, m_ImgHeight, m_ShowImage.data); } else if (m_ShowImage.cols != m_ImgWidth || m_ShowImage.rows != m_ImgHeight) { m_ImgWidth = m_ShowImage.cols; m_ImgHeight = m_ShowImage.rows; m_Aspect = (float)m_ImgWidth / m_ImgHeight; glDeleteTextures(1, &m_GLTex); m_GLTex = 0; GenTex(&m_GLTex, m_ImgWidth, m_ImgHeight, m_ShowImage.data); } else { glBindTexture(GL_TEXTURE_2D, m_GLTex); //glPixelStorei(GL_UNPACK_ALIGNMENT, 4); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_ImgWidth, m_ImgHeight, GL_LUMINANCE, GL_UNSIGNED_BYTE, m_ShowImage.data); glBindTexture(GL_TEXTURE_2D, 0); } m_ImageChanged = false; LeaveCriticalSection(&m_OriginalDataCS); } return m_GLTex; } void OPTCamera::GenTex(uint32_t *tex, unsigned int w, unsigned int h, void * data) { glGenTextures(1, tex); if (*tex > 0) { glBindTexture(GL_TEXTURE_2D, *tex); //glPixelStorei(GL_UNPACK_ALIGNMENT, 4); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, w, h, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, data); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glBindTexture(GL_TEXTURE_2D, 0); } } bool OPTCamera::GenLogImage(void) { if (!IsConnect()) return false; if (!m_DemandFlag) return false; if (!m_OriginalData || m_OriginalDataSize == 0) return false; EnterCriticalSection(&m_OriginalDataCS); unsigned char* imtemp = new unsigned char[m_OriginalDataSize]; memcpy_s(imtemp, m_OriginalDataSize, m_OriginalData, m_OriginalDataSize); uint32_t imWidth = m_OriginalWidth; uint32_t imHeight = m_OriginalHeight; LeaveCriticalSection(&m_OriginalDataCS); bool needReduceImage = false; if (imHeight* imWidth > 1200000) { needReduceImage = true; } float ratio = ConfigManager::GetInstance()->GetExtCfg()->m_LogRatio; cv::Mat image(imHeight, imWidth, CV_8U, imtemp); cv::Mat fixImage; if (!m_ExtCfg->m_UseShowImageWarpPerspective) { if (needReduceImage) { cv::resize(image, fixImage, cv::Size(0, 0), ratio, ratio); } else { image.copyTo(fixImage); } int cols = fixImage.cols - 1; int rows = fixImage.rows - 1; cv::Point2f center(cols / 2.0, rows / 2.0); double rad = MathHelper::DegreesToRadians(m_ExtCfg->m_ShowImageAngle); int topLeftx = (0 - center.x) * cos(rad) - (0 - center.y) * sin(rad) + center.x; int topLefty = (0 - center.y) * cos(rad) + (0 - center.x) * sin(rad) + center.y; if (topLeftx < 0)topLeftx = 0; if (topLeftx > cols)topLeftx = cols; if (topLefty < 0)topLefty = 0; if (topLefty > rows)topLefty = rows; int topRightx = (cols - center.x) * cos(rad) - (0 - center.y) * sin(rad) + center.x; int topRighty = (0 - center.y) * cos(rad) + (cols - center.x) * sin(rad) + center.y; if (topRightx < 0)topRightx = 0; if (topRightx > cols)topRightx = cols; if (topRighty < 0)topRighty = 0; if (topRighty > rows)topRighty = rows; int btnRightx = (cols - center.x) * cos(rad) - (rows - center.y) * sin(rad) + center.x; int btnRighty = (rows - center.y) * cos(rad) + (cols - center.x) * sin(rad) + center.y; if (btnRightx < 0)btnRightx = 0; if (btnRightx > cols)btnRightx = cols; if (btnRighty < 0)btnRighty = 0; if (btnRighty > rows)btnRighty = rows; int btnLeftx = (0 - center.x) * cos(rad) - (rows - center.y) * sin(rad) + center.x; int btnLefty = (rows - center.y) * cos(rad) + (0 - center.x) * sin(rad) + center.y; if (btnLeftx < 0)btnLeftx = 0; if (btnLeftx > cols)btnLeftx = cols; if (btnLefty < 0)btnLefty = 0; if (btnLefty > rows)btnLefty = rows; cv::Point2f srcTri[4]; srcTri[0] = cv::Point2f(topLeftx, topLefty); srcTri[1] = cv::Point2f(topRightx, topRighty); srcTri[2] = cv::Point2f(btnRightx, btnRighty); srcTri[3] = cv::Point2f(btnLeftx, btnLefty); cv::Point2f tempTri[4]; tempTri[0] = cv::Point2f(0.0f, 0.0f); tempTri[1] = cv::Point2f((float)m_ExtCfg->m_ShowImagePerspectiveWidth, 0.0f); tempTri[2] = cv::Point2f((float)m_ExtCfg->m_ShowImagePerspectiveWidth, (float)m_ExtCfg->m_ShowImagePerspectiveHeigh); tempTri[3] = cv::Point2f(0.0f, (float)m_ExtCfg->m_ShowImagePerspectiveHeigh); cv::Mat warp_mat = cv::getPerspectiveTransform(srcTri, tempTri); cv::Mat tempImage = cv::Mat(cv::Size(m_ExtCfg->m_ShowImagePerspectiveWidth, m_ExtCfg->m_ShowImagePerspectiveHeigh), CV_8U); warpPerspective(fixImage, tempImage, warp_mat, tempImage.size()); fixImage.release(); fixImage = tempImage; } else { cv::Point2f srcTri[4]; if (needReduceImage) { cv::resize(image, fixImage, cv::Size(0, 0), ratio, ratio); srcTri[0] = cv::Point2f((float)m_ExtCfg->m_ShowImageTopLeftX*ratio, (float)m_ExtCfg->m_ShowImageTopLeftY*ratio); srcTri[1] = cv::Point2f((float)m_ExtCfg->m_ShowImageTopRightX*ratio, (float)m_ExtCfg->m_ShowImageTopRightY*ratio); srcTri[2] = cv::Point2f((float)m_ExtCfg->m_ShowImageBottomRightX*ratio, (float)m_ExtCfg->m_ShowImageBottomRightY*ratio); srcTri[3] = cv::Point2f((float)m_ExtCfg->m_ShowImageBottomLeftX*ratio, (float)m_ExtCfg->m_ShowImageBottomLeftY*ratio); } else { image.copyTo(fixImage); srcTri[0] = cv::Point2f((float)m_ExtCfg->m_ShowImageTopLeftX, (float)m_ExtCfg->m_ShowImageTopLeftY); srcTri[1] = cv::Point2f((float)m_ExtCfg->m_ShowImageTopRightX, (float)m_ExtCfg->m_ShowImageTopRightY); srcTri[2] = cv::Point2f((float)m_ExtCfg->m_ShowImageBottomRightX, (float)m_ExtCfg->m_ShowImageBottomRightY); srcTri[3] = cv::Point2f((float)m_ExtCfg->m_ShowImageBottomLeftX, (float)m_ExtCfg->m_ShowImageBottomLeftY); } cv::Point2f tempTri[4]; tempTri[0] = cv::Point2f(0.0f, 0.0f); tempTri[1] = cv::Point2f((float)m_ExtCfg->m_ShowImagePerspectiveWidth, 0.0f); tempTri[2] = cv::Point2f((float)m_ExtCfg->m_ShowImagePerspectiveWidth, (float)m_ExtCfg->m_ShowImagePerspectiveHeigh); tempTri[3] = cv::Point2f(0.0f, (float)m_ExtCfg->m_ShowImagePerspectiveHeigh); cv::Mat warp_mat = cv::getPerspectiveTransform(srcTri, tempTri); cv::Mat tempImage = cv::Mat(cv::Size(m_ExtCfg->m_ShowImagePerspectiveWidth, m_ExtCfg->m_ShowImagePerspectiveHeigh), CV_8U); warpPerspective(fixImage, tempImage, warp_mat, tempImage.size()); fixImage.release(); fixImage = tempImage; } delete[] imtemp; imtemp = NULL; if (m_LogImage) { delete[] m_LogImage; } m_LogImage = NULL; m_LogImageSize = 0; std::vector dataEncode; vector compression_params; compression_params.push_back(cv::IMWRITE_JPEG_QUALITY); compression_params.push_back(60); cv::imencode(".jpg", fixImage, dataEncode, compression_params); if (!dataEncode.empty()) { m_LogImage = new unsigned char[dataEncode.size()]; for (size_t i = 0; i < dataEncode.size(); i++) { m_LogImage[i] = dataEncode[i]; } m_LogImageSize = dataEncode.size(); } else { m_LogImageSize = 0; } fixImage.release(); dataEncode.clear(); return true; } void OPTCamera::SetExposureAutoByCfg() { if (!m_Camera || !IsConnect())return; GENICAM_AcquisitionControl *pAcquisitionCtrl = NULL; GENICAM_AcquisitionControlInfo acquisitionControlInfo = { 0 }; acquisitionControlInfo.pCamera = m_Camera; GENICAM_createAcquisitionControl(&acquisitionControlInfo, &pAcquisitionCtrl); if (m_ExtCfg->m_IsExposureAuto) { GENICAM_EnumNode exposureNode; exposureNode = pAcquisitionCtrl->exposureAuto(pAcquisitionCtrl); exposureNode.setValue(&exposureNode, 2); exposureNode.release(&exposureNode); } else { GENICAM_EnumNode exposureNode; exposureNode = pAcquisitionCtrl->exposureAuto(pAcquisitionCtrl); exposureNode.setValue(&exposureNode, 0); exposureNode.release(&exposureNode); GENICAM_DoubleNode doubleNode; doubleNode = pAcquisitionCtrl->exposureTime(pAcquisitionCtrl); double etime = 0.0; doubleNode.getValue(&doubleNode, &etime); doubleNode.setValue(&doubleNode, m_ExtCfg->m_ExposureTime); doubleNode.getValue(&doubleNode, &m_ExtCfg->m_ExposureTime); doubleNode.release(&doubleNode); } pAcquisitionCtrl->release(pAcquisitionCtrl); pAcquisitionCtrl = NULL; } void OPTCamera::SetExposureTimeByCfg() { if (!m_Camera || !IsConnect())return; GENICAM_AcquisitionControl *pAcquisitionCtrl = NULL; GENICAM_AcquisitionControlInfo acquisitionControlInfo = { 0 }; acquisitionControlInfo.pCamera = m_Camera; GENICAM_createAcquisitionControl(&acquisitionControlInfo, &pAcquisitionCtrl); GENICAM_EnumNode exposureNode; exposureNode = pAcquisitionCtrl->exposureAuto(pAcquisitionCtrl); exposureNode.setValue(&exposureNode, 0); exposureNode.release(&exposureNode); GENICAM_DoubleNode doubleNode; doubleNode = pAcquisitionCtrl->exposureTime(pAcquisitionCtrl); doubleNode.setValue(&doubleNode, m_ExtCfg->m_ExposureTime); doubleNode.getValue(&doubleNode, &m_ExtCfg->m_ExposureTime); doubleNode.release(&doubleNode); pAcquisitionCtrl->release(pAcquisitionCtrl); pAcquisitionCtrl = NULL; } void OPTCamera::SetFrameRateEnable() { if (!m_Camera || !IsConnect())return; GENICAM_AcquisitionControl *pAcquisitionCtrl = NULL; GENICAM_AcquisitionControlInfo acquisitionControlInfo = { 0 }; acquisitionControlInfo.pCamera = m_Camera; GENICAM_createAcquisitionControl(&acquisitionControlInfo, &pAcquisitionCtrl); if (m_ExtCfg->m_FrameRateEnable) { GENICAM_BoolNode frameRateEnableNode; frameRateEnableNode = pAcquisitionCtrl->acquisitionFrameRateEnable(pAcquisitionCtrl); frameRateEnableNode.setValue(&frameRateEnableNode, 1); frameRateEnableNode.release(&frameRateEnableNode); GENICAM_DoubleNode frameRateNode; frameRateNode = pAcquisitionCtrl->acquisitionFrameRate(pAcquisitionCtrl); frameRateNode.setValue(&frameRateNode, m_ExtCfg->m_FrameRate); frameRateNode.release(&frameRateNode); } else { GENICAM_BoolNode frameRateEnableNode; frameRateEnableNode = pAcquisitionCtrl->acquisitionFrameRateEnable(pAcquisitionCtrl); frameRateEnableNode.setValue(&frameRateEnableNode, 0); frameRateEnableNode.release(&frameRateEnableNode); } pAcquisitionCtrl->release(pAcquisitionCtrl); pAcquisitionCtrl = NULL; } void OPTCamera::SetFrameRate() { if (!m_Camera || !IsConnect())return; GENICAM_AcquisitionControl *pAcquisitionCtrl = NULL; GENICAM_AcquisitionControlInfo acquisitionControlInfo = { 0 }; acquisitionControlInfo.pCamera = m_Camera; GENICAM_createAcquisitionControl(&acquisitionControlInfo, &pAcquisitionCtrl); GENICAM_BoolNode frameRateEnableNode; frameRateEnableNode = pAcquisitionCtrl->acquisitionFrameRateEnable(pAcquisitionCtrl); frameRateEnableNode.setValue(&frameRateEnableNode, 1); frameRateEnableNode.release(&frameRateEnableNode); GENICAM_DoubleNode frameRateNode; frameRateNode = pAcquisitionCtrl->acquisitionFrameRate(pAcquisitionCtrl); frameRateNode.setValue(&frameRateNode, m_ExtCfg->m_FrameRate); frameRateNode.release(&frameRateNode); pAcquisitionCtrl->release(pAcquisitionCtrl); pAcquisitionCtrl = NULL; } void OPTCamera::CreateTestImage() { cv::Mat img = cv::imread("L:/TestGraf/2.bmp"); if (m_LogImage) { delete[] m_LogImage; } m_LogImage = NULL; m_LogImageSize = 0; std::vector dataEncode; vector compression_params; compression_params.push_back(cv::IMWRITE_JPEG_QUALITY); compression_params.push_back(60); cv::imencode(".jpg", img, dataEncode, compression_params); if (!dataEncode.empty()) { m_LogImage = new unsigned char[dataEncode.size()]; for (size_t i = 0; i < dataEncode.size(); i++) { m_LogImage[i] = dataEncode[i]; } m_LogImageSize = dataEncode.size(); } else { m_LogImageSize = 0; } img.release(); dataEncode.clear(); }