整了两天终于搞定了,还未优化,投影仪500帧/s投编码图案,触发相机拍照,连续不断拍,实现动态三维重建。代码还未整理,先记录一下
#include
#include
#include
#include "MvCameraControl.h"
#include
#include "bmpLoader.h"
int nRet = MV_OK;
void* handle = NULL;
int expose1 = 1000;
std::string st2 = "D:\\siat_reconstruction\\projectreconstruction\\1_picture";
unsigned int g_nPayloadSize = 0;
unsigned char* m_pBufForSaveImage; // ch:用于保存图像的缓存 | en:Buffer to save image
unsigned int m_nBufSizeForSaveImage;
// ch:等待按键输入 | en:Wait for key press
void WaitForKeyPress(void)
{
while(!_kbhit())
{
Sleep(10);
}
_getch();
}
bool PrintDeviceInfo(MV_CC_DEVICE_INFO* pstMVDevInfo)
{
if (NULL == pstMVDevInfo)
{
printf("The Pointer of pstMVDevInfo is NULL!\n");
return false;
}
if (pstMVDevInfo->nTLayerType == MV_GIGE_DEVICE)
{
int nIp1 = ((pstMVDevInfo->SpecialInfo.stGigEInfo.nCurrentIp & 0xff000000) >> 24);
int nIp2 = ((pstMVDevInfo->SpecialInfo.stGigEInfo.nCurrentIp & 0x00ff0000) >> 16);
int nIp3 = ((pstMVDevInfo->SpecialInfo.stGigEInfo.nCurrentIp & 0x0000ff00) >> 8);
int nIp4 = (pstMVDevInfo->SpecialInfo.stGigEInfo.nCurrentIp & 0x000000ff);
// ch:打印当前相机ip和用户自定义名字 | en:print current ip and user defined name
printf("CurrentIp: %d.%d.%d.%d\n" , nIp1, nIp2, nIp3, nIp4);
printf("UserDefinedName: %s\n\n" , pstMVDevInfo->SpecialInfo.stGigEInfo.chUserDefinedName);
}
else if (pstMVDevInfo->nTLayerType == MV_USB_DEVICE)
{
printf("UserDefinedName: %s\n\n", pstMVDevInfo->SpecialInfo.stUsb3VInfo.chUserDefinedName);
}
else
{
printf("Not support.\n");
}
return true;
}
int i = 0;
void __stdcall ImageCallBackEx(unsigned char * pData, MV_FRAME_OUT_INFO_EX* pFrameInfo, void* pUser)
{
if (pFrameInfo)
{
printf("Get One Frame: Width[%d], Height[%d], nFrameNum[%d]\n",
pFrameInfo->nWidth, pFrameInfo->nHeight, pFrameInfo->nFrameNum);
}
// ch:设置对应的相机参数 | en:Set camera parameter
if (NULL == m_pBufForSaveImage)
{
// ch:BMP图片大小:width * height * 3 + 2048(预留BMP头大小)
// en:// BMP image size: width * height * 3 + 2048 (Reserved BMP header size)
m_nBufSizeForSaveImage = pFrameInfo->nWidth * pFrameInfo->nHeight * 3 + 2048;
m_pBufForSaveImage = (unsigned char*)malloc(m_nBufSizeForSaveImage);
}
//MV_SAVE_IMAGE_PARAM_EX stParam = { 0 };
//MV_SAVE_IAMGE_TYPE m_nSaveImageType; // ch:保存图像格式 | en:Save Image Type
//m_nSaveImageType = MV_Image_Bmp;
//stParam.enImageType = m_nSaveImageType; // ch:需要保存的图像类型 | en:Image format to save
//stParam.enPixelType = pFrameInfo->enPixelType; // ch:相机对应的像素格式 | en:Camera pixel type
//stParam.nWidth = pFrameInfo->nWidth; // ch:相机对应的宽 | en:Width
//stParam.nHeight = pFrameInfo->nHeight; // ch:相机对应的高 | en:Height
//stParam.nDataLen = pFrameInfo->nFrameLen;
//stParam.pData = pData;
//stParam.pImageBuffer = m_pBufForSaveImage;
//stParam.nBufferSize = m_nBufSizeForSaveImage; // ch:存储节点的大小 | en:Buffer node size
//stParam.nJpgQuality = 80; // ch:jpg编码,仅在保存Jpg图像时有效。保存BMP时SDK内忽略该参数
//MV_CC_SaveImageEx2(handle, &stParam); // en:jpg encoding, only valid when saving as Jpg. SDK ignore this parameter when saving as BMP
//
// //将转换之后图片数据保存成文件
//char chImageName[100] = { 0 };
//std::string s = std::to_string(i);
//std::string ch1 = st2 + s +"\\%d.bmp";
//char p[100];
//int i = 0;
//for (i = 0; i < ch1.length(); i++)
// p[i] = ch1[i];
//p[i] = '\0';
// sprintf_s(chImageName, 100, p, pFrameInfo->nFrameNum);
// //std::string chImageName = "C:\\Users\\Administrator\\Desktop\\mianjiegouguangchongjian\\kls\\deviceone_picture\\"+std::to_string(stImageInfo.nFrameNum)+".bmp";
//FILE* fp = fopen(chImageName, "wb+");
//fwrite(m_pBufForSaveImage, 1, stParam.nImageLen, fp);
//fclose(fp);
//free(m_pBufForSaveImage);
//i++;
...其他图像数据处理
// //for (int i = 0; i < 100; i++)
//保存图片
{