Raw-image-format (additional bytes?) of aravis-viewer

Hi there,

I have a Teledyne Dalsa Genie Nano (C4030) and with aravis/aravis-viewer-0.8, streaming works very well.

I did not find a way to display the raw images I stored with the repective button in aravis-viewer, so I wrote a very simple python-script to display the raw image stored from aravis-viewer. I cannot upload a file, pls. find the code in the footer of this message.

There was a bit of trial and error with my code, because always, the file-size of the raw image is 256 byte larger than the bytes of the cam’s payload. In my code, I decided to cut the last 256 bytes and everything works very well. The cut bytes seem to be all 0.

Could someone please explain to me the format of the raw files written from aravis-viewer? What are the trailing bytes? I had a quite long look into the project’s git, but I am still left with many questionmarks.

Thank you a lot!
Benjamin

#!/usr/bin/python3

import numpy as np
import cv2
from matplotlib import pyplot as plt

# Teledyne Dalsa Genie Nano with Sony IMX,
# values as reported from the cam’s features.
SENSOR_WIDTH = 4112
SENSOR_HEIGHT = 2176
N_PAYLOAD_BYTES = SENSOR_WIDTH * SENSOR_HEIGHT

# Desired output dimensions
SCALE = 1/5
target_dim = (int(SENSOR_WIDTH * SCALE), int(SENSOR_HEIGHT * SCALE))

# FQFN to a raw file stored before.
IMG_PATH = "/home/user/bla.raw"

# Open the files in binary mode, no
# interpretation.
fd = open(IMG_PATH,‘rb’)
raw_bytes_buffered = fd.read()
fd.close()

# Interpret all bytes as uint8 and put them into
# a 1D numpy array.
raw_bytes_as_int_array = np.frombuffer(raw_bytes_buffered, np.uint8)


# There are some additional (leading?) bytes. Why?(???)
payload_bytes = raw_bytes_as_int_array[:n_payload_bytes]

# Reshape the 1D array to a @d array with the dimensions of the sensor (cf. payload bytes).
img_bytes = payload_bytes.reshape(sensor_height, sensor_width)

# Demosaicing, resizing, rotating. It is very
# important to demosaic first, since we rely
# on the arrangement of the Bayer filter.
img_bytes = cv2.cvtColor(img_bytes, cv2.COLOR_BayerRG2RGB)
img_bytes = cv2.resize(img_bytes, target_dim)
img_bytes = cv2.rotate(img_bytes, cv2.ROTATE_180)

# Finally, display the image!
cv2.imshow(“Raw image’s contents!”, img_bytes)
cv2.waitKey()

Hi,

The data in the raw files are what is in the payload sent by the camera, without any processing. This is what is returned by arv_buffer_get_image_data().

Trailing bytes depends on the camera you are using. Maybe it is explained in the device documentation.

Emmanuel.

Hi,

thank you a lot!

Benjamin

Just a follow-up on this. As you, Emmmanuel, pointed out, the additional bytes are not something aravis-related, but stem from the camera. To be more precise: The payload-data is padded (“When it is not required to use a smaller packet for the last payload packet, the last payload packet might transport padding. In this case, the additional padding is not part of the PayloadSize and the receiver must take care not to copy any data outside of the defined PayloadSize to the destination buffer.”). Information on this can be found in the GigE Vision Standard (V2.2, that’s the one I found), the quotation is from section 24.3.2. Now I need to map that to my cam. However, thank you again!