Example #1
0
void CMainFrame::on_dev_open_ccd()
{
	BOOL isccdinit=theApp.m_CCD.m_isinit;
	DS_RUNMODE ccd_status=theApp.m_CCD.m_runstatus;
	DS_CAMERA_STATUS ds_err=STATUS_OK;

	//if(ccd_status==RUNMODE_STOP)
	if(!isccdinit)
	{
		if ( STATUS_OK != (ds_err=CameraInit(SnapThreadCallback, theApp.m_CCD.m_resolution, 
			((CMainFrame*)AfxGetMainWnd())->GetActiveView()->m_hWnd, this->m_hWnd)))
		{
			string strret("Init Camera failed!\tError: ");

			switch(ds_err)
			{
				case STATUS_NO_DEVICE_FIND:
					strret+="No device found.";
					break;
				case STATUS_NOT_ENOUGH_SYSTEM_MEMORY:
					strret+="Not enough memory.";
					break;
				case STATUS_PARAMETER_INVALID:
					strret+="Invalid parameter.";
					break;
				default:
					strret+="Other error.";
					break;
			}
			
			MessageBox(strret.c_str(), "Error", MB_OK | MB_ICONSTOP);
			return;
			
		}

		//theApp.m_CCD.m_runstatus=RUNMODE_PLAY;
		theApp.m_CCD.m_isinit=TRUE;
		CameraPlay();
		CameraSetLongExpPower(FALSE);
		theApp.m_CCD.m_runstatus=RUNMODE_PLAY;
		CameraSetVideoMessage(WM_CCDVIDEOMSG);
		CameraDisplayEnable(TRUE);
	}
}
Example #2
0
void ToGame(void)
{
	Pause = false;

	SpaceReset(&space);

	// Reset player positions and velocity
	for (int i = 0, c = 0; i < MAX_PLAYERS; i++)
	{
		PlayerReset(&players[i], c);
		if (!players[i].Enabled) continue;
		c++;
	}
	CameraInit(&camera);
	SoundPlay(SoundStart, 1.0);
	MusicSetLoud(true);

	GatherInput = GameGatherInput;
	DoLogic     = GameDoLogic;
	OutputFrame = GameOutputFrame;
}
Example #3
0
//void pixyInit(uint32_t slaveRomStart, const unsigned char slaveImage[], uint32_t imageSize)
void pixyInit(void)
{
	// write stack guard word
 //	STACK_GUARD = STACK_GUARD_WORD;

	commonInit();

	IPC_haltSlave();

	ADCInit();
   	SCTInit();
	CameraInit();
/*	IPC_startSlave(); */
	// start slave
/*	if (slaveRomStart && slaveImage && imageSize)
	{
		IPC_downloadSlaveImage(slaveRomStart, slaveImage, imageSize);

	} */

	// initialize shared memory interface before running M0
	SMLink *smLink = new SMLink;

	// run M0
    cr_start_m0(SLAVE_M0APP,&__core_m0app_START__);

	// initialize chirp objects
	USBLink *usbLink = new USBLink;
	g_chirpUsb = new Chirp(false, false, usbLink);
  	g_chirpM0 = new Chirp(false, true, smLink);

	// initialize devices/modules
	led_init();
	if (prm_init(g_chirpUsb)<0) // error, let user know (don't just continue like nothing's happened)
		showError(1, 0x0000ff, "Flash is corrupt, parameters have been lost\n");
	pwr_init();
	cam_init();
	rcs_init();
	//cc_init();
}
Example #4
0
void pixyInit(uint32_t slaveRomStart, const unsigned char slaveImage[], uint32_t imageSize)
{
	// write stack guard word
 	STACK_GUARD = STACK_GUARD_WORD;

	commonInit();

	IPC_haltSlave();

	// clear RC servo registers to prevent and glitches upon initialization
	rcs_enable(0, 0);
	rcs_enable(1, 0);

	ADCInit();
   	SCTInit();
	CameraInit();

	// start slave
	if (slaveRomStart && slaveImage && imageSize)
	{
		IPC_downloadSlaveImage(slaveRomStart, slaveImage, imageSize);
		IPC_startSlave();
	}

	// initialize chirp objects
	USBLink *usbLink = new USBLink;
	g_chirpUsb = new Chirp(false, false, usbLink);
	g_chirpUsb->setSendTimeout(3000); // set a high timeout because the host can sometimes go AWOL for a second or two....
	SMLink *smLink = new SMLink;
  	g_chirpM0 = new Chirp(false, true, smLink);

	// initialize devices/modules
	led_init();
	prm_init(g_chirpUsb);
	pwr_init();
	cam_init();
	rcs_init();
	//cc_init();
}
Example #5
0
File: camera.c Project: RTS2/rts2
int
cond_init (char *device_name, int camera_id)
{
  short base;
  int i;
  //StatusResults sr;
  QueryTemperatureStatusResults qtsr;
  GetVersionResults gvr;

  if (is_init)
    return 0;

  base = getbaseaddr (0);	// sbig_port...?

  // lock the device
  sem_lock ();

  // This is a standard driver init procedure 
  begin_realtime ();
  CameraInit (base);

  if (MicroCommand (MC_GET_VERSION, ST7_CAMERA, NULL, &gvr))
    goto err;

  cameraID = gvr.cameraID;

  //if(MicroCommand (MC_STATUS, cameraID, NULL, &sr)) goto err;
  if (MicroCommand (MC_TEMP_STATUS, cameraID, NULL, &qtsr))
    goto err;
  get_eeprom ();


  if (Cams[eePtr.model].hasTrack)
    chips = 2;
  else
    chips = 1;

  ch_info = (struct chip_info *) malloc (sizeof (struct chip_info) * chips);

  for (i = 0; i < chips; i++)
    {
      ch_info[i].width = Cams[eePtr.model].horzImage;
      ch_info[i].height = Cams[eePtr.model].vertImage;
      ch_info[i].binning_vertical = 1;
      ch_info[i].binning_horizontal = 1;
      ch_info[i].pixelX = Cams[eePtr.model].pixelX;
      ch_info[i].pixelY = Cams[eePtr.model].pixelY;
      if (i)
	ch_info[i].gain = eePtr.trackingGain;
      else
	ch_info[i].gain = eePtr.imagingGain;
    }

  // make space for the read out image
  {
    CAMERA *C;
    int j, k;

    for (j = 0; j < chips; j++)
      {
	OpenCCD (j, &C);

	free (img[j]);
	free (lin[j]);

	img[j] = (unsigned short *)
	  malloc (C->horzTotal * C->vertTotal * sizeof (unsigned short));
	lin[j] = (unsigned short **)
	  malloc (C->vertTotal * sizeof (unsigned short *));

	for (k = 0; k < C->vertTotal; k++)
	  lin[j][k] = img[j] + k * C->horzTotal;

	max_line[j] = C->vertTotal;

	CloseCCD (C);
      }
  }

  // determine temperature regulation state
  switch (qtsr.enabled)
    {
    case 0:
      // a bit strange: may have different
      // meanings... (freeze)
      camera_reg = (qtsr.power > 250) ? CAMERA_COOL_MAX : CAMERA_COOL_OFF;
      break;
    case 1:
      camera_reg = CAMERA_COOL_HOLD;
      break;
      break;
    default:
      camera_reg = CAMERA_COOL_OFF;
    }

  is_init = 1;

  sem_unlock ();

  return 0;

err:
  sem_unlock ();
  errno = ENODEV;
  return -1;
}
Example #6
0
//Main Process
int _tmain(int argc, _TCHAR* argv[])
{
	CameraInit(&LeftDevice, 0);
	CameraInit(&RightDevice, 1);

	LeftImgOver = CreateSemaphore(NULL, 0, 1, NULL);
	RightImgOver = CreateSemaphore(NULL, 0, 1, NULL);
	LeftProcessOver = CreateSemaphore(NULL, 0, 1, NULL);
	RightProcessOver = CreateSemaphore(NULL, 0, 1, NULL);

	LeftImg = cvCreateImageHeader(cvSize(IMGWIDTH, IMGHEIGHT), IPL_DEPTH_8U, 3);
	RightImg = cvCreateImageHeader(cvSize(IMGWIDTH, IMGHEIGHT), IPL_DEPTH_8U, 3);



#ifdef SHOW
	ShowImgProcess = _beginthreadex(NULL, 0, ImgShowThread, NULL, 0, NULL);
#endif
	LeftCamReceive = (HANDLE)_beginthreadex(NULL, 0, LeftCaptureThread, NULL, 0, NULL);
	LeftCamReceive = (HANDLE)_beginthreadex(NULL, 0, RightCaptureThread, NULL, 0, NULL);
	LeftImgProcess = (HANDLE)_beginthreadex(NULL, 0, LeftImgCalcThread, NULL, 0, NULL);
	RightImaProcess = (HANDLE)_beginthreadex(NULL, 0, RightImgCalcThread, NULL, 0, NULL);


	while (true)
	{
		switch (cvWaitKey(33))
		{
		case 27: //'esc' key has been pressed, exit program.
			LeftDevice->Stop();
			LeftDevice->CloseDevice();
			LeftDevice->DeviceUnInit();
			LeftDevice->Release();
			RightDevice->Stop();
			RightDevice->CloseDevice();
			RightDevice->DeviceUnInit();
			RightDevice->Release();
			IDevice::DeviceUnInitialSDK();
			return 0;
		case 100: //'d' has been pressed. this will debug mode
			debugMode = !debugMode;
			if (debugMode == false) printf("Debug mode disabled.\n");
			else printf("Debug mode enabled.\n");
			break;
		//case 112: //'p' has been pressed. this will pause/resume the code.
		//	pause = !pause;
		//	if (pause == true)
		//	{
		//		printf("Code paused, press 'p' again to resume\n");
		//		while (pause == true)
		//		{
		//			//stay in this loop until 
		//			switch (cvWaitKey())
		//			{
		//			case 112:
		//				//change pause back to false
		//				pause = false;
		//				printf("Code resumed.\n");
		//				break;
		//			}
		//		}
		//	}
		}
	}
	


	HANDLE multitask[4];
	multitask[0] = LeftCamReceive;
	multitask[1] = RightCamReceive;
	multitask[2] = LeftImgProcess;
	multitask[3] = RightImaProcess;
	WaitForMultipleObjects(2, multitask, TRUE, INFINITE);

	//for (int i = 0; i < 2; i++)
	//	CloseHandle(hThread[i]);
	//CloseHandle(g_hEmpty);
	//CloseHandle(g_hFull);
	//DeleteCriticalSection(&g_cs);
}
void CDialog3::OnBnClickedPlay()
{
	// TODO: 在此添加控件通知处理程序代码
	if(m_RunMode == RUNMODE_PLAY)
	{
		CameraStop(); //fp in dll
		CameraUnInit();
		this->SetDlgItemTextA(IDC_PLAY,"&Play");
		this->GetDlgItem(IDC_PLAY)->SetFocus();
		this->GetDlgItem(IDC_SAVEFILE)->EnableWindow(FALSE);
		this->GetDlgItem(IDC_SETUP)->EnableWindow(FALSE);
		this->GetDlgItem(IDC_RESOLUTION)->EnableWindow(FALSE);
		this->GetDlgItem(IDC_SAVEIMG)->EnableWindow(FALSE);
		m_RunMode =RUNMODE_STOP;
		return ;
	}
	else
	{
		BYTE CamNum = this->m_MultiCamList.GetCurSel();//取得组合框当前选中项的下标
		if(this->m_MultiCamList.GetCount() == 0)
		{
			CamNum = 0;
		}
		if(R_ROI == m_Resolution)
		{
			CameraSetROI(m_HOff, m_VOff, m_Width, m_Height); //fp in dll ,to set the resolution
		}
		if(STATUS_OK != CameraInit(SnapThreadCallback, 
			                       m_Resolution,
								   m_pDlg->GetDlgItem(IDC_PICTURE)->m_hWnd, //NULL
								   CamNum+1,
								   m_pDlg))
		 { 
			 MessageBox("Init Camera failed","Error",MB_OK|MB_ICONSTOP);
			 return ;
		}

#ifdef ENABLE_READ_SN_DEBUG
		char SN[32];
		CameraReadSN(SN, 32);
		CString sSN;
		sSN = SN;
		
		CString sUserSN = "WWW.D-IMAGE.NET 0755-61860636";
		if (sSN == sUserSN)
		{
		//	MessageBox(x, "SN is OK!", MB_OK | MB_ICONSTOP);
		}
		else //检查不对,重写一次,写之前请确保EEPROM处于可写状态。
		{
			char* pAddr = sUserSN.GetBuffer(32);
			
			CameraWriteSN(pAddr, 32);

			char cNewSn[32];
			CameraReadSN(cNewSn, 32);
			CString sNewSN = cNewSn;

			if (sNewSN == sUserSN )
			{		
				MessageBox("SN Rewrite Ok!", "SN Error", MB_OK | MB_ICONSTOP);
			}
			else
			{
				MessageBox("SN Rewrite Error!", "SN Error", MB_OK | MB_ICONSTOP);
			}
			CameraUnInit();
			return;
		}
#endif
		// Set AWB Window
		{
			INT width = 0;
			INT hight = 0;
			CameraGetImageSize(&width, &hight);
			CameraSetWBWindow(width>>2, hight>>2, width>>1, hight>>1);
		}
		this->SetDlgItemText(IDC_PLAY, "Sto&p");
		this->GetDlgItem(IDC_SAVEFILE)->EnableWindow(TRUE);
		this->GetDlgItem(IDC_SETUP)->EnableWindow(TRUE);
		this->GetDlgItem(IDC_RESOLUTION)->EnableWindow(TRUE);
		this->GetDlgItem(IDC_SAVEIMG)->EnableWindow(TRUE);
		
		/*WM_USERDEFMSG 用户自定义信息,通过CameraSetMessage()函数得到相机
		Message ID;该Message ID含有Wparam和Lparam信息,将它们传递到信息
		响应函数OnVideoMsg()当中进行判断和处理*/
		CameraSetMessage(this->m_hWnd, WM_USERDEFMSG);
		CameraPlay();
		m_iVideoCnt = 0;
		m_iErrorFrames = 0;
		m_RunMode = RUNMODE_PLAY;
		return;
	}
}
Example #8
0
bool MVCAM::Init()
{
	//相机的设备信息
	tSdkCameraDevInfo sCameraList[10];
	INT iCameraNums = 10;//调用CameraEnumerateDevice前,先设置iCameraNums = 10,表示最多只读取10个设备,如果需要枚举更多的设备,请更改sCameraList数组的大小和iCameraNums的值
	CameraSdkStatus status;

	if (CameraEnumerateDevice(sCameraList, &iCameraNums) != CAMERA_STATUS_SUCCESS || iCameraNums == 0)
	{
		printf("No camera was found!");
		return FALSE;
	}

	//该示例中,我们只假设连接了一个相机。因此,只初始化第一个相机。(-1,-1)表示加载上次退出前保存的参数,如果是第一次使用该相机,则加载默认参数.
	//In this demo ,we just init the first camera.
	if ((status = CameraInit(&sCameraList[0], -1, -1, &m_hCamera)) != CAMERA_STATUS_SUCCESS)
	{
		char msg[128];
		sprintf_s(msg, "Failed to init the camera! Error code is %d", status);
		printf(msg);
		return FALSE;
	}


	//Get properties description for this camera.
	tSdkCameraCapbility sCameraInfo;
	CameraGetCapability(m_hCamera, &sCameraInfo);// 获得相机的属性


	CameraSetAeState(m_hCamera, FALSE);//设置相机曝光的模式。自动或者手动。bState:TRUE,使能自动曝光;FALSE,停止自动曝光。
	CameraSetExposureTime(m_hCamera, 1000 * ExposureTimeMS);//曝光时间10ms = 1000微秒*10
	CameraSetAnalogGain(m_hCamera, 10 * AnalogGain);//设置模拟增益16=1.6  该值乘以 CameraGetCapability  获得的相机属性结构体中sExposeDesc.fAnalogGainStep ,就得到实际的图像信号放大倍数。
	if (ColorType == CV_8U)
	{
		CameraSetMonochrome(m_hCamera, TRUE);//设置黑白图像
	}
	CameraSetFrameSpeed(m_hCamera, sCameraInfo.iFrameSpeedDesc - 1);//设定相机输出图像的帧率。iFrameSpeedSel:选择的帧率模式索引号,范围从 0 到CameraGetCapability 获得的信息结构体中	iFrameSpeedDesc - 1


	//申请空间
	m_pFrameBuffer = (BYTE *)CameraAlignMalloc(sCameraInfo.sResolutionRange.iWidthMax*sCameraInfo.sResolutionRange.iWidthMax * 3, 16);


	if (sCameraInfo.sIspCapacity.bMonoSensor)//ISP 能力描述,BOOL bMonoSensor; //表示该型号相机是否为黑白相机,如果是黑白相机,则颜色相关的功能都无法调节
	{
		CameraSetIspOutFormat(m_hCamera, CAMERA_MEDIA_TYPE_MONO8);
	}

	//创建该相机的属性配置窗口。
	CameraCreateSettingPage(m_hCamera, NULL, "cam", NULL, NULL, 0);//"通知SDK内部建该相机的属性页面";

	//CameraPlay(m_hCamera);//调用 CameraPlay 函数,让相机进入工作模式,并且 SDK 开始接收来自相机的图像。

	//相机初始化完成
	CameraShowSettingPage(m_hCamera, FALSE);//TRUE显示相机配置界面。FALSE则隐藏。

	tSdkImageResolution sRoiResolution;
	memset(&sRoiResolution, 0, sizeof(sRoiResolution));
	sRoiResolution.iIndex = 0xff;
	sRoiResolution.iWidth = 784;
	sRoiResolution.iWidthFOV = sRoiResolution.iWidth * 3;
	sRoiResolution.iHeight = 100;
	sRoiResolution.iHeightFOV = sRoiResolution.iHeight * 3;
	sRoiResolution.iWidthZoomHd = 0;
	sRoiResolution.iHeightZoomHd = 0;
	sRoiResolution.iHOffsetFOV = 128;
	sRoiResolution.iVOffsetFOV = 470;
	sRoiResolution.iWidthZoomSw = 0;
	sRoiResolution.iHeightZoomSw = 0;
	sRoiResolution.uBinAverageMode = 0;
	sRoiResolution.uBinSumMode = 0;
	sRoiResolution.uResampleMask = 0;
	sRoiResolution.uSkipMode = 2;
	CameraSetImageResolution(m_hCamera, &sRoiResolution);//设置预览的分辨率。

	HasInited = true;
	return true;
}
Example #9
0
/*
 * s_BSDCameraInit
 *
 *	初始化摄像头
 *
 *	输入:服务器端口
 *	返回:小于0,失败;0,成功
 */
static int s_BSDCameraInit(void)
{
	return CameraInit();
}