【opencv】3.在一个opencv窗口中显示多个视频界面、画箭头、画掉头箭头
生活随笔
收集整理的這篇文章主要介紹了
【opencv】3.在一个opencv窗口中显示多个视频界面、画箭头、画掉头箭头
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
1.在一個opencv窗口中顯示不同視頻界面
/** * @brief 在一個opencv窗口win_name中顯示不同視頻界面 * @param img_1 和 img_2 是分別是取自不同視頻中的一幀 cv::Mat **/ void Draw(cv::Mat &img_1, cv::Mat &img_2) {cv::Mat img =cv::Mat(1080, 1920, CV_8UC3, cv::Scalar(0, 0, 0)); //(1080h,1920w)if (img_1.data != NULL) {cv::Mat img_tmp;//把img_1 resize 為img_tmp,尺寸變?yōu)?950w, 540hcv::resize(img_1, img_tmp, cv::Size(950, 540)); cv::Rect roi(0, 270, 950, 540); //定義一個矩形roi//將img_tmp復(fù)制到img中roi指定的矩形位置img_tmp.copyTo(img(roi)); }if (img_2.data != NULL) {cv::Mat img_tmp;cv::resize(img_2, img_tmp, cv::Size(960, 540));cv::Rect roi(960, 270, 960, 540);img_tmp.copyTo(img(roi));}std::string win_name = "window";cv::namedWindow(win_name, CV_WINDOW_NORMAL);// cv::resizeWindow(camra_name, 1280, 960);cv::resizeWindow(win_name, 1920, 1080);cv::imshow(win_name, img);cv::waitKey(1); }2.opencv畫掉頭的箭頭
/*** @brief 畫掉頭的箭頭* @param x和y:是掉頭箭頭的起筆點(diǎn)在像素坐標(biāo)系中的橫縱坐標(biāo)* @param scale: 是設(shè)置掉頭箭頭大小的尺度* **/ void DrawUturnArroW(cv::Mat &img, const int x, const int y,const float scale, const cv::Scalar &color) {cv::Point a = cv::Point(x, y); //起筆點(diǎn)cv::Point b = cv::Point(x, y - 20 * scale);cv::Point c = cv::Point(x - 10 * scale, y - 20 * scale);cv::Point d = cv::Point(x - 10 * scale, y - 5 * scale);cv::Point e = cv::Point(x - 5 * scale, y - 10 * scale);cv::Point f = cv::Point(x - 15 * scale, y - 10 * scale);cv::line(img, a, b, color, 3); //掉頭箭頭右邊直線部分cv::line(img, b, c, color, 3); //掉頭箭頭的橫線cv::line(img, c, d, color, 3); //掉頭箭頭的左邊豎線cv::line(img, d, e, color, 3); //掉頭箭頭尖的左邊cv::line(img, d, f, color, 3); //掉頭箭頭尖的右邊 } #include <iostream> #include "opencv2/opencv.hpp"int main() {cv::Mat img(200, 200, CV_8UC3); DrawUturnArroW(img,100,100,2,cv::Scalar(0,0,255) );cv::imwrite("b.png",img); }編譯方法
g++ `pkg-config opencv --cflags` test.cpp -std=c++11 -o test `pkg-config opencv --libs`以下是掉頭箭頭結(jié)果圖:
3.opencv畫箭頭
void DrawArrow(cv::Mat &img, cv::Point pStart, cv::Point pEnd, int len,int alpha, cv::Scalar &color, int thickness,int lineType) {const double PI = 3.1415926;cv::Point arrow;double angle =atan2((double)(pStart.y - pEnd.y), (double)(pStart.x - pEnd.x));cv::line(img, pStart, pEnd, color, thickness, lineType);arrow.x = pEnd.x + len * cos(angle + PI * alpha / 180);arrow.y = pEnd.y + len * sin(angle + PI * alpha / 180);cv::line(img, pEnd, arrow, color, thickness, lineType);arrow.x = pEnd.x + len * cos(angle - PI * alpha / 180);arrow.y = pEnd.y + len * sin(angle - PI * alpha / 180);cv::line(img, pEnd, arrow, color, thickness, lineType); } #include <iostream> #include "opencv2/opencv.hpp"int main() {cv::Mat img(200, 200, CV_8UC3);DrawArrow(img,cv::Point(100,140),cv::Point(100,100),10,45,cv::Scalar(0,0,255),5,8 );cv::imwrite("b.png",img);//cv::imshow("a",img);//cv::waitKey(0); }以下是箭頭結(jié)果圖,可以為左轉(zhuǎn)右轉(zhuǎn)等:
總結(jié)
以上是生活随笔為你收集整理的【opencv】3.在一个opencv窗口中显示多个视频界面、画箭头、画掉头箭头的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【C++】34. gflags中的 --
- 下一篇: 【自动驾驶】18.像素坐标系【2D To