zoukankan      html  css  js  c++  java
  • OpenCV学习5-----使用Mat合并多张图像

    最近做实验需要对比实验结果,需要将几张图片拼在一起,直观对比。

    尝试用OpenCV解决。

    核心思想其实是   声明一个足够大的,正好容纳下那几张图片的mat,然后将拼图依次copy到大图片相应的位置。

    void mymerge()
    {
        string  path = "E:\laboratory\dataset\synthesisdata\bvhtransformdepthacquistion\action7\people1\";
        
        vector<Mat>input(20);
        for (int i = 0; i < 20;i++)
        {
            stringstream ss;
            ss << path << i << ".jpg";
            input[i] = imread(ss.str());        
        }
    
        Size bigsize(input[0].cols * 10, input[0].rows*2);//合并后图片size
            
        vector<Mat>temp(20);
    
        Mat mergefinal;
        mergefinal.create(bigsize, CV_MAKETYPE(input[0].depth(), 3));//rgb 3通道
        mergefinal = Scalar::all(0);
    
        for (int i = 0; i < 20;i++)
        {
            if (i<10)temp[i] = mergefinal(Rect(i*input[0].cols, 0, input[0].cols, input[0].rows));
            else temp[i] = mergefinal(Rect((i - 10)*input[0].cols, input[0].rows, input[0].cols, input[0].rows));
            input[i].copyTo(temp[i]); //copy图片到对应位置
        }
    
        imshow("merge", mergefinal);
        imwrite("merge.jpg", mergefinal);
    
        waitKey(0);
    }

    效果:

    参考:

    http://blog.csdn.net/zuiyuchenfeng/article/details/9141051

  • 相关阅读:
    Leetcode#145 Binary Tree Postorder Traversal
    Leetcode#146 LRU Cache
    单引号和双引号的区别
    $* $@ $#
    pthread_detach
    pthread_join
    intent 启动activity、service的方法
    multicast based on udp
    ARM指令系统
    ARM寄存器
  • 原文地址:https://www.cnblogs.com/hellowooorld/p/7989442.html
Copyright © 2011-2022 走看看