Saving image to a file using NvJPEGEncoder

Hello,

I am trying to save the I420 data stored in a program buffer using MMAPI NvJPEGEncoder.

I follow the example in ~/tegra_multimedi_api/samples/05_jpeg_encode.

I wrote a class to be used with my detectnet and I want to save the cropped images based on the detections.

The problem with saving using this code is very much like the one described in https://devtalk.nvidia.com/default/topic/1028968/jetson-tx2/how-to-save-image-to-file-/post/5235026/#5235026

BUT, only when I try to save the cropped image (I see some green images or some images with information from some previous frame, it is random), i.e., the cropInfo in line 47 has values obtained from detections. If I try to save the entire frame, then it works perfectly!

What could be going wrong when I set cropRect to some non zero values?

Can anybody help?

EDIT: Removed the class as the link in #2 does have the exact same issue and a generic sample code.

Please refer to
[url]does the jpegEncoder not clear the buffer? - Jetson TX2 - NVIDIA Developer Forums

Thanks, DaneLLL! This resolved my issue.

I have a few questions and suggestions that might help all of us here.

  1. If the crop width and height are required to have even values, why not mention it in the docs? Even when I run the 05_jpeg_encode sample from MMAPI with odd values, I get the invalid output. It will be really helpful.
  2. What is the reason for having crop width and height to be even? Is it the underlying compression that requires it or the way MMAPI handles different buffers or something else?
  3. This is purely a suggestion as co-incidentally, I did stumble upon the post by the same user (linked in #1) who had made another post (which has the solution, linked in #2 above). However, as my search had a keyword nvjpegencoder, the second post wouldn't appear. Maybe you guys can improve the forums by generating automatic tags that would help further narrowing down to search for issues within a specific channel. I am sure you already have a good amount of data from this forums and definitely all the resources. :)

Thanks!

Hi bhargavK,

We will check and evaluate, but I think it is pretty common to try even value in SW programming. Most HW engine is with limitation of data alignment.

One day you would see AI do this and never get a comment from a real person like me.

I am looking forward to the day when no one asked such questions and everything was powered by AI… :)

But honestly, it feels good to thank a person like you who helps us all the time! I still don’t thank Alexa.

Thanks a lot, I will remember the following advice!