send bitmap
This commit is contained in:
parent
397a07d0b7
commit
0f57074569
|
@ -31,7 +31,7 @@ static bool RayTrace(
|
|||
TArray <FHitResult> OutHits;
|
||||
static FName TraceTag = FName(TEXT("VehicleTrace"));
|
||||
|
||||
//World->DebugDrawTraceTag = TraceTag;
|
||||
World->DebugDrawTraceTag = TraceTag;
|
||||
|
||||
const bool Success = World->LineTraceMultiByObjectType(
|
||||
OutHits,
|
||||
|
@ -56,7 +56,8 @@ static bool RayTrace(
|
|||
|
||||
AAICarlaVehicleController::AAICarlaVehicleController() :
|
||||
Super(),
|
||||
MovementComponent(nullptr)
|
||||
MovementComponent(nullptr),
|
||||
TrafficLightStop(false)
|
||||
{
|
||||
bAutoManageActiveCameraTarget = false;
|
||||
//MAX_SPEED = ((rand() * 10) - 5) + MAX_SPEED;
|
||||
|
@ -203,8 +204,8 @@ void AAICarlaVehicleController::Tick(float DeltaTime){
|
|||
steering = CalcStreeringValue();
|
||||
}
|
||||
|
||||
const FVector Start = GetPawn()->GetActorLocation() + (GetPawn()->GetActorForwardVector().GetSafeNormal() * 250.0) + FVector(0.0, 0.0, 50.0);
|
||||
const FVector End = Start + GetPawn()->GetActorForwardVector().GetSafeNormal() * 400.0;
|
||||
const FVector Start = GetPawn()->GetActorLocation() + (GetPawn()->GetActorForwardVector().GetSafeNormal() * (200.0f + VehicleBounds->GetScaledBoxExtent().X/2.0f)) + FVector(0.0f, 0.0f, 50.0f);
|
||||
const FVector End = Start + GetPawn()->GetActorForwardVector().GetSafeNormal() * (300.0f + VehicleBounds->GetScaledBoxExtent().X/2.0f);
|
||||
|
||||
|
||||
auto speed = MovementComponent->GetForwardSpeed() * 0.036f;
|
||||
|
|
|
@ -131,7 +131,7 @@ private:
|
|||
UPROPERTY(EditAnywhere)
|
||||
float MAX_SPEED = 30.0f;
|
||||
|
||||
bool TrafficLightStop = false;
|
||||
bool TrafficLightStop;
|
||||
|
||||
int route_it = 0;
|
||||
TArray<FVector> route;
|
||||
|
|
|
@ -23,12 +23,29 @@ namespace server {
|
|||
const std::unique_ptr<Protocol> &proto,
|
||||
const Reward_Values &rwd
|
||||
) {
|
||||
if (!thr.getRestart()) {
|
||||
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
if (!thr.getRestart()) {
|
||||
std::string message;
|
||||
|
||||
|
||||
clock_t start = clock();
|
||||
|
||||
Reward reward;
|
||||
proto->LoadReward(reward, rwd);
|
||||
|
||||
|
||||
clock_t end = clock();
|
||||
|
||||
double elapsed_secs = double(end- start) / CLOCKS_PER_SEC;
|
||||
|
||||
|
||||
cout << "Send time: " << elapsed_secs << " (s)" << endl;
|
||||
|
||||
bool correctSerialize = reward.SerializeToString(&message);
|
||||
|
||||
TCPServer::error_code error;
|
||||
|
@ -47,6 +64,9 @@ namespace server {
|
|||
logTCPError("Falied to serialize", error);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// This is the thread that listens for string over the TCP socket.
|
||||
|
|
|
@ -10,6 +10,9 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
#include <ctime>
|
||||
|
||||
#ifdef CARLA_WITH_PNG_COMPRESSION
|
||||
#include CARLA_LIBPNG_INCLUDE
|
||||
static_assert(
|
||||
|
@ -67,12 +70,12 @@ namespace server {
|
|||
TPngDestructor(png_struct *p) : p(p) {}
|
||||
~TPngDestructor() { if (p) { png_destroy_write_struct(&p, NULL); } }
|
||||
};
|
||||
|
||||
/*
|
||||
static pixel_t * pixel_at (bitmap_t * bitmap, int x, int y)
|
||||
{
|
||||
return bitmap->pixels + bitmap->width * y + x;
|
||||
}
|
||||
|
||||
*/
|
||||
void loadPNGData(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
{
|
||||
/* with libpng15 next line causes pointer deference error; use libpng12 */
|
||||
|
@ -93,7 +96,7 @@ namespace server {
|
|||
memcpy(p->buffer + p->size, data, length);
|
||||
p->size += length;
|
||||
}
|
||||
|
||||
/*
|
||||
bool LoadBitmap (bitmap_t &bitmap, const Image &image_info){
|
||||
|
||||
bitmap.width = image_info.width;
|
||||
|
@ -120,9 +123,33 @@ namespace server {
|
|||
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
static bool GetImage(const Image &image_info, img_encode &compressedImage){
|
||||
static bool LoadBitmap (char* image, const Image &image_info){
|
||||
|
||||
size_t x = 0, y = 0;
|
||||
int it = 0;
|
||||
for (const Color &color : image_info.image) {
|
||||
|
||||
if (x >= image_info.width) {
|
||||
x = 0;
|
||||
++y;
|
||||
}
|
||||
|
||||
image[it] = color.R;
|
||||
image[++it] = color.G;
|
||||
image[++it] = color.B;
|
||||
++x;
|
||||
//pixel->alpha = color.A;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
static bool GetPNGImage(const Image &image_info, img_encode &compressedImage){
|
||||
if (image_info.image.empty())
|
||||
return false;
|
||||
if (image_info.image.size() != image_info.width * image_info.height) {
|
||||
|
@ -131,8 +158,9 @@ namespace server {
|
|||
}
|
||||
|
||||
bitmap_t bitmap;
|
||||
if (!LoadBitmap(bitmap, image_info)) return false;
|
||||
|
||||
if (!LoadBitmap(bitmap, image_info)) return false;
|
||||
|
||||
int depth = 8;
|
||||
int pixel_size = 3;
|
||||
png_structp png = NULL;
|
||||
|
@ -167,7 +195,7 @@ namespace server {
|
|||
PNG_FILTER_TYPE_DEFAULT);
|
||||
|
||||
|
||||
/* Initialize rows of PNG. */
|
||||
// Initialize rows of PNG.
|
||||
row_pointers = (png_byte **) png_malloc (png, bitmap.height * sizeof (png_byte *));
|
||||
for (y = 0; y < bitmap.height; ++y) {
|
||||
png_byte *row = (png_byte *) png_malloc (png, sizeof (uint8_t) * bitmap.width * pixel_size);
|
||||
|
@ -183,9 +211,9 @@ namespace server {
|
|||
compressedImage.buffer = NULL;
|
||||
compressedImage.size = 0;
|
||||
|
||||
|
||||
png_set_write_fn(png, &compressedImage, loadPNGData, NULL);
|
||||
|
||||
|
||||
png_set_rows (png, info, row_pointers);
|
||||
png_write_png(png, info, PNG_TRANSFORM_IDENTITY, NULL);
|
||||
|
||||
|
@ -198,6 +226,26 @@ namespace server {
|
|||
free(bitmap.pixels);
|
||||
free(info);
|
||||
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
static bool GetBitMapImage(const Image &image_info, char* image){
|
||||
if (image_info.image.empty()){
|
||||
std::cerr << "Error: Empty image" << std::endl;
|
||||
return false;
|
||||
}
|
||||
if (image_info.image.size() != image_info.width * image_info.height) {
|
||||
std::cerr << "Invalid image size" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!LoadBitmap(image, image_info)) {
|
||||
std::cerr << "Error loaging the bitmap" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -213,39 +261,57 @@ static bool getPNGImages(const std::vector<Image> &images, Reward &rwd) {
|
|||
std::string semanticSeg_size_data;
|
||||
|
||||
for (const Image &img : images){
|
||||
img_encode compressedImage;
|
||||
|
||||
// img_encode compressedImage;
|
||||
size_t image_size = img.width * img.height * 3;
|
||||
char image[image_size] ;
|
||||
|
||||
|
||||
if (!GetImage(img, compressedImage)) {
|
||||
/*
|
||||
if (!GetImage(img, compressedImage)) {
|
||||
std::cerr << "Error while encoding image" << std::endl;
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
|
||||
if (!GetBitMapImage(img, image)){
|
||||
std::cerr << "Error while encoding image" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
//for (unsigned long int i = 0; i < compressedImage.size; ++i) image_data += compressedImage.buffer[i];
|
||||
//image_size_data += GetBytes(compressedImage.size);
|
||||
for (unsigned long int i = 0; i < image_size; ++i) image_data += image[i];
|
||||
image_size_data += GetBytes(image_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);
|
||||
//for (unsigned long int i = 0; i < compressedImage.size; ++i) sceneFinal_data += compressedImage.buffer[i];
|
||||
//sceneFinal_size_data += GetBytes(compressedImage.size);
|
||||
for (unsigned long int i = 0; i < image_size; ++i) sceneFinal_data += image[i];
|
||||
sceneFinal_size_data += GetBytes(image_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);
|
||||
//for (unsigned long int i = 0; i < compressedImage.size; ++i) depth_data += compressedImage.buffer[i];
|
||||
//depth_size_data += GetBytes(compressedImage.size);
|
||||
for (unsigned long int i = 0; i < image_size; ++i) sceneFinal_data += image[i];
|
||||
sceneFinal_size_data += GetBytes(image_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);
|
||||
//for (unsigned long int i = 0; i < compressedImage.size; ++i) semanticSeg_data += compressedImage.buffer[i];
|
||||
//semanticSeg_size_data += GetBytes(compressedImage.size);
|
||||
for (unsigned long int i = 0; i < image_size; ++i) sceneFinal_data += image[i];
|
||||
sceneFinal_size_data += GetBytes(image_size);
|
||||
break;
|
||||
}
|
||||
|
||||
free(compressedImage.buffer);
|
||||
|
||||
//free(compressedImage.buffer);
|
||||
}
|
||||
|
||||
rwd.set_depth_sizes(depth_size_data);
|
||||
|
@ -273,6 +339,7 @@ static bool getPNGImages(const std::vector<Image> &images, Reward &rwd) {
|
|||
Protocol::~Protocol() {}
|
||||
|
||||
void Protocol::LoadReward(Reward &reward, const Reward_Values &values) {
|
||||
|
||||
reward.set_collision_car(values.collision_car);
|
||||
reward.set_collision_gen(values.collision_general);
|
||||
reward.set_collision_ped(values.collision_pedestrian);
|
||||
|
@ -294,7 +361,10 @@ static bool getPNGImages(const std::vector<Image> &images, Reward &rwd) {
|
|||
if (!getPNGImages(values.images, reward)) {
|
||||
std::cerr << "Error compressing image to PNG" << std::endl;
|
||||
}
|
||||
|
||||
#endif // CARLA_WITH_PNG_COMPRESSION
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Protocol::LoadScene(Scene &scene, const Scene_Values &values) {
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
#include <atomic>
|
||||
#include <functional>
|
||||
|
||||
#include <ctime>
|
||||
|
||||
namespace carla {
|
||||
namespace thread {
|
||||
|
||||
|
@ -68,9 +70,20 @@ namespace thread {
|
|||
_restart = false;
|
||||
_queue.canWait(true);
|
||||
while (!_restart && !done) {
|
||||
auto value = _queue.wait_and_pop();
|
||||
if (value != nullptr) {
|
||||
_job(*value);
|
||||
{
|
||||
using namespace std;
|
||||
clock_t start = clock();
|
||||
|
||||
auto value = _queue.wait_and_pop();
|
||||
if (value != nullptr) {
|
||||
_job(*value);
|
||||
|
||||
clock_t end = clock();
|
||||
double elapsed_secs = double(end- start) / CLOCKS_PER_SEC;
|
||||
cout<< "Send Thread: " << elapsed_secs << endl;
|
||||
|
||||
}
|
||||
|
||||
}//Sleep(10);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,9 +25,9 @@ static std::vector<carla::Color> makeImage(uint32_t width, uint32_t height) {
|
|||
std::vector<unsigned char> img(width * height * 4);
|
||||
for (uint32_t i = 0; i < height; ++i) {
|
||||
for (uint32_t e = 0; e < width; ++e) {
|
||||
img[4 * width * i + 4 * e + 0] = 255 * !(e & i);
|
||||
img[4 * width * i + 4 * e + 1] = e ^ i;
|
||||
img[4 * width * i + 4 * e + 2] = e | i;
|
||||
img[4 * width * i + 4 * e + 0] = rand() % 256;//255 * !(e & i);
|
||||
img[4 * width * i + 4 * e + 1] = rand() % 256;//e ^ i;
|
||||
img[4 * width * i + 4 * e + 2] = rand() % 256;//e | i;
|
||||
img[4 * width * i + 4 * e + 3] = 255;
|
||||
}
|
||||
}
|
||||
|
@ -46,8 +46,8 @@ static std::vector<carla::Color> makeImage(uint32_t width, uint32_t height) {
|
|||
std::unique_ptr<carla::Reward_Values> makeReward() {
|
||||
auto reward = std::make_unique<carla::Reward_Values>();
|
||||
|
||||
const uint32_t imageWidth = 512u;
|
||||
const uint32_t imageHeight = 512u;
|
||||
const uint32_t imageWidth = 800u;
|
||||
const uint32_t imageHeight = 600u;
|
||||
|
||||
reward->player_location = {1.0f, 1.0f};
|
||||
reward->player_orientation = {1.0f, 0.0f, 0.0f};
|
||||
|
@ -60,7 +60,7 @@ std::unique_ptr<carla::Reward_Values> makeReward() {
|
|||
reward->intersect_offroad = 0.5f;
|
||||
reward->game_timestamp = 0u;
|
||||
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
for (int i = 0; i < 1; ++i) {
|
||||
carla::Image img;
|
||||
img.image = makeImage(imageWidth, imageHeight);
|
||||
img.width = imageWidth;
|
||||
|
@ -104,20 +104,6 @@ int main(int argc, char *argv[]) {
|
|||
for (;;) {
|
||||
if (server.newEpisodeRequested(file, read) && read) {
|
||||
|
||||
/*
|
||||
{
|
||||
uint32_t scene;
|
||||
bool error = false, readed = false;
|
||||
do {
|
||||
error = !server.tryReadSceneInit(scene, readed);
|
||||
} while (!readed && !error);
|
||||
|
||||
if (error) {
|
||||
std::cerr << "ERROR while sending SceneValues" << std::endl;
|
||||
}
|
||||
else std::cout << "Received: scene = " << scene << std::endl;
|
||||
}
|
||||
*/
|
||||
carla::Scene_Values sceneValues;
|
||||
|
||||
for (int i = 0; i < 1; ++i){
|
||||
|
|
Loading…
Reference in New Issue