最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

基于C++的攝像頭圖像采集及拼接程序的簡(jiǎn)單實(shí)現(xiàn)

 更新時(shí)間:2022年01月23日 12:47:32   作者:newlw  
本程序是在?ubuntu14.04?平臺(tái)下實(shí)現(xiàn)的,在本項(xiàng)目目錄下,已經(jīng)有編譯生成的可執(zhí)行程序,其中Camera_to_Frmae.cpp是我們從雙攝像頭實(shí)時(shí)抓取單幀圖像的源碼,對(duì)基于C++的攝像頭圖像采集及拼接程序的實(shí)現(xiàn)感興趣的朋友一起看看吧

程序的說(shuō)明

實(shí)現(xiàn)從攝像頭實(shí)時(shí)采集單幀圖像,之后完成圖像的拼接,本程序?qū)崿F(xiàn)了兩張圖片的拼接和三張圖片的拼接。

在此之前你需要在 linux 下安裝 opencv Package 這個(gè)包,因?yàn)楸境绦蛑饕褂?opencv 這個(gè)包中提供的 api 函數(shù)。

實(shí)現(xiàn)從攝像頭實(shí)時(shí)不同視角采集視頻的單幀圖像并保存實(shí)時(shí)采集的視頻文件之后,完成圖像的拼接,由于實(shí)驗(yàn)室設(shè)備有限,手頭只有兩個(gè)攝像頭一次只能抓取。

兩張不同視角的單幀圖像,我們抓取的單幀圖像保存在當(dāng)前項(xiàng)目目錄下的 frame1 和 frame2 文件夾中,因此我同時(shí)制作了兩個(gè)完成程序。

拼接的程序,一個(gè)實(shí)現(xiàn)完成兩個(gè)不同視角的圖像拼接,另一個(gè)實(shí)現(xiàn)三張不同視角的單幀圖像的拼接。其中的 testusb.cpp 文件是測(cè)試攝像頭的程序。在執(zhí)行本程序前,你應(yīng)該保證有兩個(gè)是攝像頭插在主機(jī)端口上,用于實(shí)時(shí)采集單幀圖像。

代碼介紹

在進(jìn)行程序的編譯前,請(qǐng)確定你已經(jīng)安裝了 opencv2.4.9 和 pkg-config 包,本程序是在 ubuntu14.04 平臺(tái)下實(shí)現(xiàn)的,在本項(xiàng)目目錄下,已經(jīng)有編譯生成的可執(zhí)行程序,其中 Camera_to_Frmae.cpp 是我們從雙攝像頭實(shí)時(shí)抓取單幀圖像的源碼。

  • ImageJoint.cpp 和 ImageJoint2.cpp、ImageJoint3.cpp 分別是完成兩張不同視角的圖像拼接和三張不同視角的圖像拼接程序,其中三張圖像拼接的圖像是我從網(wǎng)上找的現(xiàn)成的圖像庫(kù)
  • testusb.cpp 是我測(cè)試攝像頭的程序

程序編譯

