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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

opencv打开相机获取图像并保存

發(fā)布時(shí)間:2023/12/8 编程问答 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 opencv打开相机获取图像并保存 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
#include<opencv2/opencv.hpp> #include<iostream>using namespace cv; using namespace std;Mat input_Image, Left_Image, Right_Image; //Mat矩陣//寫入圖像數(shù)據(jù) void save( int times ) {string a = "0";string leftImage = "left0.jpg"; //設(shè)置照片的名字格式string rightImage = "right0.jpg";//設(shè)置照片的名字格式int re_length = 1;a = to_string(times); //將int型數(shù)據(jù)轉(zhuǎn)換為string型//將字符串第4個(gè)位置(因?yàn)槭菑?開始算的)的1位字符替換為a;比如 a="1",則替換后為"left1.jpg"leftImage.replace(4, 1, a);//將字符串第5個(gè)位置(因?yàn)槭菑?開始算的)的1位字符替換為a;比如a="1",則替換后為"right1.jpg"rightImage.replace(5, 1, a);imwrite(leftImage, Left_Image); //將Left_Image(Mat型)中的圖像數(shù)據(jù)寫入到leftImage(string)中imwrite(rightImage, Right_Image); //將Right_Image(Mat型)中的圖像數(shù)據(jù)寫入到rightImage(string)中}//獲取圖像數(shù)據(jù) void setCam(int weight, int height, int num) {int state = 0;string Error;VideoCapture cam(0);int times = 1;/*設(shè)置緩存區(qū)大小*/cam.set(CV_CAP_PROP_FRAME_WIDTH, weight);cam.set(CV_CAP_PROP_FRAME_HEIGHT, height);while (! cam.isOpened() ) //報(bào)錯(cuò){Error = "camre is not open";return;}while (true){cam >> input_Image; //將獲取的影像數(shù)據(jù)傳入input_Image矩陣中//分為左右兩個(gè)窗口顯示獲取的圖像Left_Image = input_Image(Rect( 0, 0, input_Image.size().width / 2, input_Image.size().height));Right_Image = input_Image(Rect( input_Image.size().width / 2, 0, input_Image.size().width / 2, input_Image.size().height));//顯示圖像imshow("LeftImage", Left_Image);imshow("ReightImage", Right_Image);save( times );//保存圖像數(shù)據(jù)times += 1;//在等待的30毫秒期間如果按下Esc鍵或者循環(huán)保存圖片已經(jīng)有40張(左右各20張),則跳出循環(huán)if (27 == waitKey(30) || times > 20 )break;//waitKey(100)等待100毫秒waitKey(100);}}int main() {int weight = 1280; //圖像捕捉窗口的寬度int height = 480; //圖像捕捉窗口高度setCam( weight, height, 20 );system("pause"); //程序停止不關(guān)閉控制臺(tái)窗口return 0;}

總結(jié)

以上是生活随笔為你收集整理的opencv打开相机获取图像并保存的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。