1. 程式人生 > 實用技巧 >Dalsa 線掃相機採集

Dalsa 線掃相機採集

  之前使用同事遺留程式碼。程式碼裡面gige相機用“SapAcqDevice”類,採集卡用“SapAcquisition” 。現在需要更改相機增益和曝光。通過組合提升拍攝適應性。然後,因為之前同事留的坑,並且dalsa自帶的gui示例沒有涉及相機增益和曝光設定。所以一直繞著“SapAcquisition”這個類搜尋,只找到

    BOOL b = m_Acq->GetParameter(CORACQ_PRM_CONNECTOR_EXPOSURE_INPUT,&exposureTime);

  增益沒找到“CORACQ_PRM”開頭設定。只有最大最小值相關。相反,“SapAcqDevice” 設定曝光和增益很簡單。只是前面先入為主,人為是gige用的類。後面問凌雲,給出如下說明

  

  以及如下示例:

  

// Allocate acquisition object

SapAcquisition *pAcq = new SapAcquisition(SapLocation (“X64-CL_1”, 0), “FrameGrabber.ccf”);

// Allocate acqDevice object

SapAcqDevice *pAcqDevice = new SapAcqDevice (SapLocation (“CameraLink_1”, 0), “CLCamera.ccf”);

// Allocate buffer object, taking settings directly from the acquisition

SapBuffer *pBuffer = new SapBuffer(2, pAcq);

// Allocate view object, images will be displayed directly on the desktop

SapView *pView = new SapView(pBuffer, SapHwndDesktop);

// Allocate transfer object to link acquisition and buffer

SapTransfer *pTransfer = new SapAcqToBuf(pAcq, pBuffer, XferCallback, pView);// 在該TrasferPair中pAcq代表該源pBuffer代表目的地;

// Create resources for all objects

BOOL success = pAcq->Create();

success = pAcqDevice->Create();

success = pBuffer->Create();

success = pView->Create();

success = pTransfer->Create();

m_Acq->RegisterCallback(CORACQ_VAL_EVENT_TYPE_FRAME_LOST , frameLostCallback , NULL) ;

m_Acq->RegisterCallback(CORACQ_VAL_EVENT_TYPE_EXTERNAL_TRIGGER , ExtTrigCallback , NULL) ;

success = pAcq-> GetParameter(CORACQ_PRM_CROP_WIDTH , &imageWidth);

success = pAcq-> GetParameter(CORACQ_PRM_CROP_HEIGHT , &imageHeight);

int paramValue ;

success = pAcqDevice -> SetFeature(“ExposureTime”, &paramValue);

// Start a continuous transfer (live grab)

success = pTransfer->Grab();

printf("Press any key to stop grab\n");

getch();

// Stop the transfer and wait (timeout = 5 seconds)

success = pTransfer->Freeze();

success = pTransfer->Wait(5000);

success = pTransfer->Abort();

printf("Press any key to terminate\n");

getch();

// Release resources for all objects

success = pTransfer->Destroy();

success = pView->Destroy();

success = pBuffer->Destroy();

success = pAcqDevice ->Destroy();

success = pAcq->Destroy();

// Free all objects

delete pTransfer;

delete pView;

delete pBuffer;

delete pAcqDevice;

delete pAcq;

return 0;

  倆個同時使用。一個是載入採集卡引數,一個是使用相機名稱作為連線。上面的例子都要輸入ccf。 採集的ccf來源都清楚。 相機的ccf如圖示獲得(左上角File-》另存為——》彈出的視窗選擇儲存檔名和儲存路徑):

  如果不想更改相機配置,使用以下建構函式

SapAcqDevice(SapLocation location = SapLocation::ServerSystem, BOOL readOnly = FALSE);

  之類設定曝光(引數名“”)和明場(引數名,"")。

double paramValue=200,gainValue =2;
pAcqDevice -> SetFeature(“ExposureTime”, & paramValue);
pAcqDevice -> SetFeature(“Gain”, & gainValue);
//設定每個通道增益(以下程式碼來源版權宣告:本文為CSDN博主「圓滾熊」的原創文章,  原文連結:https://blog.csdn.net/y459541195/article/details/100706850)

  m_AcqDevice->SetFeatureValue("GainSelector","DigitalAll");//設定總增益
  m_AcqDevice->SetFeatureValue("Gain", dlg2.m_edit_GainAll);
  m_AcqDevice->SetFeatureValue("GainSelector", "DigitalRed");//R通道增益
  m_AcqDevice->SetFeatureValue("Gain", dlg2.m_edit_GainRed);
  m_AcqDevice->SetFeatureValue("GainSelector", "DigitalGreen");//G通道增益
  m_AcqDevice->SetFeatureValue("Gain", (double)1.0);
  m_AcqDevice->SetFeatureValue("GainSelector", "DigitalBlue");//B通道增益
  m_AcqDevice->SetFeatureValue("Gain", dlg2.m_edit_GainBlue);

  ————————————————