如何合并图像?

时间:2018-07-26 06:27:12

标签: c++ opencv

我的一个文件夹中有几张图像,我想将它们全部合并成一张图像。例如,如果我将所有字母都变成A B C D E F G H之类的图片形式,而我希望所有字母都在ABCDEFGH这样的图片中,依此类推。因此,请有人帮助我。

我尝试过的是:

int main()
{
    // Load images
    Mat3b img1 = imread("C:\\Users\\leno\\Documents\\640x480dove\\OCR_REF\\FONT-0.bmp");
    Mat3b img2 = imread("C:\\Users\\leno\\Documents\\640x480dove\\OCR_REF\\FONT-1.bmp");
    //Mat3b img3 = imread("C:\\Users\\leno\\Documents\\640x480dove\\OCR_REF\\FONT-2.bmp");

    // Get dimension of final image
    int rows = max(img1.rows, img2.rows);
    //int rows1 = max(img1.rows, img3.rows);
    int cols = img1.cols + img2.cols ;
    //int cols1 = img1.cols + img3.cols;

    // Create a black image
    Mat3b res(rows, cols, Vec3b(0, 0, 0));
    //Mat3b res1(rows1,cols1, Vec3b(0,0,0));

    // Copy images in correct position
    img1.copyTo(res(Rect(0, 0, img1.cols, img1.rows)));
    img2.copyTo(res(Rect(img1.cols, 0, img2.cols, img2.rows)));
    //img3.copyTo(res1(Rect(img1.cols, 0, img3.cols, img3.rows)));
    //img3.copyTo(res1(Rect(0, 0, img3.cols, img3.rows)));

    // Show result
    imshow("Img 1", img1);
    imshow("Img 2", img2);
    imshow("Result", res);
    //imshow("result", res1);
    waitKey(0);

    return 0;
}

1 个答案:

答案 0 :(得分:0)

只需确保<div class="control-list"> <table class="table data" data-control="rowlink"> <thead> <tr> <th><span>Jenis</span></th> <th><span>Jam</span></th> <th><span>Pelayan</span></th> <th style="width: 10%"><span></span></th> </tr> </thead> <tbody> <?php foreach ($kebumItems as $item): ?> <tr> <td><a href="javascript:;" data-control="popup" data-handler="onLoadUpdateItemForm" data-request-data="record_id: '<?= $item->id ?>'" data-size="large"> <?= e($item->jenis) ?></a> </td> <td><?= e($item->jam) ?></td> <td><?= e($item->pelayan) ?></td> <td class="nolink text-right"> <a href="javascript:;" data-request="onDeleteItem" data-request-data="record_id: '<?= $item->id ?>'" data-request-confirm="Delete this item?" class="oc-icon-remove" data-toggle="tooltip" title="Remove"></a> </td> </tr> <?php endforeach ?> </tbody> </table> </div> 可以处理任意数量的图像,以下是用于演示目的的示例代码段:

cv::hconcat()

输出为:

enter image description here