Exemple #1
0
void Contoller::initForE2V()
{
	USING_VIRTUAL_CAMERA = 0;//是否使用虚拟摄像头 1使用 0用E2V

	//初始化采集卡
	status = MicroDisplayInit::InitParameter(mdi);
	//status = MicroDisplayInit::InitLoad(mdi, "4096RGB1LineX1.mcf");
	if (status < 0)
	{
		MD_ErrorMessageWait(mdi.fg);
		return;
	}
	MicroDisplayInit::CreateBufferWithOutDiplay(mdi);
	//MicroDisplayInit::CreateBufferWithDiplay(mdi);
	Fg_saveConfig(mdi.fg, "save.mcf");
	//没有报错说明初始化完成,有错会自动报错并退出。
	OutPutDebugInfo("相机&采集卡初始化完成!");


	/**********************初始化采集卡***********************/
	if (mc100_open(0) >= 0)
	{
		OutPutDebugInfo("打开采集卡0成功!");
		//开始监听采集卡
		std::thread t_watcher(std::mem_fn(&Contoller::IoCardWatcherThread), this);
		t_watcher.detach();
		mc100_write_port(0, MC100_PORTA, 0x00);
		IoCardOK = 1;
	}
	else
	{
		OutPutDebugInfo("打开采集卡0失败!");
	}
}
Exemple #2
0
//监听采集卡状态进程
void Contoller::IoCardWatcherThread()
{
	sofeState = SofeState::SS_WATCHING;
	do{
		if (sofeState == SofeState::SS_WATCHING &&
			producerState != ProducerState::PS_GRABBING &&
			mc100_check_pin(0, (MC100_PORTA << 4) | 0) != 1)
		{
			sofeState = SofeState::SS_ACTIVATED;
			//producerState != ProducerState::GRABBING
			OutPutDebugInfo("触发器触发");
			Sleep(10);
			//等待采集处理完毕
			while (producerState == ProducerState::PS_GRABBING)
			{
				Sleep(10);
			}
		}
		else
		{
			Sleep(1);
		}
	} while (sofeState != SofeState::SS_EXIT);
}
Exemple #3
0
void Contoller::initForVC(string virtualImg)
{
	USING_VIRTUAL_CAMERA = 1;
	vc = VirtualCamera(mdi, virtualImg);//初始化虚拟相机
	OutPutDebugInfo("相机&采集卡初始化完成!");
}
Exemple #4
0
void Contoller::RunnerThread()
{
	int grabbingIndex = 0;
	do{
		//触发器触发未响应,且程序并未在采图
		if (sofeState == SofeState::SS_ACTIVATED &&
			producerState != ProducerState::PS_GRABBING)
		{

			producerState = ProducerState::PS_GRABBING;
			//设置程序状态回到WATCHING,表示触发信号已响应
			sofeState = SofeState::SS_WATCHING;

			OutPutDebugInfo("开始采图");
			Sleep(DelayTime);

			grabbingIndex += 1;
			if (grabbingIndex > 1000) grabbingIndex = 1;


			//初始化缓存
			s.Start();
			//启动生产者
			std::thread t1(std::mem_fn(&Contoller::producerThread), this);
			t1.detach();

			//启动消费者
			std::thread t2(std::mem_fn(&Contoller::customerThread), this);
			t2.detach();
			Sleep(10);
			customerState = CustomerState::CS_PROCESSING;


			//等待采集处理完毕
			while (producerState == ProducerState::PS_GRABBING)
			{
				Sleep(10);
			}
			while (customerState == CustomerState::CS_PROCESSING)
			{
				Sleep(10);
			}

			////若采图完成时,消费者正在运行算法,表示上一轮的处理尚未完成,算法速度不够。
			//if (customerState == CustomerState::CS_PROCESSING)
			//	ExitWithError("算法速度过慢!上一轮处理尚未完成!");



#ifdef OUTPUT_DEBUG_INFO
			if (OUTPUT_DEBUG_INFO)
			{
				string p1;
				stringstream ss1;
				ss1 << "samples/result" << grabbingIndex << "_o原图.jpg";
				ss1 >> p1;
				string p2;
				stringstream ss2;
				ss2 << "samples/result" << grabbingIndex << "_x3.jpg";
				ss2 >> p2;
				cv::imwrite(p1, s.NowBuffer);
				//cv::imwrite(p2, s.NowBufferImg);
			}
#endif
		}
		else
		{
			Sleep(10);
		}
	} while (sofeState != SofeState::SS_EXIT);
// 初始化采集卡与摄像机
// 设置参数初始化
// 返回Status;
int MicroDisplayInit::InitParameter(MicroDisplayInit& mdi)
{
#ifdef OUTPUT_DEBUG_INFO
	if (OUTPUT_DEBUG_INFO)
	{
		getBoardInfo();
	}
#endif


	int status = 0;
	char debugInfo[256];


	// Initialization of the microEnable frame grabber
	if (mdi.colorType == GRAY)
	{
		if ((mdi.fg = Fg_Init(mdi.dllNameGRAY, mdi.nBoard)) == NULL) {
			return status;
		}
		//设置传输模式,设置后才为4k
		int _FG_CAMERA_LINK_CAMTYP = FG_CL_DUALTAP_8_BIT;
		if (Fg_setParameter(mdi.fg, FG_CAMERA_LINK_CAMTYP, &_FG_CAMERA_LINK_CAMTYP, mdi.nCamPort) < 0) {
			return status;
		}
	}
	else
	{
		if ((mdi.fg = Fg_Init(mdi.dllNameRGB, mdi.nBoard)) == NULL) {
			return status;
		}
		//TODO:添加传输模式的调整
		//int _FG_CAMERA_LINK_CAMTYP = FG_CL_DUALTAP_8_BIT;
		//if (Fg_setParameter(mdi.fg, FG_CAMERA_LINK_CAMTYP, &_FG_CAMERA_LINK_CAMTYP, mdi.nCamPort) < 0) {
		//	return status;
		//}
	}
	OutPutDebugInfo("Init Grabber ok");

	//设置参数
	int _FG_CAMERA_LINK_CAMTYP = FG_CL_DUALTAP_8_BIT;
	if (Fg_setParameter(mdi.fg, FG_CAMERA_LINK_CAMTYP, &_FG_CAMERA_LINK_CAMTYP, mdi.nCamPort) < 0) {
		return status;
	}
	if (Fg_setParameter(mdi.fg, FG_WIDTH, &mdi.width, mdi.nCamPort) < 0) {
		return status;
	}
	if (Fg_setParameter(mdi.fg, FG_HEIGHT, &mdi.height, mdi.nCamPort) < 0) {
		return status;
	}
	int bitAlignment = FG_LEFT_ALIGNED;
	if (Fg_setParameter(mdi.fg, FG_BITALIGNMENT, &bitAlignment, mdi.nCamPort) < 0) {
		return status;
	}
	sprintf(debugInfo, "Set Image Size on port %d (w: %d,h: %d) ok", mdi.nCamPort, mdi.width, mdi.height);
	OutPutDebugInfo(debugInfo);


	// Memory allocation
	int format = 0;
	Fg_getParameter(mdi.fg, FG_FORMAT, &format, mdi.nCamPort);
	size_t bytesPerPixel = 1;
	switch (format){
	case FG_GRAY:	bytesPerPixel = 1; break;
	case FG_GRAY16:	bytesPerPixel = 2; break;
	case FG_COL24:	bytesPerPixel = 3; break;
	case FG_COL32:	bytesPerPixel = 4; break;
	case FG_COL30:	bytesPerPixel = 5; break;
	case FG_COL48:	bytesPerPixel = 6; break;
	}
	size_t totalBufSize = mdi.width*mdi.height*mdi.nr_of_buffer*bytesPerPixel;
	if ((mdi.pMem0 = Fg_AllocMemEx(mdi.fg, totalBufSize, mdi.nr_of_buffer)) == NULL){
		return status;
	}
	else {
		sprintf(debugInfo, "%d framebuffer allocated for port %d ok", mdi.nr_of_buffer, mdi.nCamPort);
		OutPutDebugInfo(debugInfo);
	}
	return status;
}
// get board and camera-link serial port information
// using silicon-software runtime library fglib5
int MicroDisplayInit::getBoardInfo()
{
	int boardType;
	int i = 0;

	int maxNrOfboards = 10;// use a constant no. of boards to query, when evaluations versions minor to RT 5.2
	int nrOfBoardsFound = 0;
	int maxBoardIndex = -1;
	int iPortCount = 0;
	int nrOfBoardsPresent = 0;

	// detect all boards
	nrOfBoardsPresent = getNrOfBoards();
	if (!nrOfBoardsPresent)
		return 0;

	for (i = 0; i < maxNrOfboards; i++) {
		int iPortNrOnBoard = 0;
		const char * boardName;
		bool skipIndex = false;
		boardType = Fg_getBoardType(i);
		switch (boardType) {
		case PN_MICROENABLE4AS1CL:
			boardName = "MicroEnable IV AS1-CL";
			iPortNrOnBoard = 1;
			break;
		case PN_MICROENABLE4AD1CL:
			boardName = "MicroEnable IV AD1-CL";
			iPortNrOnBoard = 1;
			break;
		case PN_MICROENABLE4VD1CL:
			boardName = "MicroEnable IV VD1-CL";
			iPortNrOnBoard = 2;
			break;
		case PN_MICROENABLE4AD4CL:
			boardName = "MicroEnable IV AD4-CL";
			iPortNrOnBoard = 2;
			break;
		case PN_MICROENABLE4VD4CL:
			boardName = "MicroEnable IV VD4-CL";
			iPortNrOnBoard = 2;
			break;
			// ignore the non-cameralink boards
		case PN_MICROENABLE3I:
		case PN_MICROENABLE3IXXL:
		case PN_MICROENABLE4AQ4GE:
		case PN_MICROENABLE4VQ4GE:
		default:
			boardName = "Unknown / Unsupported Board";
			skipIndex = true;
		}
		if (!skipIndex){
			nrOfBoardsFound++;
			maxBoardIndex = i;

			if (iPortNrOnBoard > 0){
				if (i == 0)
					OutPutDebugInfo("Following serial ports are available:");
				for (int j = 0; j < iPortNrOnBoard; j++){
					iPortCount++;
					char debugInfo[256];
					sprintf(debugInfo, "%d. Board_%u %s (%x) Port_%d", iPortCount - 1, i, boardName, boardType, j);
					OutPutDebugInfo(debugInfo);
				}
			}
		}
		else{
		}
		if (nrOfBoardsFound >= nrOfBoardsPresent){
			break;// all boards are scanned
		}
	}
	return iPortCount;
}