⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 camera.cpp

📁 用vc编写的视频采集端口编成
💻 CPP
📖 第 1 页 / 共 4 页
字号:
// Camera.cpp: implementation of the CCamera class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Camera.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CCamera::CCamera()
{
	char lpstrValue[100], lpstrTemp[10], lpszMessage[100];
	DWORD cbData = 100, dwType;
	unsigned long dwRtValue;
	int i, j, k;


	//----------------------------------------------------------
	// Initiate Infomation about pan&tilt device
	HKEY hKey;
	if(RegOpenKeyEx(HKEY_CURRENT_USER, "software\\doggle\\AirGuard\\Pan&Tilt", 0, KEY_ALL_ACCESS, &hKey) != ERROR_SUCCESS)
		MessageBox(NULL, "Calling RegOpenKeyEx error", "error", MB_OK | MB_ICONERROR);


	// Initiate dwPanSpeed
	cbData = 100;
	dwRtValue = RegQueryValueEx(hKey, "PanSpeed", NULL, &dwType, (LPBYTE)lpstrValue, &cbData);
	if (dwRtValue != ERROR_SUCCESS){
	
		sprintf(lpszMessage, "找不到指定文件, 请与供应商联系");
		MessageBox(NULL, lpszMessage, "error", MB_OK | MB_ICONERROR);
		dwPanSpeed = 1;
	}
	else
		dwPanSpeed = *((DWORD*)lpstrValue);
	
	//Initate dwTiltSpeed
	cbData = 100;
	dwRtValue = RegQueryValueEx(hKey, "TiltSpeed", NULL, &dwType, (LPBYTE)lpstrValue, &cbData);
	if (dwRtValue != ERROR_SUCCESS){
		sprintf(lpszMessage, "找不到指定文件, 请与供应商联系");
		MessageBox(NULL, lpszMessage, "error", MB_OK | MB_ICONERROR);
		dwTiltSpeed = 1;
	}
	else
		dwTiltSpeed = *((DWORD*)lpstrValue);

	RegCloseKey(hKey);

	//----------------------------------------------------------
	// Initiate CameraList
	if(RegOpenKeyEx(HKEY_CURRENT_USER, "software\\doggle\\AirGuard\\Cameras", 0, KEY_ALL_ACCESS, &hKey) != ERROR_SUCCESS){
		MessageBox(NULL, "Calling RegOpenKeyEx error", "error", MB_OK | MB_ICONERROR);
		return;
	}

	char lpszValueLong[500];
	for(int iLoop = 0; iLoop < 16; iLoop ++){ // One time for each camera

		cbData = 500;
		sprintf(lpszMessage, "CmnQ%d", iLoop);
		dwRtValue = RegQueryValueEx(hKey, lpszMessage, NULL, &dwType, (LPBYTE)lpszValueLong, &cbData);
		if (dwRtValue != ERROR_SUCCESS){

			sprintf(lpszMessage, "找不到指定文件, 请与供应商联系");
			MessageBox(NULL, lpszMessage, "error", MB_OK | MB_ICONERROR);
			exit(0);
		}
		else{
			i = 0;	// Src pointer
			j = 0;	// Dst pointer
			k = 0;	// the No. k Chimney
			while((lpszValueLong[i] != '\0') && (k < 500)){
				while((lpszValueLong[i] != ',')&&(lpszValueLong[i] != '\0')){
					lpstrTemp[j] = lpszValueLong[i];
					i++;
					j++;
				}   // while
				lpstrTemp[j] = '\0';
				j = 0;
				pCameraList[iLoop].piCmnID[k] = atoi(lpstrTemp);

				// skip ','
				if(lpszValueLong[i] != '\0')
					i ++;
				k ++;
			} //while
			if(k < 500)
				while(k < 500){
					pCameraList[iLoop].piCmnID[k] = -1;
					k ++;
				}	// while
		}   // else

		//------------------------------------------------------------
		cbData = 500;
		sprintf(lpszMessage, "Address%d", iLoop);
		dwRtValue = RegQueryValueEx(hKey, lpszMessage, NULL, &dwType, (LPBYTE)lpszValueLong, &cbData);
		if (dwRtValue != ERROR_SUCCESS){

			sprintf(lpszMessage, "找不到指定文件, 请与供应商联系");
			MessageBox(NULL, lpszMessage, "error", MB_OK | MB_ICONERROR);
			return;
		}
		else{strcpy(pCameraList[iLoop].lpszAdress, lpszValueLong);}

		//------------------------------------------------------------
		cbData = 500;
		sprintf(lpszMessage, "Type%d", iLoop);
		dwRtValue = RegQueryValueEx(hKey, lpszMessage, NULL, &dwType, (LPBYTE)lpszValueLong, &cbData);
		if (dwRtValue != ERROR_SUCCESS){

			sprintf(lpszMessage, "找不到指定文件, 请与供应商联系");
			MessageBox(NULL, lpszMessage, "error", MB_OK | MB_ICONERROR);
			return;
		}
		else
			pCameraList[iLoop].iType = *((DWORD*)lpszValueLong);

		//------------------------------------------------------------
		cbData = 500;
		sprintf(lpszMessage, "Protocol%d", iLoop);
		dwRtValue = RegQueryValueEx(hKey, lpszMessage, NULL, &dwType, (LPBYTE)lpszValueLong, &cbData);
		if (dwRtValue != ERROR_SUCCESS){

			sprintf(lpszMessage, "找不到指定文件, 请与供应商联系");
			MessageBox(NULL, lpszMessage, "error", MB_OK | MB_ICONERROR);
			return;
		}
		else
			pCameraList[iLoop].iProtocol = *((DWORD*)lpszValueLong);

		//------------------------------------------------------------
		cbData = 500;
		sprintf(lpszMessage, "Port%d", iLoop);
		dwRtValue = RegQueryValueEx(hKey, lpszMessage, NULL, &dwType, (LPBYTE)lpszValueLong, &cbData);
		if (dwRtValue != ERROR_SUCCESS){

			sprintf(lpszMessage, "找不到指定文件, 请与供应商联系");
			MessageBox(NULL, lpszMessage, "error", MB_OK | MB_ICONERROR);
			return;
		}
		else
			pCameraList[iLoop].iAVPort = *((DWORD*)lpszValueLong);


	}  // for
	pCameraList[INVALIDCAMERA].iType = INVALID;

	RegCloseKey(hKey);

	//----------------------------------------------------------
	// Initiate fCriticalPointer
	if(RegOpenKeyEx(HKEY_CURRENT_USER, "software\\doggle\\AirGuard", 0, KEY_ALL_ACCESS, &hKey) != ERROR_SUCCESS){
		MessageBox(NULL, "Calling RegOpenKeyEx error", "error", MB_OK | MB_ICONERROR);
		return;
	}

	cbData = 100;
	dwRtValue = RegQueryValueEx(hKey, "CriticalPoint", NULL, &dwType, (LPBYTE)lpstrValue, &cbData);
	if (dwRtValue != ERROR_SUCCESS){
	//	FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwRtValue, 0, lpszMessage, 100, NULL);
		sprintf(lpszMessage, "找不到指定文件, 请与供应商联系");
		MessageBox(NULL, lpszMessage, "error", MB_OK | MB_ICONERROR);
		return;
	}
	else fCriticalPoint = (float)atof(lpstrValue);

	RegCloseKey(hKey);

	//----------------------------------------------------------
	// Initiate other member variables
	m_iCurrentChimney = -1;  // invalid chimney id
	m_iCurrentCamera = INVALIDCAMERA;  //invalid camera id
	/*m_iCurrentCamera = 15;
	m_iCurrentCamera = GetNextCameraID();*/
	*szCommandLine = '\0';

	pnSpeedTable[0] = 0x31;
	pnSpeedTable[1] = 0x7;
	pnSpeedTable[2] = 0xd;
	pnSpeedTable[3] = 0x15;
	pnSpeedTable[4] = 0x21;
	pnSpeedTable[5] = 0x35;
	pnSpeedTable[6] = 0x39;
	pnSpeedTable[7] = 0x3b;
	pnSpeedTable[8] = 0x3f;
	pnSpeedTable[9] = 0x40;

}

