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

Resolve an opencv encoder issue

parent dcdd9f53
No related branches found
No related tags found
1 merge request!311Resolves #296 removal of NvPipe
Pipeline #27143 failed
This commit is part of merge request !311. Comments created here will be created in the context of that merge request.
......@@ -6,7 +6,7 @@
variables:
GIT_SUBMODULE_STRATEGY: recursive
CMAKE_ARGS_WINDOWS: '-DCMAKE_GENERATOR_PLATFORM=x64 -DPORTAUDIO_DIR="D:/Build/portaudio" -DNVPIPE_DIR="D:/Build/NvPipe" -DEigen3_DIR="C:/Program Files (x86)/Eigen3/share/eigen3/cmake" -DOpenCV_DIR="D:/Build/opencv-4.1.1" -DCUDA_TOOLKIT_ROOT_DIR="C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1" -DWITH_OPENVR=TRUE -DOPENVR_DIR="D:/Build/OpenVRSDK" -DWITH_CERES=FALSE'
CMAKE_ARGS_WINDOWS: '-DCMAKE_GENERATOR_PLATFORM=x64 -DPORTAUDIO_DIR="D:/Build/portaudio" -DEigen3_DIR="C:/Program Files (x86)/Eigen3/share/eigen3/cmake" -DOpenCV_DIR="D:/Build/opencv-4.1.1" -DCUDA_TOOLKIT_ROOT_DIR="C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1" -DWITH_OPENVR=TRUE -DOPENVR_DIR="D:/Build/OpenVRSDK" -DWITH_CERES=FALSE'
stages:
- all
......
......@@ -10,7 +10,6 @@ include(GNUInstallDirs)
include(CTest)
enable_testing()
option(WITH_NVPIPE "Use NvPipe for compression if available" ON)
option(WITH_OPTFLOW "Use NVIDIA Optical Flow if available" OFF)
option(WITH_OPENVR "Build with OpenVR support" OFF)
option(WITH_OPUS "Use Opus audio compression" ON)
......
......@@ -28,10 +28,12 @@ bool OpenCVEncoder::supports(ftl::codecs::codec_t codec) {
}
bool OpenCVEncoder::encode(const cv::cuda::GpuMat &in, ftl::codecs::Packet &pkt) {
bool is_colour = !(pkt.flags & ftl::codecs::kFlagFloat);
bool is_colour = in.type() == CV_8UC4 || in.type() == CV_8UC1;
if (is_colour && in.type() != CV_8UC4 && in.type() != CV_8UC1) return false;
if (!is_colour && in.type() == CV_8UC4) {
if (pkt.codec == codec_t::Any) pkt.codec = (is_colour && in.type() != CV_8UC1) ? codec_t::JPG : codec_t::PNG;
if (!supports(pkt.codec)) return false;
if (!is_colour && pkt.codec == codec_t::JPG) {
LOG(ERROR) << "OpenCV Encoder doesn't support lossy depth";
return false;
}
......@@ -43,39 +45,23 @@ bool OpenCVEncoder::encode(const cv::cuda::GpuMat &in, ftl::codecs::Packet &pkt)
return false;
}
/*pkt.definition = (pkt.definition == definition_t::Any) ? ftl::codecs::findDefinition(in.cols, in.rows) : pkt.definition;
if (pkt.definition == definition_t::Invalid || pkt.definition == definition_t::Any) {
LOG(ERROR) << "Invalid definition";
return false;
}*/
// Ensure definition does not exceed max
current_definition_ = pkt.definition; //((int)pkt.definition < (int)max_definition) ? max_definition : pkt.definition;
in.download(tmp_);
//CHECK(cv::Size(ftl::codecs::getWidth(definition), ftl::codecs::getHeight(definition)) == in.size());
//if (!is_colour) {
//tmp_.convertTo(tmp_, CV_16U, 1000.0f);
//}
if (!is_colour) {
tmp_.convertTo(tmp_, CV_16U, 1000.0f);
}
int width = ftl::codecs::getWidth(current_definition_);
int height = ftl::codecs::getHeight(current_definition_);
// Scale down image to match requested definition...
/*if (ftl::codecs::getHeight(current_definition_) < in.rows) {
cv::resize(tmp_, tmp_, cv::Size(ftl::codecs::getWidth(current_definition_), ftl::codecs::getHeight(current_definition_)), 0, 0, (is_colour) ? 1 : cv::INTER_NEAREST);
} else {
}*/
if (tx*width != in.cols || ty*height != in.rows) {
LOG(ERROR) << "Input does not match requested definition";
return false;
}
if (pkt.codec == codec_t::Any) pkt.codec = (is_colour && in.type() != CV_8UC1) ? codec_t::JPG : codec_t::PNG;
//for (int i=0; i<chunk_count_; ++i) {
// Add chunk job to thread pool
//ftl::pool.push([this,i,cb,is_colour,bitrate](int id) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment