Can send more than two kinds of images

This commit is contained in:
Xisco Bosch 2017-05-08 16:11:52 +02:00
parent bdfbf53670
commit 28c1fed3b6
4 changed files with 29 additions and 19 deletions

View File

@ -29,7 +29,9 @@ namespace carla {
enum ImageType {
IMAGE,
SCENE_FINAL,
DEPTH,
SEMANTIC_SEG,
};
struct Image {

View File

@ -199,26 +199,17 @@ namespace server {
static bool getPNGImages(const std::vector<Image> &images, Reward &rwd) {
std::string image_data;
std::string sceneFinal_data;
std::string depth_data;
std::string semanticSeg_data;
std::string image_size_data;
std::string sceneFinal_size_data;
std::string depth_size_data;
std::string semanticSeg_size_data;
for (const Image &img : images){
img_encode compressedImage;
/*
{
using namespace std;
clock_t begin = clock();
if (!GetImage(img, compressedImage)) {
std::cerr << "Error while encoding image" << std::endl;
return false;
}
clock_t end = clock();
double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
cout << "Time to encode the image: " << elapsed_secs << " sec" << endl;
}*/
if (!GetImage(img, compressedImage)) {
std::cerr << "Error while encoding image" << std::endl;
@ -226,14 +217,26 @@ static bool getPNGImages(const std::vector<Image> &images, Reward &rwd) {
}
switch (img.type){
case IMAGE:
for (unsigned long int i = 0; i < compressedImage.size; ++i) image_data += compressedImage.buffer[i];
image_size_data += GetBytes(compressedImage.size);
break;
case SCENE_FINAL:
for (unsigned long int i = 0; i < compressedImage.size; ++i) sceneFinal_data += compressedImage.buffer[i];
sceneFinal_size_data += GetBytes(compressedImage.size);
break;
case DEPTH:
for (unsigned long int i = 0; i < compressedImage.size; ++i) depth_data += compressedImage.buffer[i];
depth_size_data += GetBytes(compressedImage.size);
break;
case SEMANTIC_SEG:
for (unsigned long int i = 0; i < compressedImage.size; ++i) semanticSeg_data += compressedImage.buffer[i];
semanticSeg_size_data += GetBytes(compressedImage.size);
break;
}
free(compressedImage.buffer);
@ -241,9 +244,13 @@ static bool getPNGImages(const std::vector<Image> &images, Reward &rwd) {
}
rwd.set_depth_sizes(depth_size_data);
rwd.set_finalimage_sizes(sceneFinal_size_data);
rwd.set_image_sizes(image_size_data);
rwd.set_semanticseg_sizes(semanticSeg_size_data);
rwd.set_images(image_data);
rwd.set_finalimages(sceneFinal_data);
rwd.set_depths(depth_data);
rwd.set_semanticsegs(semanticSeg_data);
return true;
}

View File

@ -82,8 +82,12 @@ message Reward {
optional float ori_y = 15;
optional float ori_z = 16;
optional bytes image_sizes = 17;
optional bytes depth_sizes = 18;
optional bytes images = 19;
optional bytes depths = 20;
optional bytes finalImage_sizes = 18;
optional bytes depth_sizes = 19;
optional bytes semanticSeg_sizes = 20;
optional bytes images = 21;
optional bytes finalImages = 22;
optional bytes depths = 23;
optional bytes semanticSegs = 24;
}

View File

@ -206,6 +206,3 @@ int main(int argc, char *argv[]) {
}
}
//TODO:
//pmatrix float 16
//start_index size_t