简体   繁体   中英

How to capture a raw image (.png) using a nvargus camera in gstreamer

I am trying to capture a raw 4k image for my AI application using a 4k camera shown here . I want to capture a frame every 5 seconds and store it as a.png file which I will later run through my neural network for detection. I know the ommand to record a 4k video in raw format (.mkv). However I am not able to capture a single image (frame) in 3840x2160 resolution.

There is a sample command which is

gst-launch-1.0 nvarguscamerasrc sensor-id=0 num-buffers=1 ! "video/x-raw(memory:NVMM),format=(string)NV12, width=(int)3840, height=(int)2160" ! nvjpegenc ! filesink location=test.jpg 

The above command works but it only stores in jpg which is around 1mb insize. This is not very clear and I want a png format which is more detailed. I tried changing the extension in the filename but it is not working. I am using a jetson xavier nx.

EDIT I have tried to change the encoding by using the following command

gst-launch-1.0 nvarguscamerasrc sensor-id=0 num-buffers=1 ! "video/x-raw(memory:NVMM), format=(string)NV12, width=(int)3840, height=(int)2160" ! pngenc ! filesink location=test1.png

However I am getting the following error

WARNING: erroneous pipeline: could not link nvarguscamerasrc0 to pngenc0, pngenc0 can't handle caps video/x-raw(memory:NVMM), format=(string)NV12, width=(int)3840, height=(int)2160

You would just need to copy the image from Argus in NVMM memory into system memory. nvvidconv plugin may be used for that:

gst-launch-1.0 nvarguscamerasrc sensor-id=0 num-buffers=1 ! "video/x-raw(memory:NVMM), format=(string)NV12, width=(int)3840, height=(int)2160" ! nvvidconv ! pngenc ! filesink location=test1.png

However, argus will auto tune many parameters unless otherwise specified, so the first frame may be dark depending on your scene. In such case, you may capture 21 images and use multifilesink so that you'll just keep the 21st image after 1s and then convert it to png:

gst-launch-1.0 nvarguscamerasrc sensor-id=0 num-buffers=21 ! 'video/x-raw(memory:NVMM), format=NV12, width=3840, height=2160, framerate=21/1' ! nvvidconv ! video/x-raw,format=RGBA ! multifilesink location=test1.rgba max-files=1

gst-launch-1.0 filesrc location=test1.rgba ! videoparse format=rgba width=3840 height=2160 framerate=0/1 ! pngenc ! filesink location=test1.png

Note that pngenc is not very fast with Jetson.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM