簡體   English   中英

如何獲得相機的分辨率

[英]How to get resolution of camera

  1. 如何獲得相機的分辨率? 有人可以給我一些建議嗎?
  2. 以下是我唯一能做的,但要花費太多時間才能獲得解決方案。
  3. 代碼的順序如下所示:a。打開相機b。更改相機的分辨率,然后檢查重用

     void GetResolution( const int& countOfCamera, resolution_t (&resoulationTemp)[MAX_RESOLUTION] ){ VideoCapture *pVideoCaptures[MAX_CAMERA] = {NULL}; bool ret1 = false; bool ret2 = false; for ( int j=0; j<countOfCamera; ++j ) { pVideoCaptures[j] = new VideoCapture(j); /*========================================================================== *If we don't do this, we will not open the Camera correctly ===========================================================================*/ pVideoCaptures[j]->set( CV_CAP_PROP_FRAME_WIDTH, defaultResolution.width ); pVideoCaptures[j]->set ( CV_CAP_PROP_FRAME_HEIGHT, defaultResolution.height ); } for ( int i=0; i<MAX_RESOLUTION; ++i ) { for ( int j=0; j<countOfCamera; ++j ) { ret1 = pVideoCaptures[j]->set( CV_CAP_PROP_FRAME_WIDTH, resolutions[i].width ); ret2 = pVideoCaptures[j]->set ( CV_CAP_PROP_FRAME_HEIGHT, resolutions[i].height ); if ( !(ret1 && ret2) ) { //The resolution is not OK break; //Check the next resolution } else if ( j == ( countOfCamera -1 ) ) { //The resolution is OK for all camera,then store it. resoulationTemp[i].width = resolutions[i].width; resoulationTemp[i].height = resolutions[i].height; } else { //Do nothing } } } for ( int j=0; j<countOfCamera; ++j ) //Release the memory { pVideoCaptures[j]->release(); delete pVideoCaptures[j]; pVideoCaptures[j] = NULL; } 

    }

不幸的是,沒有方便的方法來通過opencv API獲取特定攝像機的受支持的分辨率列表(因為它支持那么多平台和這么多視頻捕獲后端)。 甚至您的代碼也將因此而受苦,請閱讀videoio.hpp的源代碼。 但是大多數數字視頻設備都支持標准分辨率,您只需從中選擇即可。 獲取受支持格式的實際列表的另一種方法是使用第三方庫,例如Qt通過幾次調用解決了該任務。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM