Dalsa 相机参数设置以及采集

1、定义成员变量

SapAcqDevice		*m_pAcqDevice;
SapBufferWithTrash	*m_pBuffers;
SapTransfer			*m_pAcqDeviceToBuf;
BayerEncode m_bayer_encode;
static void NanoXferCallback(SapXferCallbackInfo *pInfo);

2、Oninitidialog中设置参数以及连接

//相机连接
m_pAcqDevice = new SapAcqDevice(SapLocation(1,0), FALSE);
m_pBuffers	= new SapBufferWithTrash(10,m_pAcqDevice);
m_pAcqDeviceToBuf = new SapAcqDeviceToBuf(m_pAcqDevice,m_pBuffers,NanoXferCallback, this);

BOOL b=m_pAcqDevice->Create();	
if(b)
	InsertListBox("相机连接成功!");
else
	InsertListBox("相机连接失败!");

m_pAcqDevice->SetFeatureValue("Width",1280);
m_pAcqDevice->SetFeatureValue("Height",1024);

b=m_pBuffers->Create();
b=m_pAcqDeviceToBuf->Create();

m_pAcqDevice->SetFeatureValue("TriggerMode",0);
b = m_pAcqDevice->SetFeatureValue("ExposureTime",(double)200);
if(b)
	InsertListBox("曝光时间设置成功!");
else
	InsertListBox("曝光时间设置失败!");

m_pAcqDevice->SetFeatureValue("Gain", (double)3);
b = m_pAcqDevice->SetFeatureValue("AcquisitionFrameRate", (double)theApp.m_iHZ);
if(b)
	InsertListBox("帧率设置成功!");
else
	InsertListBox("帧率设置失败!");

3、回调函数中保存图片

void CTrainNumberIdentificationDlg::NanoXferCallback(
SapXferCallbackInfo *pInfo)
{
CTrainNumberIdentificationDlg *p =
(CTrainNumberIdentificationDlg * )pInfo->GetContext();
BYTE *pData = NULL;
CString strCurImageName = _T("");
if(theApp.m_strDeviceName == “1”)
strCurImageName.Format("%s%d.jpg",theApp.m_strPicPath,theApp.m_nPicorder);
else
strCurImageName.Format("%s2-%d.jpg",theApp.m_strPicPath,theApp.m_nPicorder);

if (!pInfo->IsTrash())
{
	p->m_pBuffers->GetAddress((void **)&pData);
	BYTE *pDataJPGIn = new BYTE[4000000];
	{
		//m_image_compress.PushImageData(pData,m_pBuffers->GetWidth(),m_pBuffers->GetHeight(),
		//										((m_pBuffers->GetPixelDepth())/8),strCurImageName);
		p->m_bayer_encode.gp_bayer_decode(pData,1280,1024,pDataJPGIn,
														BAYER_TILE_RGGB);

		JSAMPROW row_pointer[1] = {NULL};			
	int row_stride = 0;	
	struct jpeg_compress_struct jcs;
	struct jpeg_error_mgr jem;
	FILE *pSaveFile = NULL;
	fopen_s(&pSaveFile,strCurImageName,"wb");

	jcs.err = jpeg_std_error(&jem);
	jpeg_create_compress(&jcs);
	jpeg_stdio_dest(&jcs, pSaveFile);

	jcs.image_width = 1280; 			
	jcs.image_height = 1024;
	jcs.input_components = 3;			 
	//if (1 == pImageInfo->m_nChannel)
	//{
	//	jcs.in_color_space = JCS_GRAYSCALE; 
	//}
	//else
	{
		jcs.in_color_space = JCS_RGB;
	}
	jpeg_set_defaults(&jcs);	
	jpeg_set_quality(&jcs,80,true);
	jpeg_start_compress(&jcs,TRUE);
	row_stride = jcs.image_width*(3);	
	
	//if(MirrorImage(pImageInfo,pImageInfo->m_nFlip))
	{
		while (jcs.next_scanline < jcs.image_height) 
		{
			row_pointer[0] = &(pDataJPGIn)[jcs.next_scanline*row_stride];
			jpeg_write_scanlines(&jcs,row_pointer,1);
		}
	}
	jpeg_finish_compress(&jcs);
	jpeg_destroy_compress(&jcs);
	fclose(pSaveFile);
	pSaveFile = NULL;
}
if(pDataJPGIn)
	delete pDataJPGIn;
}
else
{
	//pCamCtrl->m_camera_log.LogErr(_T("Camera UserID = %s,出现丢帧:%d\n"),
	//							  pCamCtrl->m_strUserID,pInfo->GetEventCount());  
}

//入队列
EnterCriticalSection(&(theApp.m_CS)); 	
theApp.g_grab_image_queue.push(strCurImageName);
LeaveCriticalSection(&(theApp.m_CS));
strCurImageName+="\n";
g_logQueue.Log(strCurImageName);
theApp.m_nPicorder++;

}

你可能感兴趣的:(工业相机,图像处理)