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

OpenCV實(shí)現(xiàn)相機(jī)標(biāo)定示例詳解

 更新時(shí)間:2021年11月25日 10:07:28   作者:語音余音玉印  
相機(jī)標(biāo)定是圖像處理的基礎(chǔ),現(xiàn)在市面上買到的相機(jī),都存在著或多或少的畸變。本文將介紹如何利用一系列棋盤照片進(jìn)行攝像機(jī)標(biāo)定的,感興趣的小伙伴可以關(guān)注一下

環(huán)境準(zhǔn)備

vs2015+opencv4.10安裝與配置

相機(jī)標(biāo)定

棋盤格圖片

可以自己生成,然后打印到A4紙上。(也可以去TB買一塊,平價(jià)買亞克力板的,不反光買氧化鋁材質(zhì),高精度買陶瓷的)

/**
* 生成棋盤格圖片
**/
int generateCalibrationPicture()
{
	//Mat frame = imread("3A4.bmp"); // cols*rows = 630*891  
	Mat frame(1600, 2580, CV_8UC3, Scalar(0, 0, 0));
	int nc = frame.channels();
	int nWidthOfROI = 320;
	for (int j = 10; j<frame.rows - 10; j++)
	{
		uchar* data = frame.ptr<uchar>(j);
		for (int i = 10; i<(frame.cols - 10)*nc; i += nc)
		{
			if ((i / nc / nWidthOfROI + j / nWidthOfROI) % 2)
			{
				// bgr  
				data[i / nc*nc + 0] = 255;
				data[i / nc*nc + 1] = 255;
				data[i / nc*nc + 2] = 255;
			}
		}
	}
	imshow("test", frame);
	//imwrite("3.bmp", frame);
	waitKey(0);
	return 0;
}

實(shí)時(shí)顯示相機(jī)的畫面

準(zhǔn)備一個(gè)相機(jī),我的是usb相機(jī)(羅技100多的)。

int displayCameraRealTime()
{
	//1.從攝像頭讀入視頻
	VideoCapture capture(0);
	if (!capture.isOpened()) {
		std::cout << "無法開啟攝像頭!" << std::endl;
		return -1;
	}
	//2.循環(huán)顯示每一幀
	while (1)
	{
		Mat cam;
		capture >> cam;//獲取當(dāng)前幀圖像
		namedWindow("實(shí)時(shí)相機(jī)畫面", WINDOW_AUTOSIZE);
		imshow("實(shí)時(shí)相機(jī)畫面", cam);//顯示當(dāng)前幀圖像
							  //imwrite(to_string(i) + ".png", cam);
		waitKey(20);//延時(shí)20ms
	}
}

效果如下圖:

在線標(biāo)定

把打印的棋盤格固定在板子上

/**
* 實(shí)時(shí)檢測角點(diǎn),按鍵保存角點(diǎn)參數(shù),達(dá)到數(shù)量執(zhí)行標(biāo)定并保存標(biāo)定結(jié)果
* @param numBoards			需要幾張標(biāo)定圖片,即獲取幾組角點(diǎn)參數(shù)
* @param boardSize			格子尺寸Size 7*4
* @param squareSize			格子尺寸 mm
* @param flipHorizontal		是否翻轉(zhuǎn)
*/
int calibrateCameraRealTime(int numBoards, cv::Size boardSize, float squareSize = 1, int delay = 50, bool flipHorizontal = false);

實(shí)時(shí)顯示相機(jī)畫面,按鍵保存能檢測到角點(diǎn)的 棋盤格圖片

int saveChessboardImages(cv::Size boardSize, string savePath)
{
	//1.從攝像頭讀入視頻
	VideoCapture capture(0);
	if (!capture.isOpened()) {
		std::cout << "無法開啟攝像頭!" << std::endl;
		return -1;
	}
	if (savePath != "./")
	{
		myMkdir(savePath);
	}
	//2.循環(huán)顯示每一幀
	while (1) {
		Mat image0, image;
		capture >> image0;
		// 將圖像復(fù)制到image
		image0.copyTo(image);
		// 查找標(biāo)定板(不對稱圓網(wǎng)格板)
		vector<Point2f> corners;
		//bool found = findCirclesGrid(image, boardSize, corners, CALIB_CB_ASYMMETRIC_GRID);
		bool found = findChessboardCorners(image, boardSize, corners, CALIB_CB_FAST_CHECK);
		// 畫上去
		drawChessboardCorners(image, boardSize, corners, found);
		int action = waitKey(30) & 255;
		// 判斷動(dòng)作
		if (action == ACTION_SPACE) { // 用戶按下了空格
			if (found) {
				// 保存圖片
				string imgFileName = savePath + getCurrentTime() + ".png";
				imwrite(imgFileName, image0);
				cout << imgFileName << " saved" << endl;
			}
			else {
				printf("%s\n", "未檢測到角點(diǎn)");
			}
		}
		else if (action == ACTION_ESC) { // 用戶按下了ESC
			break;
		}
		cv::imshow("Calibration", image);
	}
	cv::destroyAllWindows();
	return 1;
}

離線標(biāo)定

/**
* 離線相機(jī)標(biāo)定
* @param imagePath    標(biāo)定圖片存放路徑
* @param boardSize    格子尺寸Size 7*4
* @param squareSize   格子尺寸 mm
*/
int calibrateCameraOffLine(string imagePath, const Size boardSize, float squareSize = 1);

畸變矯正

/**
* 去畸變 1、本地圖片 2、實(shí)時(shí)相機(jī)圖像
* @param path		標(biāo)定參數(shù)存放路徑
* @param imagePath	需要矯正的圖片 存放路徑
*/
int undistortRectifyImage(string paraPath, string imagePath = " ");

矯正效果貌似不明顯

完整工程地址

到此這篇關(guān)于OpenCV實(shí)現(xiàn)相機(jī)標(biāo)定示例詳解的文章就介紹到這了,更多相關(guān)OpenCV 相機(jī)標(biāo)定內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論

南部县| 增城市| 海南省| 延吉市| 信阳市| 赣州市| 金阳县| 甘谷县| 邹平县| 治县。| 汶川县| 平和县| 黔东| 合川市| 沧源| 高平市| 施甸县| 色达县| 榆中县| 古蔺县| 岗巴县| 莎车县| 方城县| 汤阴县| 乌拉特中旗| 武安市| 鸡东县| 西青区| 龙川县| 本溪市| 沙洋县| 屯留县| 玛多县| 滦南县| 祁阳县| 会昌县| 郯城县| 望奎县| 喜德县| 瑞金市| 桐庐县|