Ask Your Question
0

how to reshape a mat like (1,3,height,width) to (height,width,3)?

asked 2019-05-08 22:23:25 -0600

lunasdejavu gravatar image

I am using opencv4.1 under windows 7x64 with visual studio 2015 I am implementing code to one in C++. But it makes me confused that how to do this

out = out.reshape(3, out.shape[2], out.shape[3])
out = out.transpose(1, 2, 0)

in opencv C++ version?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2019-05-08 22:59:18 -0600

dkurt gravatar image

Try cv::dnn::imagesFromBlob

edit flag offensive delete link more

Comments

how to initial cv::OutputArrayOfArrays result? I tried this code

  std::vector<std::vector<cv::Point>>  result;
    cv::dnn::imagesFromBlob(out, result);

it still failed

lunasdejavu gravatar imagelunasdejavu ( 2019-05-09 00:24:25 -0600 )edit

I tried

std::vector<std::vector<cv::Mat >> vectorOfImages;
cv::dnn::imagesFromBlob(out, vectorOfImages);
 but  the  size of vectorOfimages is only [1,height,width]
lunasdejavu gravatar imagelunasdejavu ( 2019-05-09 03:08:51 -0600 )edit

@lunasdejavu, Cannot reproduce. Here is my script:

import cv2 as cv
import numpy as np

batch_size = 16
blob = np.random.standard_normal([batch_size, 3, 44, 55]).astype(np.float32)
images = cv.dnn.imagesFromBlob(blob)
print(len(images))
print(images[0].shape)

which gives

16
(44, 55, 3)

So 16 images with 3 channels and 55 width, 44 height.

dkurt gravatar imagedkurt ( 2019-05-22 03:36:46 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2019-05-08 22:23:25 -0600

Seen: 3,563 times

Last updated: May 08 '19