2016年3月15日 星期二

Get a list of Camera Devices using OpenCV

Get a list of Camera Devices using OpenCV

使用方式為依序輸入每一個device,直到回傳 null or false代表找不到裝置為止

C API

CvCapture *cap;
int device_counts = 0;
while ( true ) {
    cap = cvCreateCameraCapture( device_counts++ );
    if ( cap == NULL ) {
        break;
    }
    cvReleaseCapture(&cap);
}
cvReleaseCapture(&cap);
std::cout << "devices count : " << device_counts - 1 << std::endl;

C++ API

cv::VideoCapture camera;
int device_counts = 0;
while ( true ) {
    if ( !camera.open(device_counts++) ) {
        break;
    }
}
camera.release();
std::cout << "devices count : " << device_counts - 1 << std::endl;

更多OpenCV文章請參考:OpenCV Tutorial (學習筆記)

0 意見:

張貼留言