void MVCamra::showCam()
{
//if (r == MVST_SUCCESS) return;
MVSTATUS_CODES r;
r = MVInitLib();
if (r != MVST_SUCCESS)
{
::MessageBox(NULL, _T("初始化失败 "), _T("错误"), MB_OK);
return;
/*cout << "初始化失败 " << "原因:" << MB_ICONWARNING << endl;*/
}
//查找连接到计算机上的相机数量
int numberofCams = 0;
MVGetNumOfCameras(&numberofCams);
//cout << numberofCams << endl;
if (numberofCams == 0)
{
::MessageBox(NULL, _T("没有发现相机! "), _T("错误"), MB_OK);
return;
}
else
{
//MessageBox(NULL, _T("发现相机! "), _T("正确"), MB_OK);
}
cam.hCam = NULL;
MVOpenCamByIndex(0, &cam.hCam);//打开相机,返回相机句柄
if (cam.hCam != NULL)
{
/*cout << "已经打开相机!" << endl;*/
}
//设置图像像素格式
cam.pixelformat = PixelFormat_BayerRG8;
MVSetPixelFormat(cam.hCam, cam.pixelformat);
//设置当前帧率
double fps = 40;
MVSetFrameRate(cam.hCam, fps);
//设置曝光时间
MVSetAutoExposureTimeLowerLimit(cam.hCam, 10);
MVSetAutoExposureTimeUpperLimit(cam.hCam, 300000);
//设置期望亮度
MVSetAutoTargetValue(cam.hCam, 128);
//设置亮度容差
MVSetAutoThreshold(cam.hCam, 0.3);
//设置触发方式
MVSetTriggerMode(cam.hCam, TriggerMode_Off);
//设置及获取图像宽高
int ww = 1600, hh = 1200;
MVSetWidth(cam.hCam, ww);
MVSetHeight(cam.hCam, hh);
MVGetWidth(cam.hCam, &ww);
MVGetHeight(cam.hCam, &hh);
//获取图像格式
MVGetPixelFormat(cam.hCam, &cam.pixelformat);
cam.mvimage.CreateByPixelFormat(ww, hh, cam.pixelformat);
//MVSetExposureTime(cam.hCam, 24000);
while (1)
{
//相机开始工作采集视频流(传输速率太快 会有丢帧 不影响性能)
MVSTATUS_CODES y;
if (dt.index <= 12 && dt.index >= 0)
{
//DLPC350_SetLedCurrents(30, 30, 30);
DLPC350_LoadImageIndex(dt.index);
std::this_thread::sleep_for(std::chrono::milliseconds(200));
//cv::waitKey(10);
y = MVStartGrab(cam.hCam, StreamCB, (ULONG_PTR)this);
if (calib_button_flag/*&&dt.index >= 0*/)
{
grating.src_grating[dt.index] = cam.src.clone();
}
/*if (dt.index <= 9 && dt.index >= 0)
cv::imwrite("F://cvs//image//0//0" + to_string(dt.index) + ".bmp", grating.src_grating[dt.index ]);
else
cv::imwrite("F://cvs//image//0//" + to_string(dt.index) + ".bmp", grating.src_grating[dt.index ]);*/
//cv::cvtColor(cam.src, grating.src_grating[dt.index - 1], CV_BGR2GRAY);
if (dt.index <= 9 && dt.index >= 0)
cv::imwrite("E://dlpcam//0" + to_string(dt.index) + ".bmp", grating.src_grating[dt.index ]);
else
cv::imwrite("E://dlpcam//" + to_string(dt.index) + ".bmp", grating.src_grating[dt.index ]);
//cv::waitKey(50);
dt.index++;
}
else
{
DLPC350_LoadImageIndex(0);
y = MVStartGrab(cam.hCam, StreamCB, (ULONG_PTR)this);
}
//if(dt.index >=13)DLPC350_LoadImageIndex(0);
//std::this_thread::sleep_for(std::chrono::milliseconds(60));
}
//关闭视频流
MVStopGrab(cam.hCam);
//关闭相机
MVCloseCam(cam.hCam);
}
weishi相机显示
最新推荐文章于 2023-06-15 13:59:07 发布