摄像头参数查看与调节

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/Paul_C_V/article/details/40923139

cvGetCaptureProperty

获得视频获取结构的属性

double cvGetCaptureProperty( CvCapture* capture, int property_id );
capture
视频获取结构。
property_id
属性标识。可以是下面之一:
CV_CAP_PROP_POS_MSEC - 影片目前位置,为毫秒数或者视频获取时间戳
CV_CAP_PROP_POS_FRAMES - 将被下一步解压/获取的帧索引,以0为起点
CV_CAP_PROP_POS_AVI_RATIO - 视频文件的相对位置(0 - 影片的开始,1 - 影片的结尾)
CV_CAP_PROP_FRAME_WIDTH - 视频流中的帧宽度
CV_CAP_PROP_FRAME_HEIGHT - 视频流中的帧高度
CV_CAP_PROP_FPS - 帧率
CV_CAP_PROP_FOURCC - 表示codec的四个字符 CV_CAP_PROP_FRAME_COUNT - 视频文件中帧的总数

函数cvGetCaptureProperty获得摄像头或者视频文件的指定属性。

译者注:有时候这个函数在cvQueryFrame被调用一次后,再调用cvGetCaptureProperty才会返回正确的数值。



cvSetCaptureProperty

设置视频获取属性

int cvSetCaptureProperty( CvCapture* capture, int property_id, double value );
capture
视频获取结构。
property_id
属性标识符。可以是下面之一:
CV_CAP_PROP_POS_MSEC - 从文件开始的位置,单位为毫秒
CV_CAP_PROP_POS_FRAMES - 单位为帧数的位置(只对视频文件有效)
CV_CAP_PROP_POS_AVI_RATIO - 视频文件的相对位置(0 - 影片的开始,1 - 影片的结尾)
CV_CAP_PROP_FRAME_WIDTH - 视频流的帧宽度(只对摄像头有效)
CV_CAP_PROP_FRAME_HEIGHT - 视频流的帧高度(只对摄像头有效)
CV_CAP_PROP_FPS - 帧率(只对摄像头有效)
CV_CAP_PROP_FOURCC - 表示codec的四个字符(只对摄像头有效)
value
属性的值。
函数cvSetCaptureProperty设置指定视频获取的属性。 目前这个函数对视频文件只支持: CV_CAP_PROP_POS_MSEC, CV_CAP_PROP_POS_FRAMES, CV_CAP_PROP_POS_AVI_RATIO