bool CCamera::InitCamera(HWND hWnd)
{
	return (InitComm(hWnd) == 0) ? 0 : 1;
}

DWORD CCamera::GetPanSpeed()
{
	return dwPanSpeed;
}

DWORD CCamera::GetTiltSpeed()
{
	return dwTiltSpeed;
}
bool CCamera::SetCriticalPoint(float fCriticalPoint)
// Function: Set critical point which will determine whether a blackness value is illegal or not.
//			 The fCriticalPoint and the corresponding value in the register
//				will be modified at the same time.

{
	fCriticalPoint = fCriticalPoint;
	char lpszBuffer[20];
	sprintf(lpszBuffer, "%f", fCriticalPoint);
	HKEY hKey;

	if(RegOpenKeyEx(HKEY_CURRENT_USER, "software\\doggle\\AirGuard", 0, KEY_ALL_ACCESS, &hKey) != ERROR_SUCCESS)
		MessageBox(NULL, "Calling RegOpenKeyEx error", "error", MB_OK | MB_ICONERROR);
	RegSetValueEx(hKey, "CriticalPoint", NULL, REG_SZ, (BYTE*)lpszBuffer, strlen(lpszBuffer));
	RegCloseKey(hKey);
	return 1;
}

bool CCamera::SetPanSpeed(DWORD ps)
{
	HKEY hKey;
	if((ps > 0) && (ps < 65)){
		dwPanSpeed = ps;

	
		if(RegOpenKeyEx(HKEY_CURRENT_USER, "software\\doggle\\AirGuard\\Pan&Tilt", 0, KEY_ALL_ACCESS, &hKey) != ERROR_SUCCESS){
			MessageBox(NULL, "Calling RegOpenKeyEx error", "error", MB_OK | MB_ICONERROR);
			return 0;
		}
		else{
			RegSetValueEx(hKey, "PanSpeed", NULL, REG_DWORD, (BYTE*)&dwPanSpeed, 4);
			RegCloseKey(hKey);
		}
		return 1;
	}

	else return false;
}

