weishi相机显示

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

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值