我已经编写了一个用于稠密采样特征点的CUDA函数,但是我遇到了错误。我的CUDA代码如下所示。我正在使用CUDA 7.5工具包。
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/imgproc/imgproc.hpp"
#include <opencv2/gpu/gpu.hpp>
#include <opencv2/opencv.hpp>
using namespace cv::gpu;
using namespace cv;
using namespace std;
__global__ void densefun(std::vector<int>* d_counters,std::vector<Point2f>* d_points,int d_x_max,int d_y_max,int width, int min_distance)
{
int i = blockDim.x * blockIdx.x + threadIdx.x;
Point2f point = (*d_points)[i];
int x = cvFloor(point.x);
int y = cvFloor(point.y);
//if(x >= d_x_max || y >= d_y_max)
//continue;
x /= min_distance;
y /= min_distance;
(*d_counters)[y*width+x]++;
}
void dense(std::vector<int>& counters,std::vector<Point2f>& points,int x_max,int y_max,int width)
{
std::vector<int>* d_counters;
std::vector<Point2f>* d_points;
int min_distance=5;
cudaMalloc(&d_counters,counters.size());
cudaMalloc(&d_points,points.size());
cudaMemcpy(d_points, &points, points.size(), cudaMemcpyHostToDevice);
densefun<<<1,points.size()>>>(d_counters,d_points,x_max,y_max,width,min_distance);
cudaMemcpy(&counters, d_counters, counters.size(), cudaMemcpyDeviceToHost);
cudaFree(d_counters);
cudaFree(d_points);
}
输出:
/home/supriya/Desktop/5Dec/CalculateFV_merged_gpu_old/build/denseCuda.cu(28): error: 在 global 函数("densefun") 中调用一个 host 函数("cv::Point_ ::Point_") 是不允许的
/home/supriya/Desktop/5Dec/CalculateFV_merged_gpu_old/build/denseCuda.cu(28): error: 在 global 函数("densefun") 中调用一个 host 函数("std::vector , std::allocator > > ::operator []") 是不允许的
/home/supriya/Desktop/5Dec/CalculateFV_merged_gpu_old/build/denseCuda.cu(29) (col. 7): error: 在 global 函数("densefun") 中调用一个 host 函数("cvFloor") 是不允许的
/home/supriya/Desktop/5Dec/CalculateFV_merged_gpu_old/build/denseCuda.cu(30) (col. 7): error: 在 global 函数("densefun") 中调用一个 host 函数("cvFloor") 是不允许的
/home/supriya/Desktop/5Dec/CalculateFV_merged_gpu_old/build/denseCuda.cu(35): error: 在 global 函数("densefun") 中调用一个 host 函数("std::vector > ::operator []") 是不允许的
在 "/tmp/tmpxft_00000c85_00000000-7_denseCuda.cpp1.ii" 的编译中检测到 5 个错误。 CMake 错误,位于 testVideo_generated_denseCuda.cu.o.cmake:260 (message): 生成文件时出错
/home/supriya/Desktop/5Dec/CalculateFV_merged_gpu_old/build/CMakeFiles/testVideo.dir//./testVideo_generated_denseCuda.cu.oCMakeFiles/testVideo.dir/build.make:392: recipe for target 'CMakeFiles/testVideo.dir/./testVideo_generated_denseCuda.cu.o' failed make[2]: * [CMakeFiles/testVideo.dir/./testVideo_generated_denseCuda.cu.o] Error 1 CMakeFiles/Makefile2:130: recipe for target 'CMakeFiles/testVideo.dir/all' failed make[1]: * [CMakeFiles/testVideo.dir/all] Error 2 Makefile:76: recipe for target 'all' failed make: *** [all] Error 2