Commit 6db3e956 authored by Vladislav Sovrasov's avatar Vladislav Sovrasov

reg: add support of different datatypes in Mapper::grid()

parent d879ea48
...@@ -59,28 +59,45 @@ void Mapper::gradient(const Mat& img1, const Mat& img2, Mat& Ix, Mat& Iy, Mat& I ...@@ -59,28 +59,45 @@ void Mapper::gradient(const Mat& img1, const Mat& img2, Mat& Ix, Mat& Iy, Mat& I
} }
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
void Mapper::grid(const Mat& img, Mat& grid_r, Mat& grid_c) const
template<typename _Tp>
void fillGridMatrices(const Mat img, Mat grid_r, Mat grid_c)
{ {
// Matrices with reference frame coordinates
grid_r.create(img.size(), img.type());
grid_c.create(img.size(), img.type());
if(img.channels() == 1) { if(img.channels() == 1) {
for(int r_i = 0; r_i < img.rows; ++r_i) { for(int r_i = 0; r_i < img.rows; ++r_i) {
for(int c_i = 0; c_i < img.cols; ++c_i) { for(int c_i = 0; c_i < img.cols; ++c_i) {
grid_r.at<double>(r_i, c_i) = r_i; grid_r.at<_Tp>(r_i, c_i) = r_i;
grid_c.at<double>(r_i, c_i) = c_i; grid_c.at<_Tp>(r_i, c_i) = c_i;
} }
} }
} else { } else {
Vec3d ones(1., 1., 1.); Vec<_Tp, 3> ones(1., 1., 1.);
for(int r_i = 0; r_i < img.rows; ++r_i) { for(int r_i = 0; r_i < img.rows; ++r_i) {
for(int c_i = 0; c_i < img.cols; ++c_i) { for(int c_i = 0; c_i < img.cols; ++c_i) {
grid_r.at<Vec3d>(r_i, c_i) = r_i*ones; grid_r.at< Vec<_Tp, 3> >(r_i, c_i) = r_i*ones;
grid_c.at<Vec3d>(r_i, c_i) = c_i*ones; grid_c.at< Vec<_Tp, 3> >(r_i, c_i) = c_i*ones;
} }
} }
} }
} }
void Mapper::grid(const Mat& img, Mat& grid_r, Mat& grid_c) const
{
CV_DbgAssert(img.channels() == 1 || img.channels() == 3);
// Matrices with reference frame coordinates
grid_r.create(img.size(), img.type());
grid_c.create(img.size(), img.type());
if(img.depth() == CV_8U)
fillGridMatrices<uchar>(img, grid_r, grid_c);
if(img.depth() == CV_16U)
fillGridMatrices<ushort>(img, grid_r, grid_c);
else if(img.depth() == CV_32F)
fillGridMatrices<float>(img, grid_r, grid_c);
else if(img.depth() == CV_64F)
fillGridMatrices<double>(img, grid_r, grid_c);
}
}} // namespace cv::reg }} // namespace cv::reg
...@@ -63,7 +63,7 @@ using namespace cv::reg; ...@@ -63,7 +63,7 @@ using namespace cv::reg;
class RegTest : public testing::Test class RegTest : public testing::Test
{ {
public: public:
void loadImage(); void loadImage(int dstDataType = CV_32FC3);
void testShift(); void testShift();
void testEuclidean(); void testEuclidean();
...@@ -242,14 +242,13 @@ void RegTest::testProjective() ...@@ -242,14 +242,13 @@ void RegTest::testProjective()
EXPECT_GE(projNorm, sqrt(3.) - 0.01); EXPECT_GE(projNorm, sqrt(3.) - 0.01);
} }
void RegTest::loadImage() void RegTest::loadImage(int dstDataType)
{ {
const string imageName = cvtest::TS::ptr()->get_data_path() + "reg/home.png"; const string imageName = cvtest::TS::ptr()->get_data_path() + "reg/home.png";
img1 = imread(imageName, -1); img1 = imread(imageName, -1);
ASSERT_TRUE(img1.data != 0); ASSERT_TRUE(!img1.empty());
// Convert to double, 3 channels img1.convertTo(img1, dstDataType);
img1.convertTo(img1, CV_64FC3);
} }
...@@ -282,3 +281,15 @@ TEST_F(RegTest, projective) ...@@ -282,3 +281,15 @@ TEST_F(RegTest, projective)
loadImage(); loadImage();
testProjective(); testProjective();
} }
TEST_F(RegTest, projective_dt64fc3)
{
loadImage(CV_64FC3);
testProjective();
}
TEST_F(RegTest, projective_dt64fc1)
{
loadImage(CV_64FC1);
testProjective();
}
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