• 大小: 20.75MB
    文件类型: .zip
    金币: 2
    下载: 1 次
    发布日期: 2023-07-13
  • 语言: C/C++
  • 标签: 车辆计数  

资源简介

通过读取摄像头,获得图片进行图像处理,动态物体检测,通过经过的基准线的变化的像素数。检测通过路口的汽车数量。本人已经添加车辆计数功能。并亲测功能。OPENCV和C++的应用。需要自行调整摄像头。根据路口的位置自行设置基准线。内含 读取内置视频和读取外界摄像头程序。默认是读取摄像头 修改参数就可以调整为读取内存

资源截图

代码片段和文件信息

//////////////////////////////////////////////////////////////////////
// Video Capture using DirectShow
// Author: Shiqi Yu (shiqi.yu@gmail.com)
// Thanks to:
// HardyAI@OpenCV China
// flymanbox@OpenCV China (for his contribution to function CameraName and frame width/height setting)
// Last modification: April 9 2009
//////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////
// 使用说明:
//   1. 将CameraDS.h CameraDS.cpp以及目录DirectShow复制到你的项目中
//   2. 菜单 Project->Settings->Settings for:(All configurations)->C/C++->Category(Preprocessor)->Additional include directories
//      设置为 DirectShow/Include
//   3. 菜单 Project->Settings->Settings for:(All configurations)->link->Category(Input)->Additional library directories
//      设置为 DirectShow/Lib
//////////////////////////////////////////////////////////////////////

// CameraDS.cpp: implementation of the CCameraDS class.
//
//////////////////////////////////////////////////////////////////////
//#include “StdAfx.h“
#include “CameraDS.h“

#pragma comment(lib“Strmiids.lib“) 
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CCameraDS::CCameraDS()
{
m_bConnected = false;
m_nWidth = 0;
m_nHeight = 0;
m_bLock = false;
m_bChanged = false;
m_pframe = NULL;
m_nBufferSize = 0;

m_pNullFilter = NULL;
m_pMediaEvent = NULL;
m_pSampleGrabberFilter = NULL;
m_pGraph = NULL;

CoInitialize(NULL);
}

CCameraDS::~CCameraDS()
{
CloseCamera();
CoUninitialize();
}

void CCameraDS::CloseCamera()
{
if(m_bConnected)
m_pMediaControl->Stop();

m_pGraph = NULL;
m_pDeviceFilter = NULL;
m_pMediaControl = NULL;
m_pSampleGrabberFilter = NULL;
m_pSampleGrabber = NULL;
m_pGrabberInput = NULL;
m_pGrabberOutput = NULL;
m_pCameraOutput = NULL;
m_pMediaEvent = NULL;
m_pNullFilter = NULL;
m_pNullInputPin = NULL;


if (m_pframe)
cvReleaseImage(&m_pframe);

m_bConnected = false;
m_nWidth = 0;
m_nHeight = 0;
m_bLock = false;
m_bChanged = false;
m_nBufferSize = 0;
}

