zoukankan      html  css  js  c++  java
  • openCV图像合成

    #include <iostream>
    #include <opencv2/opencv.hpp>
    #include <opencv2/highgui/highgui.hpp>
    //#include <opencv2/cvaux.hpp>
    #include <fstream>
    using namespace std;
    using namespace cv;
    
    int main()
    {
        Mat image1=imread("/Users/war/Desktop/2.jpeg");
        Mat image2=imread("/Users/war/Desktop/1.jpeg");
        if (image1.empty() || image2.empty())
        {
            printf("open error");
            return 0;
        }
        //1.新建一个要合并的图像
        Mat img_merge;
        Size size(image1.cols + image2.cols, MAX(image1.rows, image1.rows));
        img_merge.create(size, CV_MAKETYPE(image1.depth(), 3));
        img_merge = Scalar::all(0);
        Mat outImg_left, outImg_right;
        //2.在新建合并图像中设置感兴趣区域
        outImg_left = img_merge(Rect(0, 0, image1.cols, image1.rows));
        outImg_right = img_merge(Rect(image1.cols, 0, image1.cols, image1.rows));
        //3.将待拷贝图像拷贝到感性趣区域中
        image1.copyTo(outImg_left);
        image2.copyTo(outImg_right);
        namedWindow("image1", 0);
        imshow("image1", img_merge);
        waitKey();
        return 0;
    }

    openCV图像合成

    #include <iostream>
    #include <opencv2/opencv.hpp>
    #include <opencv2/highgui/highgui.hpp>
    //#include <opencv2/cvaux.hpp>
    #include <fstream>
    using namespace std;
    using namespace cv;
    
    int main()
    {
        Mat image1=imread("/Users/war/Desktop/1.jpeg");
        Mat image2=imread("/Users/war/Desktop/2.jpeg");
        if (image1.empty() || image2.empty())
        {
            printf("open error");
            return 0;
        }
        //push_back 方法将图像2拷贝到图像1的最后一行
        Mat img_merge;
        img_merge.push_back(image1);
        img_merge.push_back(image2);
        
        namedWindow("img_merge", 0);
        imshow("img_merge", img_merge);
        
        waitKey();
        return 0;
    }
    //#include <cv.h>
    #include <opencv2/core/core.hpp>
    #include<opencv2/highgui/highgui.hpp>
    //#include <highgui.h>
    #include <iostream>
    
    using namespace cv;
    using namespace std;
    int main()
    {
        double alpha = 0.5; double beta; double input;
        
        Mat src1, src2, dst;
        
        cout << " Simple Linear Blender " <<endl;
        cout << "-----------------------" << endl;
        cout << "* Enter alpha [0-1]: ";
        cin >> input;
        if (input >= 0.0 && input <= 1.0)
        {
            alpha = input;
        }
        
        /// Read image ( same size, same type ),注意,这里一定要相同大小,相同类型,否则出错
        src1 = imread("/Users/war/Desktop/1.png");
        src2 = imread("/Users/war/Desktop/2.png");
        
        if (!src1.data) { printf("Error loading src1 
    "); return -1; }
        if (!src2.data) { printf("Error loading src2 
    "); return -1; }
        
        /// Create Windows
        namedWindow("Linear Blend", 1);
        
        beta = (1.0 - alpha);
        addWeighted(src1, alpha, src2, beta, 0.0, dst);
        
        imshow("Linear Blend",dst);
        
        waitKey();
        return 0;
    }
    View Code
    //#include <cv.h>
    #include <opencv2/core/core.hpp>
    #include<opencv2/highgui/highgui.hpp>
    //#include <highgui.h>
    #include <iostream>
    
    using namespace cv;
    using namespace std;
    int main()
    {
        double alpha = 0.5; double beta; double input;
        
        Mat src1, src2, dst;
        
        cout << " Simple Linear Blender " <<endl;
        cout << "-----------------------" << endl;
        cout << "* Enter alpha [0-1]: ";
        cin >> input;
        if (input >= 0.0 && input <= 1.0)
        {
            alpha = input;
        }
        
        /// Read image ( same size, same type ),注意,这里一定要相同大小,相同类型,否则出错
        src1 = imread("/Users/war/Desktop/1.png");
        src2 = imread("/Users/war/Desktop/2.png");
        
        if (!src1.data) { printf("Error loading src1 
    "); return -1; }
        if (!src2.data) { printf("Error loading src2 
    "); return -1; }
        
        /// Create Windows
        namedWindow("Linear Blend", 1);
        
        beta = (1.0 - alpha);
        addWeighted(src1, alpha, src2, beta, 0.0, dst);
        
        imshow("Linear Blend",dst);
        
        waitKey();
        return 0;
    }
  • 相关阅读:
    JZYZOJ1311 邮局设置问题 dp
    备忘录和乱七八糟的体会
    Python strip、lstrip和rstrip的用法
    Linux jstack命令详解
    Linux EOF使用
    Linux 千万不要执行的10个命令
    Linux 浅谈Linux 操作系统的安全设置
    linux 使用 ionice 限制 Xen 虚拟机磁盘 IO
    Linux 实现rsyslog日志里面的IP地址记录 未测试
    linux 回收站的添加
  • 原文地址:https://www.cnblogs.com/war1111/p/10968134.html
Copyright © 2011-2022 走看看