如何合并由for循环生成的图像数组

时间:2017-08-23 07:23:51

标签: python python-3.x

我有一组5张图片,我必须在(16,16)维度中调整它们的大小。然后,我必须将每个图像打印为列向量。

为此,我使用for循环来调整所有图像的大小,但我不能将它们合并到一个数组中。如果我想将5个图像的5个列矩阵并排打印为(256 * 5)维矩阵,我该怎么办?

接下来,我提供了迄今为止所做的代码:

import cv2
import numpy as np
import glob
import itertools
import xlsxwriter

folder="E:/DOCUMENT(M.TECHS)/New folder/word/*.png"
files = list(glob.glob (folder))

i=0
for i in files:
    abc=cv2.imread(i,0)
    d=(16,16)
    abc1=cv2.resize(abc,d,interpolation=cv2.INTER_AREA)
    r,c=abc1.shape
    width, height = abc1.shape
    arr = np.ravel(abc1)
    print(arr)

1 个答案:

答案 0 :(得分:0)

尝试将所有图像附加到数组,然后使用np.concatenate(.., axis=1)加入它们。例如,更改如下:

/**
 * Tries to show browser's promt for enabling flash
 *
 * Chrome starting from 56 version and Edge from 15 are disabling flash
 * by default. To promt user to enable flash, they suggest to send user to
 * flash player download page. Then this browser will catch such request
 * and show a promt to user:
 * https://www.chromium.org/flash-roadmap#TOC-Developer-Recommendations
 * In this method we are forcing such promt by navigating user to adobe
 * site in iframe, instead of top window
 */
function requestFlashPermission() {
    var iframe = document.createElement('iframe');
    iframe.src = 'https://get.adobe.com/flashplayer';
    iframe.sandbox = '';
    document.body.appendChild(iframe);
    document.body.removeChild(iframe);
}


var isNewEdge = (navigator.userAgent.match(/Edge\/(\d+)/) || [])[1] > 14;
var isNewSafari = (navigator.userAgent.match(/OS X (\d+)/) || [])[1] > 9;
var isNewChrome = (navigator.userAgent.match(/Chrom(e|ium)\/(\d+)/) || [])[2] > 56
    && !/Mobile/i.test(navigator.userAgent);
var canRequestPermission = isNewEdge || isNewSafari || isNewChrome;

if (!swfobject.hasFlashPlayerVersion('10') && canRequestPermission) {
    requestFlashPermission();
    // Chrome requires user's click in order to allow iframe embeding
    $(window).one('click', requestFlashPermission);
}