Hi @dusty_nv
Your code is working properly on my acquired image with a crop ratio of 0.5. Here is my code. Code prior to this point puts the x coordinates for cropping in left and right and y coordinates in top and bottom.
crop_roi = (left, top, right, bottom)
imgOutput = jetson.utils.cudaAllocMapped(width=right-left, height=bottom-top, format=img.format)
print (crop_roi, img.width, img.height, imgOutput.width, imgOutput.height)
jetson.utils.cudaCrop(img, imgOutput, crop_roi)
display.Render(imgOutput)
The code as written above results in the error below:
((135, 0, 945, 1920), 1080, 1920, 810, 1920)
Traceback (most recent call last):
File "my-detection.py", line 91, in <module>
jetson.utils.cudaCrop(img, imgOutput, crop_roi)
ValueError: jetson.utils -- cudaCrop() had an invalid ROI
[gstreamer] gstCamera -- stopping pipeline, transitioning to GST_STATE_NULL
You can see the crop_roi, input image dimensions, and the output image dimensions in the print output above. If I change the crop_roi in the above code as below, it works but results in the skewed image I posted earlier.
crop_roi = (left, top, right-1, bottom-1)
And the print output changes to:
((135, 0, 944, 1919, 1080, 1920, 810, 1920)
Here is how I replaced my code with yours in this section and it works properly without any complaint of invalid crop_roi.
`# determine the amount of border pixels (cropping around the center by half)`
crop_factor = 0.5
crop_border = ((1.0 - crop_factor) * 0.5 * img.width,
(1.0 - crop_factor) * 0.5 * img.height)
# compute the ROI as (left, top, right, bottom)
crop_roi = (crop_border[0], crop_border[1], img.width - crop_border[0], img.height - crop_border[1])
# allocate the output image, with the cropped size
imgOutput = jetson.utils.cudaAllocMapped(width=img.width * crop_factor,
height=img.height * crop_factor,
format=img.format)
print (crop_roi, img.width, img.height, imgOutput.width, imgOutput.height)
# crop the image to the ROI
jetson.utils.cudaCrop(img, imgOutput, crop_roi)
display.Render(imgOutput)
Here is the output of the print:
((270.0, 480.0, 810.0, 1440.0), 1080, 1920, 540, 960)
Logically, since this works, my original version should have worked as well.
Next, I am going to revert to my original code and try to force your crop_roi numbers to result from my code and see if it starts to work then.