read camera parameters dynamicly
This commit is contained in:
@@ -12,6 +12,7 @@
|
|||||||
#include <exception>
|
#include <exception>
|
||||||
#include <CL/opencl.h>
|
#include <CL/opencl.h>
|
||||||
#include <opencv2/opencv.hpp>
|
#include <opencv2/opencv.hpp>
|
||||||
|
#include <vio/abstract_camera.h>
|
||||||
|
|
||||||
class kernel{
|
class kernel{
|
||||||
public:
|
public:
|
||||||
@@ -114,7 +115,7 @@ public:
|
|||||||
};
|
};
|
||||||
class opencl{
|
class opencl{
|
||||||
public:
|
public:
|
||||||
opencl();
|
opencl(vk::AbstractCamera* cam);
|
||||||
~opencl();
|
~opencl();
|
||||||
int32_t make_kernel(std::string name){_kernels.push_back(kernel(program,name));};
|
int32_t make_kernel(std::string name){_kernels.push_back(kernel(program,name));};
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@@ -195,6 +196,7 @@ private:
|
|||||||
cl::Device* device = nullptr;
|
cl::Device* device = nullptr;
|
||||||
cl::Program* program = nullptr;
|
cl::Program* program = nullptr;
|
||||||
cl::CommandQueue* queue= nullptr;
|
cl::CommandQueue* queue= nullptr;
|
||||||
|
vk::AbstractCamera* cam= nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //VIO_OPENCL_CL_CLASS_H
|
#endif //VIO_OPENCL_CL_CLASS_H
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
// Created by root on 4/27/21.
|
// Created by root on 4/27/21.
|
||||||
//
|
//
|
||||||
#include <vio/cl_class.h>
|
#include <vio/cl_class.h>
|
||||||
opencl::opencl() {
|
opencl::opencl(vk::AbstractCamera* cam):cam(cam) {
|
||||||
std::vector<cl::Platform> all_platforms;
|
std::vector<cl::Platform> all_platforms;
|
||||||
cl::Platform::get(&all_platforms);
|
cl::Platform::get(&all_platforms);
|
||||||
if (all_platforms.size() == 0){
|
if (all_platforms.size() == 0){
|
||||||
@@ -27,7 +27,6 @@ opencl::opencl() {
|
|||||||
<< "CL_DEVICE_COMPILER_AVAILABLE: " <<device->getInfo<CL_DEVICE_COMPILER_AVAILABLE>()<<'\n'
|
<< "CL_DEVICE_COMPILER_AVAILABLE: " <<device->getInfo<CL_DEVICE_COMPILER_AVAILABLE>()<<'\n'
|
||||||
<< "CL_DEVICE_LOCAL_MEM_SIZE: " <<device->getInfo<CL_DEVICE_LOCAL_MEM_SIZE>()<<'\n'
|
<< "CL_DEVICE_LOCAL_MEM_SIZE: " <<device->getInfo<CL_DEVICE_LOCAL_MEM_SIZE>()<<'\n'
|
||||||
<< "CL_DEVICE_GLOBAL_MEM_SIZE: " <<device->getInfo<CL_DEVICE_GLOBAL_MEM_SIZE>()<<'\n';
|
<< "CL_DEVICE_GLOBAL_MEM_SIZE: " <<device->getInfo<CL_DEVICE_GLOBAL_MEM_SIZE>()<<'\n';
|
||||||
|
|
||||||
context=new cl::Context({ *device });
|
context=new cl::Context({ *device });
|
||||||
cl::Program::Sources sources;
|
cl::Program::Sources sources;
|
||||||
read_cl fast(std::string(KERNEL_DIR)+"/fast-gray.cl");
|
read_cl fast(std::string(KERNEL_DIR)+"/fast-gray.cl");
|
||||||
@@ -35,7 +34,13 @@ opencl::opencl() {
|
|||||||
read_cl compute_residual(std::string(KERNEL_DIR)+"/compute-residual.cl");
|
read_cl compute_residual(std::string(KERNEL_DIR)+"/compute-residual.cl");
|
||||||
sources.push_back({ compute_residual.src_str, compute_residual.size });
|
sources.push_back({ compute_residual.src_str, compute_residual.size });
|
||||||
program=new cl::Program(*context, sources);
|
program=new cl::Program(*context, sources);
|
||||||
if(program->build({ *device },"-DFAST_THRESH=40 -DPATCH_SIZE=2 -DPATCH_HALFSIZE=1 -DF_X=296.724480 -DF_Y=395.357280 -DC_X=317.877600 -DC_Y=238.752640 -DS=1.016870") !=0)
|
double* camera=cam->params();
|
||||||
|
std::string options="-DFAST_THRESH=40 -DPATCH_SIZE=2 -DPATCH_HALFSIZE=1 -DF_X="+ std::to_string(camera[0]) +
|
||||||
|
" -DF_Y="+std::to_string(camera[1])+
|
||||||
|
" -DC_X="+std::to_string(camera[2])+
|
||||||
|
" -DC_Y="+std::to_string(camera[3])+
|
||||||
|
" -DS="+std::to_string(camera[4]);
|
||||||
|
if(program->build({ *device },options.c_str()) !=0)
|
||||||
std::cout << " Error building: " << program->getBuildInfo<CL_PROGRAM_BUILD_STATUS>(*device)<<'\n'
|
std::cout << " Error building: " << program->getBuildInfo<CL_PROGRAM_BUILD_STATUS>(*device)<<'\n'
|
||||||
<<program->getBuildInfo<CL_PROGRAM_BUILD_LOG>(*device) << '\n';
|
<<program->getBuildInfo<CL_PROGRAM_BUILD_LOG>(*device) << '\n';
|
||||||
queue=new cl::CommandQueue(*context,*device,CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE,NULL);
|
queue=new cl::CommandQueue(*context,*device,CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE,NULL);
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ FrameHandlerMono::FrameHandlerMono(vk::AbstractCamera* cam,Eigen::Matrix<double,
|
|||||||
ukfPtr_(init),
|
ukfPtr_(init),
|
||||||
time_(ros::Time::now())
|
time_(ros::Time::now())
|
||||||
{
|
{
|
||||||
gpu_fast_= new opencl();
|
gpu_fast_= new opencl(cam_);
|
||||||
gpu_fast_->make_kernel("fast_gray");
|
gpu_fast_->make_kernel("fast_gray");
|
||||||
cv::Mat img=cv::Mat(cv::Size(700, 500),CV_8UC1);
|
cv::Mat img=cv::Mat(cv::Size(700, 500),CV_8UC1);
|
||||||
gpu_fast_->write_buf(0,0,img);
|
gpu_fast_->write_buf(0,0,img);
|
||||||
|
|||||||
Reference in New Issue
Block a user