bool CCamera::SetTiltSpeed(DWORD ts)
{
	HKEY hKey;

	if((ts > 0) && (ts < 64)){
		dwTiltSpeed = ts;
		if(RegOpenKeyEx(HKEY_CURRENT_USER, "software\\doggle\\AirGuard\\Pan&Tilt", 0, KEY_ALL_ACCESS, &hKey) != ERROR_SUCCESS){
			MessageBox(NULL, "Calling RegOpenKeyEx error", "error", MB_OK | MB_ICONERROR);
			return 0;
		}
		else{
			RegSetValueEx(hKey, "TiltSpeed", NULL, REG_DWORD, (BYTE*)&dwTiltSpeed, 4);
			RegCloseKey(hKey);
		}
		return 1;
	}
	else return false;
}



bool CCamera::PanLeft()
{
	switch( pCameraList[m_iCurrentCamera].iType ){
		case JIMU:
			JIMU_PanLeft();
			break;
		case MPEG:
			MPEG_PanLeft();
			break;
		default:
			return 0;
	}
	return 1;

}

bool CCamera::StopPanLeft()
{
	switch( pCameraList[m_iCurrentCamera].iType ){
		case JIMU:
			JIMU_StopPanLeft();
			break;
		case MPEG:
			MPEG_StopPanLeft();
			break;
		default:
			return 0;
	}
	return 1;

}
bool CCamera::PanRight()
{
	switch( pCameraList[m_iCurrentCamera].iType ){
		case JIMU:
			JIMU_PanRight();
			break;
		case MPEG:
			MPEG_PanRight();
			break;
		default:
			return 0;
	}
	return 1;
}

bool CCamera::StopPanRight()
{
	switch( pCameraList[m_iCurrentCamera].iType ){
		case JIMU:
			JIMU_StopPanRight();
			break;
		case MPEG:
			MPEG_StopPanRight();
			break;
		default:
			return 0;
	}
	return 1;
}

bool CCamera::TiltUp()
{
	switch( pCameraList[m_iCurrentCamera].iType ){
		case JIMU:
			JIMU_TiltUp();
			break;
		case MPEG:
			MPEG_TiltUp();
			break;
		default:
			return 0;
	}
	return 1;
}

bool CCamera::StopTiltUp()
{
	switch( pCameraList[m_iCurrentCamera].iType ){
		case JIMU:
			JIMU_StopTiltUp();
			break;
		case MPEG:
			MPEG_StopTiltUp();
			break;
		default:
			return 0;
	}
	return 1;
}

