Skip to content

Commit f9b5752

Browse files
committed
Merge pull request #999 from Sahloul:features/python_wrapper/rgbd
2 parents 31fd7e1 + 62f5e86 commit f9b5752

File tree

2 files changed

+35
-34
lines changed

2 files changed

+35
-34
lines changed

modules/rgbd/include/opencv2/rgbd.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ namespace rgbd
334334
* depth of `K` if `depth` is of depth CV_U
335335
* @param mask the mask of the points to consider (can be empty)
336336
*/
337-
CV_EXPORTS
337+
CV_EXPORTS_W
338338
void
339339
depthTo3d(InputArray depth, InputArray K, OutputArray points3d, InputArray mask = noArray());
340340

@@ -1026,10 +1026,10 @@ namespace rgbd
10261026
* @param warpedDepth The warped depth.
10271027
* @param warpedMask The warped mask.
10281028
*/
1029-
CV_EXPORTS
1029+
CV_EXPORTS_W
10301030
void
10311031
warpFrame(const Mat& image, const Mat& depth, const Mat& mask, const Mat& Rt, const Mat& cameraMatrix,
1032-
const Mat& distCoeff, Mat& warpedImage, Mat* warpedDepth = 0, Mat* warpedMask = 0);
1032+
const Mat& distCoeff, OutputArray warpedImage, OutputArray warpedDepth = noArray(), OutputArray warpedMask = noArray());
10331033

10341034
// TODO Depth interpolation
10351035
// Curvature

modules/rgbd/src/odometry.cpp

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ namespace rgbd
4949

5050
enum
5151
{
52-
RGBD_ODOMETRY = 1,
53-
ICP_ODOMETRY = 2,
52+
RGBD_ODOMETRY = 1,
53+
ICP_ODOMETRY = 2,
5454
MERGED_ODOMETRY = RGBD_ODOMETRY + ICP_ODOMETRY
5555
};
5656

@@ -436,7 +436,7 @@ void computeProjectiveMatrix(const Mat& ksi, Mat& Rt)
436436

437437
eigen2cv(g, Rt);
438438
#else
439-
// TODO: check computeProjectiveMatrix when there is not eigen library,
439+
// TODO: check computeProjectiveMatrix when there is not eigen library,
440440
// because it gives less accurate pose of the camera
441441
Rt = Mat::eye(4, 4, CV_64FC1);
442442

