changed variable types in remap function in gstcameraundistort.cpp to support gpu acceleration - It still needs to be tested on the ACU!

This commit is contained in:
Erik Wienecke 2025-06-23 14:29:19 +02:00
parent 6377ebf568
commit a4e00086b3

View File

@ -81,6 +81,8 @@
#include <gst/opencv/gstopencvutils.h>
#include <opencv2/core/ocl.hpp> //added
GST_DEBUG_CATEGORY_STATIC (gst_camera_undistort_debug);
#define GST_CAT_DEFAULT gst_camera_undistort_debug
@ -324,8 +326,28 @@ camera_undistort_run (GstCameraUndistort * undist, cv::Mat img, cv::Mat outimg)
}
if (undist->showUndistorted && undist->doUndistort) {
/* activate OpenCL */
cv::ocl::setUseOpenCL(true);
cv::ocl::Context ctx = cv::ocl::Context::getDefault();
if (ctx.ndevices() > 0) {
GST_INFO_OBJECT(undist, "OpenCL available: YES");
GST_INFO_OBJECT(undist, "Using device: %s", ctx.device(0).name().c_str());
} else {
GST_INFO_OBJECT(undist, "OpenCL available: NO");
}
cv::UMat cv_input_umat, cv_output_umat;
/* convert Mat to UMat */
img.copyTo(cv_input_umat);
/* do the undistort */
cv::remap (img, outimg, undist->map1, undist->map2, cv::INTER_LINEAR);
cv::remap (cv_input_umat, cv_output_umat, undist->map1.getUMat(cv::ACCESS_READ), undist->map2.getUMat(cv::ACCESS_READ), cv::INTER_LINEAR);
/* UMat output back to Mat */
cv_output_umat.copyTo(outimg);
if (undist->crop) {
/* TODO do the cropping */