Commit 4b85c849 authored by ozantonkal's avatar ozantonkal

fix rgb and bgr incompatibility

parent 1bfd7ad1
...@@ -116,7 +116,7 @@ cv::viz::CloudWidget::CloudWidget(InputArray _cloud, InputArray _colors) ...@@ -116,7 +116,7 @@ cv::viz::CloudWidget::CloudWidget(InputArray _cloud, InputArray _colors)
// Filter colors // Filter colors
Vec3b* colors_data = new Vec3b[nr_points]; Vec3b* colors_data = new Vec3b[nr_points];
NanFilter::copy(colors, colors_data, cloud); NanFilter::copyColor(colors, colors_data, cloud);
vtkSmartPointer<vtkUnsignedCharArray> scalars = vtkSmartPointer<vtkUnsignedCharArray>::New (); vtkSmartPointer<vtkUnsignedCharArray> scalars = vtkSmartPointer<vtkUnsignedCharArray>::New ();
scalars->SetNumberOfComponents (3); scalars->SetNumberOfComponents (3);
...@@ -384,7 +384,7 @@ cv::viz::MeshWidget::MeshWidget(const Mesh3d &mesh) ...@@ -384,7 +384,7 @@ cv::viz::MeshWidget::MeshWidget(const Mesh3d &mesh)
{ {
Vec3b * colors_data = 0; Vec3b * colors_data = 0;
colors_data = new Vec3b[nr_points]; colors_data = new Vec3b[nr_points];
NanFilter::copy(mesh.colors, colors_data, mesh.cloud); NanFilter::copyColor(mesh.colors, colors_data, mesh.cloud);
scalars = vtkSmartPointer<vtkUnsignedCharArray>::New (); scalars = vtkSmartPointer<vtkUnsignedCharArray>::New ();
scalars->SetNumberOfComponents (3); scalars->SetNumberOfComponents (3);
......
...@@ -111,7 +111,7 @@ struct cv::viz::Mesh3d::loadMeshImpl ...@@ -111,7 +111,7 @@ struct cv::viz::Mesh3d::loadMeshImpl
Vec3b point_color; Vec3b point_color;
poly_colors->GetTupleValue (i, point_color.val); poly_colors->GetTupleValue (i, point_color.val);
//RGB or BGR? should we swap channels???? std::swap(point_color[0], point_color[2]); // RGB -> BGR
mesh_colors[i] = point_color; mesh_colors[i] = point_color;
} }
} }
......
...@@ -847,7 +847,7 @@ bool cv::viz::Viz3d::VizImpl::addModelFromPLYFile (const std::string &filename, ...@@ -847,7 +847,7 @@ bool cv::viz::Viz3d::VizImpl::addModelFromPLYFile (const std::string &filename,
return (true); return (true);
} }
bool cv::viz::Viz3d::VizImpl::addPolylineFromPolygonMesh (const Mesh3d& mesh, const std::string &id) bool cv::viz::Viz3d::VizImpl::addPolylineFromPolygonMesh (const Mesh3d& /*mesh*/, const std::string &/*id*/)
{ {
// CV_Assert(mesh.cloud.rows == 1 && mesh.cloud.type() == CV_32FC3); // CV_Assert(mesh.cloud.rows == 1 && mesh.cloud.type() == CV_32FC3);
// //
...@@ -1017,7 +1017,7 @@ void cv::viz::Viz3d::VizImpl::setWindowName (const std::string &name) ...@@ -1017,7 +1017,7 @@ void cv::viz::Viz3d::VizImpl::setWindowName (const std::string &name)
void cv::viz::Viz3d::VizImpl::setWindowPosition (int x, int y) { window_->SetPosition (x, y); } void cv::viz::Viz3d::VizImpl::setWindowPosition (int x, int y) { window_->SetPosition (x, y); }
void cv::viz::Viz3d::VizImpl::setWindowSize (int xw, int yw) { window_->SetSize (xw, yw); } void cv::viz::Viz3d::VizImpl::setWindowSize (int xw, int yw) { window_->SetSize (xw, yw); }
bool cv::viz::Viz3d::VizImpl::addPolygonMesh (const Mesh3d& mesh, const Mat& mask, const std::string &id) bool cv::viz::Viz3d::VizImpl::addPolygonMesh (const Mesh3d& /*mesh*/, const Mat& /*mask*/, const std::string &/*id*/)
{ {
// CV_Assert(mesh.cloud.type() == CV_32FC3 && mesh.cloud.rows == 1 && !mesh.polygons.empty ()); // CV_Assert(mesh.cloud.type() == CV_32FC3 && mesh.cloud.rows == 1 && !mesh.polygons.empty ());
// CV_Assert(mesh.colors.empty() || (!mesh.colors.empty() && mesh.colors.size() == mesh.cloud.size() && mesh.colors.type() == CV_8UC3)); // CV_Assert(mesh.colors.empty() || (!mesh.colors.empty() && mesh.colors.size() == mesh.cloud.size() && mesh.colors.type() == CV_8UC3));
...@@ -1205,7 +1205,7 @@ return true; ...@@ -1205,7 +1205,7 @@ return true;
} }
bool cv::viz::Viz3d::VizImpl::updatePolygonMesh (const Mesh3d& mesh, const cv::Mat& mask, const std::string &id) bool cv::viz::Viz3d::VizImpl::updatePolygonMesh (const Mesh3d& /*mesh*/, const cv::Mat& /*mask*/, const std::string &/*id*/)
{ {
// CV_Assert(mesh.cloud.type() == CV_32FC3 && mesh.cloud.rows == 1 && !mesh.polygons.empty ()); // CV_Assert(mesh.cloud.type() == CV_32FC3 && mesh.cloud.rows == 1 && !mesh.polygons.empty ());
// CV_Assert(mesh.colors.empty() || (!mesh.colors.empty() && mesh.colors.size() == mesh.cloud.size() && mesh.colors.type() == CV_8UC3)); // CV_Assert(mesh.colors.empty() || (!mesh.colors.empty() && mesh.colors.size() == mesh.cloud.size() && mesh.colors.type() == CV_8UC3));
......
...@@ -327,6 +327,31 @@ namespace cv ...@@ -327,6 +327,31 @@ namespace cv
} }
return output; return output;
} }
static _Out* copyColor(const Mat& source, _Out* output, const Mat& nan_mask)
{
CV_Assert(DataDepth<_Tp>::value == source.depth() && source.size() == nan_mask.size());
CV_Assert(nan_mask.channels() == 3 || nan_mask.channels() == 4);
CV_DbgAssert(DataDepth<_Msk>::value == nan_mask.depth());
int s_chs = source.channels();
int m_chs = nan_mask.channels();
for(int y = 0; y < source.rows; ++y)
{
const _Tp* srow = source.ptr<_Tp>(y);
const _Msk* mrow = nan_mask.ptr<_Msk>(y);
for(int x = 0; x < source.cols; ++x, srow += s_chs, mrow += m_chs)
if (!isNan(mrow[0]) && !isNan(mrow[1]) && !isNan(mrow[2]))
{
*output = _Out(srow);
std::swap((*output)[0], (*output)[2]); // BGR -> RGB
++output;
}
}
return output;
}
}; };
template<typename _Tp> template<typename _Tp>
...@@ -339,6 +364,17 @@ namespace cv ...@@ -339,6 +364,17 @@ namespace cv
return table[nan_mask.depth() - 5](source, output, nan_mask); return table[nan_mask.depth() - 5](source, output, nan_mask);
} }
template<typename _Tp>
static inline Vec<_Tp, 3>* copyColor(const Mat& source, Vec<_Tp, 3>* output, const Mat& nan_mask)
{
CV_Assert(nan_mask.depth() == CV_32F || nan_mask.depth() == CV_64F);
typedef Vec<_Tp, 3>* (*copy_func)(const Mat&, Vec<_Tp, 3>*, const Mat&);
const static copy_func table[2] = { &NanFilter::Impl<_Tp, float>::copyColor, &NanFilter::Impl<_Tp, double>::copyColor };
return table[nan_mask.depth() - 5](source, output, nan_mask);
}
}; };
struct ApplyAffine struct ApplyAffine
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment