欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

使用c++實(shí)現(xiàn)OpenCV繪制旋轉(zhuǎn)矩形圖形

 更新時(shí)間:2021年08月30日 17:28:53   作者:翟天保Steven  
這篇文章主要給大家介紹了使用c++實(shí)現(xiàn)OpenCV繪制圖形旋轉(zhuǎn)矩形的方法案例,通過圖文及代碼形式進(jìn)行了詳細(xì)的描述,有需要的朋友可以參考下,希望可以有所幫助

功能函數(shù)

// 繪制旋轉(zhuǎn)矩形
void DrawRotatedRect(cv::Mat mask,const cv::RotatedRect &rotatedrect,const cv::Scalar &color,int thickness, int lineType)
{
    // 提取旋轉(zhuǎn)矩形的四個(gè)角點(diǎn)
	cv::Point2f ps[4];
	rotatedrect.points(ps); 
    // 構(gòu)建輪廓線
	std::vector<std::vector<cv::Point>> tmpContours;    // 創(chuàng)建一個(gè)InputArrayOfArrays 類型的點(diǎn)集
	std::vector<cv::Point> contours;
	for (int i = 0; i != 4; ++i) {
		contours.emplace_back(cv::Point2i(ps[i]));
	}
	tmpContours.insert(tmpContours.end(), contours); 
    // 繪制輪廓,即旋轉(zhuǎn)矩形
	drawContours(mask, tmpContours, 0, color,thickness, lineType);  // 填充mask
}

測試代碼

#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
void DrawRotatedRect(cv::Mat mask, const cv::RotatedRect &rotatedrect, const cv::Scalar &color,int thickness, int lineType); 
int main()
{
	cv::Mat src = imread("test.jpg");
	cv::Mat result = src.clone();
	cv::RotatedRect rorect(cv::Point(src.cols / 2, src.rows / 2), cv::Size(1000, 800), 50);
	DrawRotatedRect(result, rorect, cv::Scalar(0, 255, 255), 5,16);
	imshow("original", src);
	imshow("result", result);
	waitKey(0);
	return 0;
}
// 繪制旋轉(zhuǎn)矩形
void DrawRotatedRect(cv::Mat mask,const cv::RotatedRect &rotatedrect,const cv::Scalar &color,int thickness, int lineType)
{
          // 提取旋轉(zhuǎn)矩形的四個(gè)角點(diǎn)
	cv::Point2f ps[4];
	rotatedrect.points(ps);
          // 構(gòu)建輪廓線
  	std::vector<std::vector<cv::Point>> tmpContours;    
          // 創(chuàng)建一個(gè)InputArrayOfArrays 類型的點(diǎn)集
	std::vector<cv::Point> contours;
	for (int i = 0; i != 4; ++i) {
		contours.emplace_back(cv::Point2i(ps[i]));
	}
	tmpContours.insert(tmpContours.end(), contours);

           // 繪制輪廓,即旋轉(zhuǎn)矩形
	drawContours(mask, tmpContours, 0, color,thickness, lineType);  // 填充mask
}

測試效果 

圖1 原圖
圖2 繪制旋轉(zhuǎn)矩形

繪制旋轉(zhuǎn)矩形首先需要得到旋轉(zhuǎn)矩形的位置坐標(biāo),我經(jīng)常配合cv::minAreaRect函數(shù)使用;

得到坐標(biāo)信息后,結(jié)合繪制輪廓線的drawContours函數(shù),即可完成。

以上就是使用c++實(shí)現(xiàn)OpenCV繪制圖形旋轉(zhuǎn)矩形的詳細(xì)內(nèi)容,更多關(guān)于c++實(shí)現(xiàn)OpenCV繪制的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評論