I'm trying to get a sequence of image from float vector (N, H, W, C), where each channel have float
values in the range 0..1.
What I'm trying to do for each image is:
- Convert float vector (HWC) to cv2
Mat
type. - Change RGB to BGR, and multiply 255 (to make values 0~255)
- Convert to uint8 type
Mat
. - Get image. (
imwrite
)
So I tried this in this way below. This code doesn't make error. but isn't working. Please let me know how to do this!
vector<float> output(batch_size * orig_height * orig_width*3); //N H W C
for(int bat=0; bat < batch_size; bat++){
Mat result(width, height, CV_32F, (void*)(output.data()+ bat*height*width*3));
cv::cvtColor(result, result, cv::COLOR_RGB2BGR);
result = result * 255.0;
result.convertTo(result, CV_8U);
cv::imwrite(file_name, result);
}