Skip to content
Snippets Groups Projects
Commit 7fc400f2 authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Add initial gpu utility code

parent 9f13e062
No related branches found
No related tags found
1 merge request!358Updates to SDK and alternative fusion
Pipeline #33900 passed
......@@ -15,9 +15,9 @@ FrameImpl::~FrameImpl()
}
std::list<voltu::ImagePtr> FrameImpl::getImageSet(voltu::Channel c)
std::vector<voltu::ImagePtr> FrameImpl::getImageSet(voltu::Channel c)
{
std::list<voltu::ImagePtr> result;
std::vector<voltu::ImagePtr> result;
ftl::codecs::Channel channel = ftl::codecs::Channel::Colour;
switch (c)
......
......@@ -16,7 +16,7 @@ public:
FrameImpl();
~FrameImpl() override;
std::list<voltu::ImagePtr> getImageSet(voltu::Channel) override;
std::vector<voltu::ImagePtr> getImageSet(voltu::Channel) override;
voltu::PointCloudPtr getPointCloud(voltu::PointCloudFormat cloudfmt, voltu::PointFormat pointfmt) override;
......
......@@ -43,6 +43,10 @@ endif()
add_library(voltu_sdk STATIC ${VOLTU_SRCS})
if (WITH_OPENCV)
target_compile_definitions(voltu_sdk PUBLIC WITH_OPENCV)
endif()
target_include_directories(voltu_sdk
PUBLIC include)
target_link_libraries(voltu_sdk ${OS_LIBS} Threads::Threads ${OPTIONAL_DEPENDENCIES} Eigen3::Eigen)
......
#pragma once
#include <voltu/types/image.hpp>
#include
#include <memory>
namespace voltu
{
/**
* @brief CUDA Processing Stream.
*
* An instance of this class is mapped to a single CUDA stream, so any of the
* available operations will occur within that stream. It is therefore
* necessary to call `waitCompletion` after all steps have been finished.
*/
class CUDAProc
{
public:
virtual bool waitCompletion(int timeout, bool except=false) = 0;
virtual void* getInternalStream() = 0;
virtual void visualiseDepthEnhancement(const voltu::ImagePtr &gt, const voltu::ImagePtr &depth_old, const voltu::ImagePtr &depth_new, const voltu::ImagePtr &colour) = 0;
};
}
......@@ -7,19 +7,29 @@
#pragma once
#include <opencv2/core/mat.hpp>
#include <opencv2/core/cuda_types.hpp>
#include <opencv2/core/cuda.hpp>
#include <voltu/types/image.hpp>
namespace voltu
{
namespace cv
namespace opencv
{
void convert(voltu::ImagePtr img, ::cv::Mat &mat);
void convert(voltu::ImagePtr img, ::cv::cuda::GpuMat &mat);
::cv::cuda::GpuMat toGpuMat(voltu::ImagePtr img);
void visualise(voltu::ImagePtr img, ::cv::Mat &mat);
}
struct GpuUtilities
{
void (*visualiseDepthEnhancement)(const voltu::ImagePtr &gt, const voltu::ImagePtr &depth_old, const voltu::ImagePtr &depth_new, const voltu::ImagePtr &colour) = nullptr;
};
extern GpuUtilities gpu;
}
\ No newline at end of file
......@@ -78,7 +78,7 @@ public:
* Identifiers (URIs), with some non-standard additions. A few examples
* are:
* * `file:///home/user/file.ftl`
* * `tcp://localhost:9001/*`
* * `tcp://localhost:9001/`
* * `ftl://my.stream.name/room1`
* * `ws://ftlab.utu.fi/lab/`
* * `./file.ftl`
......
......@@ -22,7 +22,7 @@ class Frame
public:
virtual ~Frame() = default;
PY_API PY_RV_LIFETIME_PARENT virtual std::list<voltu::ImagePtr> getImageSet(voltu::Channel channel) = 0;
PY_API PY_RV_LIFETIME_PARENT virtual std::vector<voltu::ImagePtr> getImageSet(voltu::Channel channel) = 0;
PY_API PY_RV_LIFETIME_PARENT virtual voltu::PointCloudPtr getPointCloud(voltu::PointCloudFormat cloudfmt, voltu::PointFormat pointfmt) = 0;
......
......@@ -45,7 +45,7 @@ int main(int argc, char **argv)
for (auto img : imgset)
{
cv::Mat m;
voltu::cv::visualise(img, m);
voltu::opencv::visualise(img, m);
cv::imshow(string("Image-") + img->getName(), m);
}
......
......@@ -69,7 +69,7 @@ int main(int argc, char **argv)
for (auto img : imgset)
{
cv::Mat m;
voltu::cv::convert(img, m);
voltu::opencv::convert(img, m);
cv::imshow(string("Camera-") + img->getName(), m);
}
......
......@@ -107,6 +107,10 @@ int main(int argc, char **argv)
op1->property("visibility_carving")->setBool(do_carving);
op1->property("mls_iterations")->setInt(iters);
cv::Mat old_depth;
auto oldimgset = frame->getImageSet(voltu::Channel::kDepth);
voltu::opencv::toGpuMat(oldimgset[sourceno]).download(old_depth);
pipe->submit(frame);
pipe->waitCompletion(3000, true);
......@@ -123,7 +127,8 @@ int main(int argc, char **argv)
{
if (srccount++ < sourceno) continue;
cv::Mat m;
voltu::cv::visualise(img, m);
voltu::opencv::toGpuMat(img).download(m);
voltu::opencv::visualise(img, m);
cv::imshow(string("Image-") + img->getName(), m);
break;
}
......
......@@ -8,6 +8,10 @@
#include <voltu/types/errors.hpp>
#include <voltu/voltu.hpp>
#ifdef WITH_OPENCV
#include <voltu/opencv.hpp>
#endif
#if defined(WIN32)
#include <windows.h>
#pragma comment(lib, "User32.lib")
......@@ -23,6 +27,10 @@
static bool g_init = false;
#ifdef WITH_OPENCV
voltu::GpuUtilities voltu::gpu;
#endif
typedef void* Library;
static Library loadLibrary(const char *file)
......@@ -132,6 +140,18 @@ std::shared_ptr<voltu::System> voltu::instance()
throw voltu::exceptions::RuntimeVersionMismatch();
}
#ifdef WITH_OPENCV
auto gpuinit = (voltu::GpuUtilities* (*)())getFunction(handle, "voltu_utilities_gpu");
if (gpuinit)
{
gpu = *gpuinit();
}
else
{
//throw voltu::exceptions::LibraryLoadFailed();
}
#endif
return instance;
}
else
......
......@@ -9,7 +9,7 @@
#include <opencv2/imgproc.hpp>
void voltu::cv::convert(voltu::ImagePtr img, ::cv::Mat &mat)
void voltu::opencv::convert(voltu::ImagePtr img, ::cv::Mat &mat)
{
voltu::ImageData data = img->getHost();
......@@ -31,23 +31,44 @@ void voltu::cv::convert(voltu::ImagePtr img, ::cv::Mat &mat)
}
}
void voltu::cv::convert(voltu::ImagePtr img, ::cv::cuda::GpuMat &mat)
void voltu::opencv::convert(voltu::ImagePtr img, ::cv::cuda::GpuMat &mat)
{
mat = voltu::opencv::toGpuMat(img);
}
cv::cuda::GpuMat voltu::opencv::toGpuMat(voltu::ImagePtr img)
{
voltu::ImageData data = img->getDevice();
if (data.format == voltu::ImageFormat::kBGRA8)
{
}
else if (data.format == voltu::ImageFormat::kFloat32)
{
return ::cv::cuda::GpuMat(
data.height,
data.width,
CV_32F,
data.data
);
}
throw voltu::exceptions::NotImplemented();
}
void voltu::cv::visualise(voltu::ImagePtr img, ::cv::Mat &mat)
void voltu::opencv::visualise(voltu::ImagePtr img, ::cv::Mat &mat)
{
voltu::ImageData data = img->getHost();
if (data.format == voltu::ImageFormat::kBGRA8)
{
voltu::cv::convert(img, mat);
voltu::opencv::convert(img, mat);
}
else if (data.format == voltu::ImageFormat::kFloat32)
{
::cv::Mat tmp;
voltu::cv::convert(img, tmp);
voltu::opencv::convert(img, tmp);
float maxdepth = 8.0f; // TODO: Get from intrinsics
......@@ -65,7 +86,7 @@ void voltu::cv::visualise(voltu::ImagePtr img, ::cv::Mat &mat)
else if (data.format == voltu::ImageFormat::kFloat16_4)
{
::cv::Mat tmp;
voltu::cv::convert(img, tmp);
voltu::opencv::convert(img, tmp);
tmp.convertTo(tmp, CV_32FC4);
tmp += 1.0f;
tmp *= 127.0f;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment