Hi,
How can I implement the following preprocessing to run the end-to-end C/C++ pipeline?
I've already implemented the build_gst function of the custom decoder with C++.
def override_preprocess(self, img: PIL.Image.Image | np.ndarray) -> torch.Tensor:
#trasformazione immagine
img = np.array(img)
if img.ndim == 2:
img = cv2.cvtColor(img, cv2.COLOR_GRAY2RGB)
else:
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img = np.float32(img/255.)
#Stima rumore
sigma_est = estimate_sigma(img, channel_axis=-1, average_sigmas=True)
sigma_est = np.sqrt(sigma_est)
sigma_est = min(sigma_est, 0.08)
img = cv2.resize(img, (640,480), interpolation=cv2.INTER_LINEAR)
img_tensor = torch.from_numpy(np.ascontiguousarray(img)).permute(2, 0, 1).float()
noise_tensor = torch.full_like(img_tensor[:1, :, :], fill_value=sigma_est, dtype=torch.float32)
final_tensor = torch.cat([img_tensor, noise_tensor], dim=0).to(torch.float32)
return final_tensor

