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

📄 dscamera.cpp

📁 用于系统跟踪的程序
💻 CPP
字号:
#include "stdafx.h"
#include "DSCamera.h"
#include "objbase.h"
#include <sys/timeb.h>
#include <windows.h>
#pragma warning(disable : 4996)




static int      ss, sms;
void arUtilTimerReset(void)
{
 
    struct _timeb sys_time;

    _ftime(&sys_time);
    ss  = (int)sys_time.time;
    sms = (int)sys_time.millitm;
 

}

//初始化
int DSCamera::init(char* vconf)
{
	config=vconf;
	long frame_width;
	long frame_height;

	this->gVid=NULL;
	frame_timeout_ms = 0L;
	
    
	//打开摄像机
	gVid = VideoOpen(config);

	if(gVid!=NULL)
	{
		//得到摄像机的参数
		gVid->graphManager->GetCurrentMediaFormat(&frame_width, &frame_height,NULL,NULL);
		width = (int) frame_width;
		height = (int) frame_height;
		return 1;
	}

	return -1;
}


//构造函数,初始化摄像机
DSCamera::DSCamera(char* vconf)
{
	if(vconf=="0")return;
	config=vconf;
	long frame_width;
	long frame_height;

	this->gVid=NULL;
	frame_timeout_ms = 0L;
	
    
	//打开摄像机
	gVid = VideoOpen(config);

	if(gVid!=NULL)
	{
		//得到摄像机的参数
		gVid->graphManager->GetCurrentMediaFormat(&frame_width, &frame_height,NULL,NULL);
		width = (int) frame_width;
		height = (int) frame_height;
	}
}

 



void DSCamera::Sleep( int msec )
{
    //Sleep(msec);
    return;
}

//获取摄像机图像

unsigned char * DSCamera::GetImage()
{
	  
	arUtilTimerReset();
	DWORD wait_result=0;
	unsigned char* pixelBuffer;


	if (gVid == NULL) return (NULL);
	if (gVid->graphManager == NULL) return (NULL);
	
	wait_result = gVid->graphManager->WaitForNextSample(0L);
	if(wait_result == 0) {
		if (FAILED(gVid->graphManager->CheckoutMemoryBuffer(&(gVid->g_Handle), &pixelBuffer, NULL, NULL, NULL, &(gVid->g_Timestamp)))) return(NULL);
		return (pixelBuffer);
	}
	return(NULL);
}
 

//启动摄像机,开始捕捉视频
int DSCamera::RunCamera()
{
	if (gVid == NULL) return (-1);
	if (gVid->graphManager == NULL) return (-1);
	
	if(FAILED(gVid->graphManager->Run())) return (-1);
	return (0);
}
//获取下一桢图像
int DSCamera::VideoCapNext()
{
	if (gVid == NULL) return (-1);
	if (gVid->graphManager == NULL) return (-1);
	return (SUCCEEDED(gVid->graphManager->CheckinMemoryBuffer(gVid->g_Handle)) ? 0 : -1);
}

//打开摄像机

_VideoParamT * DSCamera::VideoOpen(char *config)
{
	_VideoParamT *vid = NULL;
	 
	// Allocate the parameters structure and fill it in.
	arMalloc(vid, _VideoParamT, 1);
	memset(vid, 0, sizeof(_VideoParamT));

	CoInitialize(NULL);
	
	vid->graphManager = new DSVL_VideoSource();
	
	if(FAILED(vid->graphManager->BuildGraphFromXMLFile(config))) return(NULL);
	if(FAILED(vid->graphManager->EnableMemoryBuffer())) return(NULL);

	return (vid);
}

//关闭摄像机
void DSCamera::Close()
{
    if (gVid == NULL) return;
	if (gVid->graphManager == NULL) return  ;
	//gVid->graphManager->CheckinMemoryBuffer(gVid->g_Handle, true);
	gVid->graphManager->Stop();
	delete gVid->graphManager;
	gVid->graphManager = NULL;
	free (gVid);
	gVid = NULL;
    return ;
}

⌨️ 快捷键说明

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