Dalsa 相机参数设置以及采集

本文介绍了一个基于嵌入式系统的相机图像采集流程,包括设备初始化、参数设置、图像获取及JPEG压缩保存。详细展示了如何通过特定的嵌入式API进行设备连接、配置分辨率、曝光时间和帧率等,以及如何在回调函数中处理图像数据,将其转换为JPEG格式并保存。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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++;

}

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

码猿杂谈

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值