windows下可用:OpenCV2.3.1 + vs2012,ubuntu下无法使用:vim + OpenCV2.3.4。

 
The solution is to use the newer libv4l-based wrapper.
1. install libv4l-dev (this is how it's called in Ubuntu)
2. rerun cmake, you will see "V4L/V4L2: Using libv4l"
3. rerun make. now the resolution can be changed. tested with built-in isight on MBP.
 
下载并安装v4l (video for linux).
下载v4l-utils-0.8.5.tar.bz2 from http://www.linuxtv.org/downloads/v4l-utils/
Build v4l :
make
sudo make install

or
#install v4l
$ sudo apt-cache search v4l
$ sudo apt-get install libv4l-dev

展开阅读全文

wince 下摄像头分辩率的调节

03-26

我的代码和下面的这个差不多,因为公司不让所以不能发,不好意思。rn1.初始化rnHRESULT hr = S_OK;rnhr = CoInitializeEx(NULL,COINIT_MULTITHREADED );rnif(FAILED(hr))rnrnOutputDebugString(L"CoInitializeEx Failed!\r\n");rnCoUninitialize();rnreturn FALSE;rnrnrn// 创建ICaptureGraphBuilder2接口rnhr = CoCreateInstance(CLSID_CaptureGraphBuilder, NULL, CLSCTX_INPROC, IID_ICaptureGraphBuilder2,(void**)&pCaptureGraphBuild);rnif(FAILED(hr))rnrnOutputDebugString(L"CoCreateInstance CaptureGraphBuilder Failed!\r\n");rnreturn FALSE;rnrnrn// 创建IGraphBuilder接口rnhr = CoCreateInstance(CLSID_FilterGraph,NULL,CLSCTX_INPROC,IID_IGraphBuilder,(void**)&pGraphBuilder);rnif(FAILED(hr))rnrnOutputDebugString(L"CoCreateInstance GraphBuilder Failed!\r\n");rnreturn FALSE;rnrnrnhr = pCaptureGraphBuild->SetFiltergraph(pGraphBuilder);rnif(FAILED(hr))rnrnOutputDebugString(L"pCaptureGraphBuild SetFiltergraph GraphBuilder Failed!\r\n");rnreturn FALSE;rnrn2.查找CamerarnGUID guidCamera = 0xCB998A05, 0x122C, 0x4166, 0x84, 0x6A, 0x93, 0x3E, 0x4D, 0x7E, 0x3C, 0x86 ;rn// Note about the above: The driver material doesn't ship as part of the SDK. This GUID is hardcodedrn// here to be able to enumerate the camera drivers and pass the name of the driver to the video capture filterrnrndi.dwSize = sizeof(di);rnrnhandle = FindFirstDevice( DeviceSearchByGuid, &guidCamera, &di );rnif(( handle == NULL ) || ( di.hDevice == NULL ))rnrnOutputDebugString(L"FindCameraDevice Failed!\r\n");rnreturn FALSE;rnrnrnFindClose( handle );rnvarCamName = di.szLegacyName;rnPropBag.Write( _T("VCapName"), &varCamName );rnrnhr = CoCreateInstance(CLSID_VideoCapture, NULL, CLSCTX_INPROC,IID_IBaseFilter, (void**)&pBaseFilter);rnif(FAILED(hr))rnrnOutputDebugString(L"CoCreateInstance pBaseFilter Failed!\r\n");rnreturn FALSE;rnrnrnhr = pBaseFilter->QueryInterface(IID_IPersistPropertyBag,(void**)&pPropertyBag );rnif(FAILED(hr))rnrnOutputDebugString(L"pBaseFilter QueryInterface pPropertyBag Failed!\r\n");rnreturn FALSE;rnrnpPropertyBag->Load( &PropBag, NULL );rnrnhr = pGraphBuilder->AddFilter(pBaseFilter,_T("Video Capture Filter"));rnif(FAILED(hr))rnrnOutputDebugString(L"pGraphBuilder AddFilter pBaseFilter Failed!\r\n");rnreturn FALSE;rnrnrnhr = pCaptureGraphBuild->RenderStream (&PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video,pBaseFilter, NULL, NULL);rnif (FAILED(hr))rnrnOutputDebugString(TEXT("Couldn't render the video capture stream.\r\n"));rnpBaseFilter->Release();rnreturn hr;rnrnrnpBaseFilter->Release();rn3.连接rnHRESULT hr = S_OK;rnIMediaControl* pMediaControl = NULL;rnIVideoWindow* pVideoWindow = NULL;rnrn//查询IMediaControl接口rnhr = pGraphBuilder->QueryInterface(IID_IMediaControl,(void**)&pMediaControl);rnif(FAILED(hr))rnrnOutputDebugString(L"pGraphBuilder QueryInterface pMediaControl Failed!\r\n");rnreturn FALSE;rnrnrn//查询IVideoWindowrnhr = pGraphBuilder->QueryInterface(IID_IVideoWindow,(void**)&pVideoWindow);rnif(FAILED(hr))rnrnOutputDebugString(L"pGraphBuilder QueryInterface pVideoWindow Failed!\r\n");rnpMediaControl->Release();rnreturn FALSE;rnrnrnhr = pGraphBuilder->QueryInterface(IID_IMediaEventEx, (void **)&pMediaEvent);rnif(FAILED(hr))rnrnOutputDebugString(L"pGraphBuilder QueryInterface pMediaEvent Failed!\r\n");rnreturn FALSE;rnrnrnhr = pMediaEvent->SetNotifyWindow((OAHWND)g_hWnd,WM_GRAPHNOTIFY,0);//自定义消息WM_GRAPHNOTIFY,到第三步里Wndproc里得到该消息rnhr = pVideoWindow->put_Owner(OAHWND(g_hWnd));rnif(FAILED(hr))rnrnOutputDebugString(L"pVideoWindow put_Owner Failed!\r\n");rnreturn FALSE;rnrnrnhr = pVideoWindow->put_WindowStyle(WS_CHILD | WS_CLIPCHILDREN);rnif(FAILED(hr))rnrnOutputDebugString(L"pVideoWindow put_WindowStyle Failed!\r\n");rnreturn FALSE;rnrnrnhr = pVideoWindow->put_Visible(OATRUE);rnif(FAILED(hr))rnrnOutputDebugString(L"pVideoWindow put_Visible Failed!\r\n");rnreturn FALSE;rnrnrnhr = pVideoWindow->SetWindowPosition(0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));rnif(FAILED(hr))rnrnOutputDebugString(L"pVideoWindow SetWindowPosition Failed!\r\n");rnreturn FALSE;rnrnrnhr = pVideoWindow->put_FullScreenMode(OATRUE);rnhr = pMediaControl->Run();//开始视频捕捉rnif(FAILED(hr))rnrnOutputDebugString(L"pMediaControl Run Failed!\r\n");rnrnreturn FALSE;rnrn4.播放rncase WM_GRAPHNOTIFY:rnHandleGraphEvent();rnHRESULT HandleGraphEvent(void)rnrnLONG evCode, evParam1, evParam2;rnHRESULT hr=S_OK;rnrn// Make sure that we don't access the media event interfacern// after it has already been released.rnif (!pMediaEvent)rnreturn S_OK;rnrn// Process all queued eventsrnwhile(SUCCEEDED(pMediaEvent->GetEvent(&evCode, (LONG_PTR *) &evParam1,rn(LONG_PTR *) &evParam2, 0)))rnrn// Free memory associated with callback, since we're not using itrnhr = pMediaEvent->FreeEventParams(evCode, evParam1, evParam2);rnrn// If this is the end of the clip, reset to beginningrnif(EC_COMPLETE == evCode)rnrnLONGLONG pos=0;rnrn// Reset to first frame of moviernhr = pMediaSeeking->SetPositions(&pos, AM_SEEKING_AbsolutePositioning ,NULL, AM_SEEKING_NoPositioning);rnif (FAILED(hr))rnrn// Some custom filters (like the Windows CE MIDI filter)rn// may not implement seeking interfaces (IMediaSeeking)rn// to allow seeking to the start. In that case, just stoprn// and restart for the same effect. This should not bern// necessary in most cases.rnif (FAILED(hr = pMediaControl->Stop()))rnrn//Msg(TEXT("Failed(0x%08lx) to stop media clip!\r\n"), hr);rnbreak;rnrnrnif (FAILED(hr = pMediaControl->Run()))rnrn//Msg(TEXT("Failed(0x%08lx) to reset media clip!\r\n"), hr);rnbreak;rnrnrnrnrnrnreturn hr;rnrnrnrn我现在在UT6410上,我不管如何把窗口调大,我抓到的图片,都 是320*240的,我把代码都看了,不知道如何调节,希望有人,能帮我下。谢谢。rn 论坛

没有更多推荐了,返回首页