当前位置:网站首页>Weishi camera display

Weishi camera display

2022-06-26 02:02:00 ooolmf

void MVCamra::showCam()
{
    
	//if (r == MVST_SUCCESS) return;
	MVSTATUS_CODES r;
	r = MVInitLib();
	if (r != MVST_SUCCESS)
	{
    
		::MessageBox(NULL, _T(" initialization failed  "), _T(" error "), MB_OK);
		return;
		/*cout << " initialization failed  " << " reason :" << MB_ICONWARNING << endl;*/
	}
	// Find the number of cameras connected to the computer 
	int numberofCams = 0;
	MVGetNumOfCameras(&numberofCams);
	//cout << numberofCams << endl;
	if (numberofCams == 0)
	{
    
		::MessageBox(NULL, _T(" No camera found ! "), _T(" error "), MB_OK);
		return;
	}

	else
	{
    
		//MessageBox(NULL, _T(" Discover camera ! "), _T(" correct "), MB_OK);

	}

	cam.hCam = NULL;
	MVOpenCamByIndex(0, &cam.hCam);// Turn on camera , Return camera handle 
	if (cam.hCam != NULL)
	{
    
		/*cout << " The camera has been turned on !" << endl;*/
	}


	// Format image pixels 
	cam.pixelformat = PixelFormat_BayerRG8;
	MVSetPixelFormat(cam.hCam, cam.pixelformat);
	// Set the current frame rate 
	double fps = 40;
	MVSetFrameRate(cam.hCam, fps);
	// Set exposure time 
	MVSetAutoExposureTimeLowerLimit(cam.hCam, 10);
	MVSetAutoExposureTimeUpperLimit(cam.hCam, 300000);
	// Set the desired brightness 
	MVSetAutoTargetValue(cam.hCam, 128);
	// Set the brightness tolerance 
	MVSetAutoThreshold(cam.hCam, 0.3);
	// Set the trigger mode 
	MVSetTriggerMode(cam.hCam, TriggerMode_Off);

	// Set and obtain image width and height 
	int ww = 1600, hh = 1200;
	MVSetWidth(cam.hCam, ww);
	MVSetHeight(cam.hCam, hh);
	MVGetWidth(cam.hCam, &ww);
	MVGetHeight(cam.hCam, &hh);

	// Get image format 
	MVGetPixelFormat(cam.hCam, &cam.pixelformat);
	cam.mvimage.CreateByPixelFormat(ww, hh, cam.pixelformat);

	//MVSetExposureTime(cam.hCam, 24000);
	while (1)
	{
    
		// The camera starts working to capture the video stream ( The transmission rate is too fast   There will be frame loss   No performance impact )
		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)); 
	}
	// Turn off video streaming 
	MVStopGrab(cam.hCam);
	// Turn off camera 
	MVCloseCam(cam.hCam);

}

原网站

版权声明
本文为[ooolmf]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/177/202206260026254769.html