g++ -o dst src.cpp \`pkg-config opencv --cflags --libs\` 

程序的執(zhí)行和退出

  • ./dst
  • 程序需要退出時(shí),按 Ctrl + C 快捷鍵

效果

從攝像頭設(shè)備采集兩張單幀圖像

圖像拼接效果圖

補(bǔ)充:c++利用opencv打開(kāi)攝像頭并且保存圖片

項(xiàng)目背景

利用一個(gè)usb雙目攝像機(jī)進(jìn)行雙目測(cè)距的項(xiàng)目,這個(gè)項(xiàng)目代碼有助于使用usb雙目攝像機(jī)打開(kāi)攝像機(jī)并且保存圖片

打開(kāi)雙目相機(jī)的函數(shù)

void SetCam(int weigth, int height, int num)
{
	string a = "0";
	string Error;
	VideoCapture Cam(0);
	/*設(shè)定緩沖區(qū)大小*/
	Cam.set(CV_CAP_PROP_FRAME_WIDTH, weigth);
	Cam.set(CV_CAP_PROP_FRAME_HEIGHT, height);

	while (!Cam.isOpened())
	{
		
		a = to_string(num);
		Error = "cannot open the camera1!";
		Error = Error.replace(22, 1, a);
		//Error.copy(error, 24, 0);//這里5代表復(fù)制幾個(gè)字符,0代表復(fù)制的位置,
	}
	
	//namedWindow("攝像頭");//關(guān)鍵一句代碼
	while (true) {
		Cam >> input_image;//將影像傳入圖片
		leftImage = input_image(Rect(0, 0, input_image.size().width / 2, input_image.size().height));//split left image
		rightImage = input_image(Rect(input_image.size().width / 2, 0, input_image.size().width / 2, input_image.size().height));
		imshow("leftImage", leftImage);//left image
		imshow("rightImage", rightImage);//right image
		Save(i, 20);
		if (27 == waitKey(30))
			break;
	return ;
}

保存圖片函數(shù)Save

void Save(int &imgnum, int amount)
{
	if (imgnum < amount)
	{
		a = to_string(imgnum);
		seat = floor((imgnum - 1) / 10);
		Left = Left.replace(4 + seat, 1, a);
		Right = Right.replace(5 + seat, 1, a);
		imwrite(Left, leftImage);
		imwrite(Right, rightImage);
		imgnum += 1;
	}
}

全部代碼

#include <opencv2/opencv.hpp>

#include<iostream>
using namespace cv;
using namespace std;
VideoCapture Cam1, Cam2;
const int  weigth = 1280;
const int height = 480;
static string Left = "Left0.jpg", Right = "Right0.jpg", a = "0";
static int seat = 0;
static Mat input_image, leftImage, rightImage;
static int i = 0;
void Save(int &imgnum, int amount)
{
	if (imgnum < amount)
	{
		a = to_string(imgnum);
		seat = floor((imgnum - 1) / 10);
		Left = Left.replace(4 + seat, 1, a);
		Right = Right.replace(5 + seat, 1, a);
		imwrite(Left, leftImage);
		imwrite(Right, rightImage);
		imgnum += 1;
	}
}
void SetCam(int weigth, int height, int num)
	string a = "0";
	string Error;
	VideoCapture Cam(0);
	/*設(shè)定緩沖區(qū)大小*/
	Cam.set(CV_CAP_PROP_FRAME_WIDTH, weigth);
	Cam.set(CV_CAP_PROP_FRAME_HEIGHT, height);
	while (!Cam.isOpened())
		
		a = to_string(num);
		Error = "cannot open the camera1!";
		Error = Error.replace(22, 1, a);
		//Error.copy(error, 24, 0);//這里5代表復(fù)制幾個(gè)字符,0代表復(fù)制的位置,
	
	//namedWindow("攝像頭");//關(guān)鍵一句代碼
	while (true) {
		Cam >> input_image;//將影像傳入圖片
		leftImage = input_image(Rect(0, 0, input_image.size().width / 2, input_image.size().height));//split left image
		rightImage = input_image(Rect(input_image.size().width / 2, 0, input_image.size().width / 2, input_image.size().height));
		imshow("leftImage", leftImage);//left image
		imshow("rightImage", rightImage);//right image
		Save(i, 20);
		if (27 == waitKey(30))
			break;
	return ;
void main()
	//char* error = "error";
	SetCam(weigth, height, 10);

到此這篇關(guān)于基于C++的攝像頭圖像采集及拼接程序的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)C++攝像頭圖像采集內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

西安市| 台南市| 唐河县| 云霄县| 丰都县| 靖州| 安吉县| 皋兰县| 石阡县| 长顺县| 陇西县| 宁乡县| 南汇区| 汉阴县| 保康县| 吉水县| 上蔡县| 林口县| 玉屏| 龙山县| 隆回县| 怀安县| 清新县| 冷水江市| 巢湖市| 乐业县| 河西区| 珲春市| 安西县| 伊宁市| 泰兴市| 确山县| 淮安市| 含山县| 环江| 武城县| 湾仔区| 乐亭县| 东乡| 陆丰市| 夏津县|