bool CCameraDS::OpenCamera(int nCamID bool bDisplayProperties int nWidth int nHeight)
{

HRESULT hr = S_OK;

CoInitialize(NULL);
// Create the Filter Graph Manager.
hr = CoCreateInstance(CLSID_FilterGraph NULL CLSCTX_INPROC
IID_IGraphBuilder (void **)&m_pGraph);

hr = CoCreateInstance(CLSID_SampleGrabber NULL CLSCTX_INPROC_SERVER 
IID_IbaseFilter (LPVOID *)&m_pSampleGrabberFilter);

hr = m_pGraph->QueryInterface(IID_IMediaControl (void **) &m_pMediaControl);
hr = m_pGraph->QueryInterface(IID_IMediaEvent (void **) &m_pMediaEvent);

hr = CoCreateInstance(CLSID_NullRenderer NULL CLSCTX_INPROC_SERVER
IID_IbaseFilter (LPVOID*) &m_pNullFilter);


hr = m_pGraph->AddFilter(m_pNullFilter L“NullRende

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-02-09 14:05  StereoVision_Vedio_Read1 - Copy (3) - Copy\
     目录           0  2017-02-08 14:16  StereoVision_Vedio_Read1 - Copy (3) - Copy\Debug\
     文件      124416  2017-02-09 13:30  StereoVision_Vedio_Read1 - Copy (3) - Copy\Debug\StereoVision_Vedio_Read.exe
     文件     2955740  2017-02-09 13:30  StereoVision_Vedio_Read1 - Copy (3) - Copy\Debug\StereoVision_Vedio_Read.ilk
     文件     2993152  2017-02-09 13:30  StereoVision_Vedio_Read1 - Copy (3) - Copy\Debug\StereoVision_Vedio_Read.pdb
     目录           0  2017-02-09 14:05  StereoVision_Vedio_Read1 - Copy (3) - Copy\StereoVision_Vedio_Read\
     文件       11607  2015-02-16 10:47  StereoVision_Vedio_Read1 - Copy (3) - Copy\StereoVision_Vedio_Read\CameraDS.cpp
     文件        3510  2015-02-16 10:48  StereoVision_Vedio_Read1 - Copy (3) - Copy\StereoVision_Vedio_Read\CameraDS.h
     文件         450  2015-02-16 10:47  StereoVision_Vedio_Read1 - Copy (3) - Copy\StereoVision_Vedio_Read\CameraDS_Debug.props
     文件         450  2015-02-16 10:47  StereoVision_Vedio_Read1 - Copy (3) - Copy\StereoVision_Vedio_Read\CameraDS_Release.props
     文件       67560  2015-10-06 08:37  StereoVision_Vedio_Read1 - Copy (3) - Copy\StereoVision_Vedio_Read\CarData.txt
     目录           0  2017-02-09 13:30  StereoVision_Vedio_Read1 - Copy (3) - Copy\StereoVision_Vedio_Read\Debug\
     文件       84088  2017-02-09 13:30  StereoVision_Vedio_Read1 - Copy (3) - Copy\StereoVision_Vedio_Read\Debug\CL.read.1.tlog
     文件        1874  2017-02-09 13:30  StereoVision_Vedio_Read1 - Copy (3) - Copy\StereoVision_Vedio_Read\Debug\CL.write.1.tlog
     文件      426553  2017-02-01 13:27  StereoVision_Vedio_Read1 - Copy (3) - Copy\StereoVision_Vedio_Read\Debug\CameraDS.obj
     文件        2757  2017-02-01 13:27  StereoVision_Vedio_Read1 - Copy (3) - Copy\StereoVision_Vedio_Read\Debug\StereoVision_Vedio_Read.Build.CppClean.log
     文件         111  2017-02-09 13:30  StereoVision_Vedio_Read1 - Copy (3) - Copy\StereoVision_Vedio_Read\Debug\StereoVision_Vedio_Read.lastbuildstate
     文件        2427  2017-02-09 13:30  StereoVision_Vedio_Read1 - Copy (3) - Copy\StereoVision_Vedio_Read\Debug\StereoVision_Vedio_Read.log
     文件        1722  2017-02-09 13:30  StereoVision_Vedio_Read1 - Copy (3) - Copy\StereoVision_Vedio_Read\Debug\cl.command.1.tlog
     文件           2  2017-02-09 13:30  StereoVision_Vedio_Read1 - Copy (3) - Copy\StereoVision_Vedio_Read\Debug\link-cvtres.read.1.tlog
     文件           2  2017-02-09 13:30  StereoVision_Vedio_Read1 - Copy (3) - Copy\StereoVision_Vedio_Read\Debug\link-cvtres.write.1.tlog
     文件           2  2017-02-09 13:30  StereoVision_Vedio_Read1 - Copy (3) - Copy\StereoVision_Vedio_Read\Debug\link-rc.read.1.tlog
     文件           2  2017-02-09 13:30  StereoVision_Vedio_Read1 - Copy (3) - Copy\StereoVision_Vedio_Read\Debug\link-rc.write.1.tlog
     文件           2  2017-02-09 13:30  StereoVision_Vedio_Read1 - Copy (3) - Copy\StereoVision_Vedio_Read\Debug\link.21616-cvtres.read.1.tlog
     文件           2  2017-02-09 13:30  StereoVision_Vedio_Read1 - Copy (3) - Copy\StereoVision_Vedio_Read\Debug\link.21616-cvtres.write.1.tlog
     文件           2  2017-02-09 13:30  StereoVision_Vedio_Read1 - Copy (3) - Copy\StereoVision_Vedio_Read\Debug\link.21616-rc.read.1.tlog
     文件           2  2017-02-09 13:30  StereoVision_Vedio_Read1 - Copy (3) - Copy\StereoVision_Vedio_Read\Debug\link.21616-rc.write.1.tlog
     文件           2  2017-02-09 13:30  StereoVision_Vedio_Read1 - Copy (3) - Copy\StereoVision_Vedio_Read\Debug\link.21616.read.1.tlog
     文件           2  2017-02-09 13:30  StereoVision_Vedio_Read1 - Copy (3) - Copy\StereoVision_Vedio_Read\Debug\link.21616.write.1.tlog
     文件           2  2017-02-09 13:30  StereoVision_Vedio_Read1 - Copy (3) - Copy\StereoVision_Vedio_Read\Debug\link.22096-cvtres.read.1.tlog
     文件           2  2017-02-09 13:30  StereoVision_Vedio_Read1 - Copy (3) - Copy\StereoVision_Vedio_Read\Debug\link.22096-cvtres.write.1.tlog
............此处省略27个文件信息

评论

共有 条评论