欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

OpenCV—一个窗口拼接三个图

程序员文章站 2022-05-28 11:54:05
...

OpenCV—一个窗口拼接三个图

#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main()
{
    VideoCapture cap;
    cap.open(1);
   
    Mat mat_frame(Size(cap.get(CAP_PROP_FRAME_WIDTH)*3,cap.get(CV_CAP_PROP_FRAME_HEIGHT)),CV_8UC3);
    Mat mat_ROI0 = mat_frame( Rect(0,0,cap.get(CAP_PROP_FRAME_WIDTH),cap.get(CV_CAP_PROP_FRAME_HEIGHT)));
    Mat mat_ROI1 = mat_frame( Rect(cap.get(CAP_PROP_FRAME_WIDTH),0,cap.get(CAP_PROP_FRAME_WIDTH),cap.get(CV_CAP_PROP_FRAME_HEIGHT)));
    Mat mat_ROI2 = mat_frame( Rect(cap.get(CAP_PROP_FRAME_WIDTH)*2,0,cap.get(CAP_PROP_FRAME_WIDTH),cap.get(CV_CAP_PROP_FRAME_HEIGHT)));
    while(true)
    {
        Mat frame;
        cap >> frame;
        //mat_frame
        frame.copyTo(mat_ROI0);
        cvtColor(frame,frame,COLOR_BGR2HSV);
        frame.copyTo(mat_ROI1);
        cvtColor(frame,frame,COLOR_HSV2RGB);
        frame.copyTo(mat_ROI2);
        imshow("1",frame);
        imshow("2",mat_frame);
        //out.write(frame);
        if(waitKey(2) == 'q')
        {
            break;
        }
    }
    return 0;
}

OpenCV—一个窗口拼接三个图