videoSource.Capture()'s cudaImage to numpy

Hi, I’m trying to make use of the videoSource component available at the dev branch of jetson-utils, but I can’t find a way to convert its result (cudaImage) to a numpy array … I’m able to inspect this cudaImage properties (width, height, channels, ptr, format, mapped) and it appears to be a valid frame and everything, but apparently I can’t feed it to cudaToNumpy() because its not mapped (it says mapped=false) … while other examples I’ve checked are able to convert cudaImages to numpy successfully. The only difference that I found is that the cudaImages that were converted succesfully have the mapped flag in true (as they were created for example via cudaAllocMapped.

Is there a way to turn an unmapped cudaImage to a mapped one so that I can then convert it to numpy? Would that be the way to go?

Here’s an example:

>>> cudaImage_mapped = jetson.utils.cudaAllocMapped(width=1280, height=960, format='rgb32f')
>>> str(cudaImage_mapped)
'<cudaImage object>\n   -- ptr:      0x101370000\n   -- size:     14745600\n   -- width:    1280\n   -- height:   960\n   -- channels: 3\n   -- format:   rgb32f\n   -- mapped:   true\n   -- freeOnDelete: true\n'
>>> numpy_mapped = jetson.utils.cudaToNumpy(cudaImage_mapped)
>>> cudaImage_not_mapped = vs.Capture() # vs is a jetson.utils.videoSource instance
>>> str(cudaImage_not_mapped)
'<cudaImage object>\n   -- ptr:      0xf00db0000\n   -- size:     3686400\n   -- width:    1280\n   -- height:   960\n   -- channels: 3\n   -- format:   rgb8\n   -- mapped:   false\n   -- freeOnDelete: false\n'
>>> numpy_not_mapped = jetson.utils.cudaToNumpy(cudaImage_not_mapped)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
Exception: jetson.utils -- cudaToNumpy() needs to use CUDA mapped memory as input (allocate with mapped=1)

Thank you.
Regards.

Hi,


Suppose you can get a mapped memory if the configure is well set.
Would you mind to check it further.

Thanks.

Hmm, what URI are you creating your videoSource with? I think by default I create them all to use mapped memory…so curious why it is not already mapped.

Hi, it’s an rtsp source. The videoSource was created like this:

>>> vs = jetson.utils.videoSource('rtsp://user:pass@192.168.0.20:554', sys.argv)

The whole snippet would be:

>>> cudaImage_mapped = jetson.utils.cudaAllocMapped(width=1280, height=960, format='rgb32f')
>>> str(cudaImage_mapped)
'<cudaImage object>\n   -- ptr:      0x101370000\n   -- size:     14745600\n   -- width:    1280\n   -- height:   960\n   -- channels: 3\n   -- format:   rgb32f\n   -- mapped:   true\n   -- freeOnDelete: true\n'
>>> numpy_mapped = jetson.utils.cudaToNumpy(cudaImage_mapped)

>>> vs = jetson.utils.videoSource('rtsp://user:pass@192.168.0.20:554', sys.argv)
>>> vs.Open()
>>> cudaImage_not_mapped = vs.Capture() # vs is a jetson.utils.videoSource instance
>>> str(cudaImage_not_mapped)
'<cudaImage object>\n   -- ptr:      0xf00db0000\n   -- size:     3686400\n   -- width:    1280\n   -- height:   960\n   -- channels: 3\n   -- format:   rgb8\n   -- mapped:   false\n   -- freeOnDelete: false\n'
>>> numpy_not_mapped = jetson.utils.cudaToNumpy(cudaImage_not_mapped)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
Exception: jetson.utils -- cudaToNumpy() needs to use CUDA mapped memory as input (allocate with mapped=1)

OK gotcha, yep it was a bug - thanks for letting me know. I just fixed it in the dev branch - if you run this and pull the latest, it should work now:

$ cd jetson-inference
$ git pull origin dev
$ cd build
$ cmake ../
$ make
$ sudo make install

Great news! it works now, thank you!
Best regards.