日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

ubuntu18.04 opencv 获取摄像头 (C++/python) 双目摄像头

發布時間:2023/12/14 python 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ubuntu18.04 opencv 获取摄像头 (C++/python) 双目摄像头 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

ubuntu18.04 opencv 獲取攝像頭 (C++/python)


第一版:

// g++ opencv-camera.cpp -o a.out `pkg-config --cflags --libs opencv` #include <opencv2/opencv.hpp> using namespace std; using namespace cv;int main() {VideoCapture cap(0);if (!cap.isOpened()) {cout << "Cannot open camera\n";return 1;}Mat frame;Mat gray;//namedWindow("live", WINDOW_AUTOSIZE); // 命名一個視窗,可不寫while (true) {// 擷取影像bool ret = cap.read(frame); // or cap >> frame;if (!ret) {cout << "Can't receive frame (stream end?). Exiting ...\n";break;}// 彩色轉灰階cvtColor(frame, gray, COLOR_BGR2GRAY);// 顯示圖片imshow("live", frame);//imshow("live", gray);// 按下 q 鍵離開迴圈if (waitKey(1) == 'q') {break;}}// VideoCapture 會自動在解構子裡釋放資源return 0; }

結果:


第二版:

#include <opencv2/core.hpp> #include <opencv2/videoio.hpp> #include <opencv2/highgui.hpp> #include <iostream> #include <stdio.h> using namespace cv; using namespace std; int main(int, char**) {Mat frame;//--- INITIALIZE VIDEOCAPTUREVideoCapture cap;// open the default camera using default API// cap.open(0);// OR advance usage: select any API backendint deviceID = 0; // 0 = open default cameraint apiID = cv::CAP_ANY; // 0 = autodetect default API// open selected camera using selected APIcap.open(deviceID, apiID);// check if we succeededif (!cap.isOpened()) {cerr << "ERROR! Unable to open camera\n";return -1;}//--- GRAB AND WRITE LOOPcout << "Start grabbing" << endl<< "Press any key to terminate" << endl;for (;;){// wait for a new frame from camera and store it into 'frame'cap.read(frame);// check if we succeededif (frame.empty()) {cerr << "ERROR! blank frame grabbed\n";break;}// show live and wait for a key with timeout long enough to show imagesimshow("Live", frame);if (waitKey(5) >= 0)break;}// the camera will be deinitialized automatically in VideoCapture destructorreturn 0; }

結果:

參考:

  • https://anishdubey.com/read-write-display-video-opencv
  • https://docs.opencv.org/4.x/d8/dfe/classcv_1_1VideoCapture.html
  • 總結

    以上是生活随笔為你收集整理的ubuntu18.04 opencv 获取摄像头 (C++/python) 双目摄像头的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。