`#define MAX_WIDTH 3840
#define MAX_HEIGHT 2160
cv::Point2f findCorrespondingFisheyePoint(int Xe, int Ye, int We, int He, float FOV)
{
cv::Point2f fisheyePoint;
float theta, phi, r;
cv::Point3f sphericalPoint;
theta = CV_PI * (Xe / ((float)We) - 0.5);
phi = CV_PI * (Ye / ((float)He) - 0.5);
sphericalPoint.x = cos(phi) * sin(theta);
sphericalPoint.y = cos(phi) * cos(theta);
sphericalPoint.z = sin(phi);
theta = atan2(sphericalPoint.z, sphericalPoint.x);
phi = atan2(sqrt(pow(sphericalPoint.x, 2) + pow(sphericalPoint.z, 2)), sphericalPoint.y);
r = ((float)We) * phi / FOV;
fisheyePoint.x = (int)(0.5 * ((float)We) + r * cos(theta));
fisheyePoint.y = (int)(0.5 * ((float)He) + r * sin(theta));
return fisheyePoint;
}
dim3 blocks(MAXj, 1);
dim3 grids(MAXi, 1);
__global__ void kernel()
{
int i = blockIdx.x;
int j = threadIdx.x;
cv::Point2f inPLeft = findCorrespondingFisheyePoint(i, j, MAX_WIDTH, MAX_HEIGHT, FOV);
}`
I got a distorted flat image using a dslr camera body and a fisheye lens, and found the source code to perform equirectangular work to express it in 3d space at the site below.
Convert a fisheye image to an equirectangular image with opencv4
There were no problems with the correction work. But the speed is too slow.
Based on the CPU-based processing, the time of about 300~400ns per pixel was measured. However, when equirectangular work with 4K resolution (3840*2160) is performed, 8 million operations are required and it takes over 5 seconds in total.
I want to apply cuda, but it seems that the opencv library cannot be applied to the device code area.