@@ -462,7 +462,7 @@ void computeCorresps(const Mat& K, const Mat& K_inv, const Mat& Rt,
462462
CV_Assert(Rt.type() == CV_64FC1);
463463

464464
Mat corresps(depth1.size(), CV_16SC2, Scalar::all(-1));
465-
465+
466466
Rect r(0, 0, depth1.cols, depth1.rows);
467467
Mat Kt = Rt(Rect(3,0,1,3)).clone();
468468
Kt = K * Kt;
@@ -486,7 +486,7 @@ void computeCorresps(const Mat& K, const Mat& K_inv, const Mat& Rt,
486486
KRK_inv3_u1[u1] = (float)(KRK_inv_ptr[3] * u1);
487487
KRK_inv6_u1[u1] = (float)(KRK_inv_ptr[6] * u1);
488488
}
489-
489+
490490
for(int v1 = 0; v1 < depth1.rows; v1++)
491491
{
492492
KRK_inv1_v1_plus_KRK_inv2[v1] = (float)(KRK_inv_ptr[1] * v1 + KRK_inv_ptr[2]);
@@ -506,16 +506,16 @@ void computeCorresps(const Mat& K, const Mat& K_inv, const Mat& Rt,
506506
if(mask1_row[u1])
507507
{
508508
CV_DbgAssert(!cvIsNaN(d1));
509-
float transformed_d1 = static_cast<float>(d1 * (KRK_inv6_u1[u1] + KRK_inv7_v1_plus_KRK_inv8[v1]) +
509+
float transformed_d1 = static_cast<float>(d1 * (KRK_inv6_u1[u1] + KRK_inv7_v1_plus_KRK_inv8[v1]) +
510510
Kt_ptr[2]);
511511
if(transformed_d1 > 0)
512512
{
513513
float transformed_d1_inv = 1.f / transformed_d1;
514-
int u0 = cvRound(transformed_d1_inv * (d1 * (KRK_inv0_u1[u1] + KRK_inv1_v1_plus_KRK_inv2[v1]) +
514+
int u0 = cvRound(transformed_d1_inv * (d1 * (KRK_inv0_u1[u1] + KRK_inv1_v1_plus_KRK_inv2[v1]) +
515515
Kt_ptr[0]));
516-
int v0 = cvRound(transformed_d1_inv * (d1 * (KRK_inv3_u1[u1] + KRK_inv4_v1_plus_KRK_inv5[v1]) +
516+
int v0 = cvRound(transformed_d1_inv * (d1 * (KRK_inv3_u1[u1] + KRK_inv4_v1_plus_KRK_inv5[v1]) +
517517
Kt_ptr[1]));
518-
518+
519519
if(r.contains(Point(u0,v0)))
520520
{
521521
float d0 = depth0.at<float>(v0,u0);
@@ -527,7 +527,7 @@ void computeCorresps(const Mat& K, const Mat& K_inv, const Mat& Rt,
527527
{
528528
int exist_u1 = c[0], exist_v1 = c[1];
529529

530-
float exist_d1 = (float)(depth1.at<float>(exist_v1,exist_u1) *
530+
float exist_d1 = (float)(depth1.at<float>(exist_v1,exist_u1) *
531531
(KRK_inv6_u1[exist_u1] + KRK_inv7_v1_plus_KRK_inv8[exist_v1]) + Kt_ptr[2]);
532532

533533
if(transformed_d1 > exist_d1)
@@ -631,7 +631,7 @@ void calcICPEquationCoeffsTranslation(double* C, const Point3f& /*p0*/, const Ve
631631
typedef
632632
void (*CalcICPEquationCoeffsPtr)(double*, const Point3f&, const Vec3f&);
633633

634-
static
634+
static
635635
void calcRgbdLsmMatrices(const Mat& image0, const Mat& cloud0, const Mat& Rt,
636636
const Mat& image1, const Mat& dI_dx1, const Mat& dI_dy1,
637637
const Mat& corresps, double fx, double fy, double sobelScaleIn,
@@ -657,8 +657,8 @@ void calcRgbdLsmMatrices(const Mat& image0, const Mat& cloud0, const Mat& Rt,
657657
const Vec4i& c = corresps_ptr[correspIndex];
658658
int u0 = c[0], v0 = c[1];
659659
int u1 = c[2], v1 = c[3];
660-
661-
diffs_ptr[correspIndex] = static_cast<float>(static_cast<int>(image0.at<uchar>(v0,u0)) -
660+
661+
diffs_ptr[correspIndex] = static_cast<float>(static_cast<int>(image0.at<uchar>(v0,u0)) -
662662
static_cast<int>(image1.at<uchar>(v1,u1)));
663663
sigma += diffs_ptr[correspIndex] * diffs_ptr[correspIndex];
664664
}
@@ -697,8 +697,8 @@ void calcRgbdLsmMatrices(const Mat& image0, const Mat& cloud0, const Mat& Rt,
697697

698698
AtB_ptr[y] += A_ptr[y] * w * diffs_ptr[correspIndex];
699699
}
700-
}
701-
700+
}
701+
702702
for(int y = 0; y < transformDim; y++)
703703
for(int x = y+1; x < transformDim; x++)
704704
AtA.at<double>(x,y) = AtA.at<double>(y,x);
@@ -790,16 +790,16 @@ bool solveSystem(const Mat& AtA, const Mat& AtB, double detThreshold, Mat& x)
790790
return true;
791791
}
792792

793-
static
793+
static
794794
bool testDeltaTransformation(const Mat& deltaRt, double maxTranslation, double maxRotation)
795795
{
796796
double translation = norm(deltaRt(Rect(3, 0, 1, 3)));
797-
797+
798798
Mat rvec;
799799
Rodrigues(deltaRt(Rect(0,0,3,3)), rvec);
800-
800+
801801
double rotation = norm(rvec) * 180. / CV_PI;
802-
802+
803803
return translation <= maxTranslation && rotation <= maxRotation;
804804
}
805805

@@ -920,9 +920,9 @@ bool RGBDICPOdometryImpl(Mat& Rt, const Mat& initRt,
920920
isOk = true;
921921
}
922922
}
923-
923+
924924
Rt = resultRt;
925-
925+
926926
if(isOk)
927927
{
928928
Mat deltaRt;
@@ -941,24 +941,25 @@ template<class ImageElemType>
941941
static void
942942
warpFrameImpl(const Mat& image, const Mat& depth, const Mat& mask,
943943
const Mat& Rt, const Mat& cameraMatrix, const Mat& distCoeff,
944-
Mat& warpedImage, Mat* warpedDepth, Mat* warpedMask)
944+
OutputArray _warpedImage, OutputArray warpedDepth, OutputArray warpedMask)
945945
{
946946
CV_Assert(image.size() == depth.size());
947-
947+
948948
Mat cloud;
949949
depthTo3d(depth, cameraMatrix, cloud);
950-
950+
951951
std::vector<Point2f> points2d;
952952
Mat transformedCloud;
953953
perspectiveTransform(cloud, transformedCloud, Rt);
954954
projectPoints(transformedCloud.reshape(3, 1), Mat::eye(3, 3, CV_64FC1), Mat::zeros(3, 1, CV_64FC1), cameraMatrix,
955955
distCoeff, points2d);
956956

957-
warpedImage = Mat(image.size(), image.type(), Scalar::all(0));
957+
_warpedImage.create(image.size(), image.type());
958+
Mat warpedImage = _warpedImage.getMat();
958959

959960
Mat zBuffer(image.size(), CV_32FC1, std::numeric_limits<float>::max());
960961
const Rect rect = Rect(0, 0, image.cols, image.rows);
961-
962+
962963
for (int y = 0; y < image.rows; y++)
963964
{
964965
//const Point3f* cloud_row = cloud.ptr<Point3f>(y);
@@ -978,13 +979,13 @@ warpFrameImpl(const Mat& image, const Mat& depth, const Mat& mask,
978979
}
979980
}
980981

981-
if(warpedMask)
982-
*warpedMask = zBuffer != std::numeric_limits<float>::max();
982+
if(warpedMask.needed())
983+
Mat(zBuffer != std::numeric_limits<float>::max()).copyTo(warpedMask);
983984

984-
if(warpedDepth)
985+
if(warpedDepth.needed())
985986
{
986987
zBuffer.setTo(std::numeric_limits<float>::quiet_NaN(), zBuffer == std::numeric_limits<float>::max());
987-
*warpedDepth = zBuffer;
988+
zBuffer.copyTo(warpedDepth);
988989
}
989990
}
990991

@@ -1406,7 +1407,7 @@ bool RgbdICPOdometry::computeImpl(const Ptr<OdometryFrame>& srcFrame, const Ptr<
14061407
void
14071408
warpFrame(const Mat& image, const Mat& depth, const Mat& mask,
14081409
const Mat& Rt, const Mat& cameraMatrix, const Mat& distCoeff,
1409-
Mat& warpedImage, Mat* warpedDepth, Mat* warpedMask)
1410+
OutputArray warpedImage, OutputArray warpedDepth, OutputArray warpedMask)
14101411
{
14111412
if(image.type() == CV_8UC1)
14121413
warpFrameImpl<uchar>(image, depth, mask, Rt, cameraMatrix, distCoeff, warpedImage, warpedDepth, warpedMask);

0 commit comments

Comments
 (0)