dusty-nv / jetson-utils

C++/CUDA/Python multimedia utilities for NVIDIA Jetson
MIT License
737 stars 289 forks source link

Question about failing to save an image (Normal situation) #178

Open lasiyan opened 1 year ago

lasiyan commented 1 year ago

[Environment]

[Question]

The simple code below should work fine when running in debugging mode using gdb.

But strangely, when I run it directly from the terminal (e.g. ./myAPP), I get failed on saveImage.

Have you experienced similar symptoms?

I suspected a synchronization problem and added cudaDeviceSynchronize right after loadImage and saveImage, but it doesn't improve.

void run()
{
  Log::SetLevel(Log::Level::DEBUG);

  uchar3* img;
  int w, h;
  if (!loadImage("test.jpg", &img, &w, &h)) {
    printf("loadImage fail\n");
  }
  CUDA(cudaDeviceSynchronize());

  printf("%02X %02X %02X\n", img->x, img->y, img->z);

  if (!saveImage("res_org.jpg", img, w, h)) {
    printf("saveImage fail\n");
  }
  CUDA(cudaDeviceSynchronize());
  CUDA(cudaFreeHost(img));
}

Below are the results of the run. Is there a way to view the verbose log instead of SetLevel?

[image]  loaded 'test.jpg'  (1920x1080, 3 channels)
[cuda]   cudaAllocMapped 6220800 bytes, CPU 0x203d8e000 GPU 0x203d8e000
24 26 21
[image]  failed to save 1920x1080 image to 'res_org.jpg'
saveImage fail

I referenced this article. I'm new to CUDA, so please bear with me.

dusty-nv commented 1 year ago

Hi @lasiyan, here is the code to saveImage()

https://github.com/dusty-nv/jetson-utils/blob/f0bff5c502f9ac6b10aa2912f1324797df94bc2d/image/imageIO.cpp#L250

in this case, it checks the result from stbi_write_jpg() 3rd-party library function, and I'm not sure why that would work ok normally but fail under GDB