bool CCamera::TiltDown()
{
	switch( pCameraList[m_iCurrentCamera].iType ){
		case JIMU:
			JIMU_TiltDown();
			break;
		case MPEG:
			MPEG_TiltDown();
			break;
		default:
			return 0;
	}
	return 1;
}

bool CCamera::StopTiltDown()
{
	switch( pCameraList[m_iCurrentCamera].iType ){
		case JIMU:
			JIMU_StopTiltDown();
			break;
		case MPEG:
			MPEG_StopTiltDown();
			break;
		default:
			return 0;
	}
	return 1;
}

bool CCamera::ZoomTelephoto()
{
	switch( pCameraList[m_iCurrentCamera].iType ){
		case JIMU:
			JIMU_ZoomTelephoto();
			break;
		case MPEG:
			MPEG_ZoomTelephoto();
			break;
		default:
			return 0;
	}
	return 1;
}

bool CCamera::StopZoomTelephoto()
{
	switch( pCameraList[m_iCurrentCamera].iType ){
		case JIMU:
			JIMU_StopZoomTelephoto();
			break;
		case MPEG:
			MPEG_StopZoomTelephoto();
			break;
		default:
			return 0;
	}
	return 1;
}

bool CCamera::ZoomWide()
{
	switch( pCameraList[m_iCurrentCamera].iType ){
		case JIMU:
			JIMU_ZoomWide();
			break;
		case MPEG:
			MPEG_ZoomWide();
			break;
		default:
			return 0;
	}
	return 1;
}

bool CCamera::StopZoomWide()
{
	switch( pCameraList[m_iCurrentCamera].iType ){
		case JIMU:
			JIMU_StopZoomWide();
			break;
		case MPEG:
			MPEG_StopZoomWide();
			break;
		default:
			return 0;
	}
	return 1;
}

bool CCamera::FocusNear()
{
	switch( pCameraList[m_iCurrentCamera].iType ){
		case JIMU:
			JIMU_FocusNear();
			break;
		case MPEG:
			MPEG_FocusNear();
			break;
		default:
			return 0;
	}
	return 1;
}

bool CCamera::StopFocusNear()
{
	switch( pCameraList[m_iCurrentCamera].iType ){
		case JIMU:
			JIMU_StopFocusNear();
			break;
		case MPEG:
			MPEG_StopFocusNear();
			break;
		default:
			return 0;
	}
	return 1;
}

bool CCamera::FocusFar()
{
	switch( pCameraList[m_iCurrentCamera].iType ){
		case JIMU:
			JIMU_FocusFar();
			break;
		case MPEG:
			MPEG_FocusFar();
			break;
		default:
			return 0;
	}
	return 1;
}

bool CCamera::StopFocusFar()
{
	switch( pCameraList[m_iCurrentCamera].iType ){
		case JIMU:
			JIMU_StopFocusFar();
			break;
		case MPEG:
			MPEG_StopFocusFar();
			break;
		default:
			return 0;
	}
	return 1;
}

bool CCamera::IrisOpen()
{
	switch( pCameraList[m_iCurrentCamera].iType ){
		case JIMU:
			JIMU_IrisOpen();
			break;
		case MPEG:
			MPEG_IrisOpen();
			break;
		default:
			return 0;
	}
	return 1;
}

bool CCamera::StopIrisOpen()
{
	switch( pCameraList[m_iCurrentCamera].iType ){
		case JIMU:
			JIMU_StopIrisOpen();
			break;
		case MPEG:
			MPEG_StopIrisOpen();
			break;
		default:
			return 0;
	}
	return 1;
}

bool CCamera::IrisClose()
{
	switch( pCameraList[m_iCurrentCamera].iType ){
		case JIMU:
			JIMU_IrisClose();
			break;
		case MPEG:
			MPEG_IrisClose();
			break;
		default:
			return 0;
	}
	return 1;
}

bool CCamera::StopIrisClose()
{
	switch( pCameraList[m_iCurrentCamera].iType ){
		case JIMU:
			JIMU_StopIrisClose();
			break;
		case MPEG:
			MPEG_StopIrisClose();
			break;
		default:
			return 0;
	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -