Skip to content

Commit bd05d0f

Browse files
committed
Reduce Mat_ usage.
1 parent 3000519 commit bd05d0f

File tree

9 files changed

+22
-23
lines changed

9 files changed

+22
-23
lines changed

modules/face/src/facemarkLBF.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -661,11 +661,10 @@ FacemarkLBFImpl::BBox::BBox(double _x, double _y, double w, double h) {
661661

662662
// Project absolute shape to relative shape binding to this bbox
663663
Mat FacemarkLBFImpl::BBox::project(const Mat &shape) const {
664-
Mat_<double> res(shape.rows, shape.cols);
665-
const Mat_<double> &shape_ = (Mat_<double>)shape;
664+
Mat res(shape.rows, shape.cols, CV_64FC1);
666665
for (int i = 0; i < shape.rows; i++) {
667-
res(i, 0) = (shape_(i, 0) - x_center) / x_scale;
668-
res(i, 1) = (shape_(i, 1) - y_center) / y_scale;
666+
res.at<double>(i, 0) = (shape.at<double>(i, 0) - x_center) / x_scale;
667+
res.at<double>(i, 1) = (shape.at<double>(i, 1) - y_center) / y_scale;
669668
}
670669
return res;
671670
}
@@ -997,7 +996,7 @@ void FacemarkLBFImpl::RandomForest::train(std::vector<Mat> &imgs, std::vector<Ma
997996
}
998997

999998
Mat FacemarkLBFImpl::RandomForest::generateLBF(Mat &img, Mat &current_shape, BBox &bbox, Mat &mean_shape) {
1000-
Mat_<int> lbf_feat(1, landmark_n*trees_n);
999+
Mat lbf_feat(1, landmark_n*trees_n, CV_32SC1);
10011000
double scale;
10021001
Mat_<double> rotate;
10031002
calcSimilarityTransform(bbox.project(current_shape), mean_shape, scale, rotate);
@@ -1036,7 +1035,7 @@ Mat FacemarkLBFImpl::RandomForest::generateLBF(Mat &img, Mat &current_shape, BBo
10361035
idx = 2 * idx + 1;
10371036
}
10381037
}
1039-
lbf_feat(i*trees_n + j) = (i*trees_n + j)*base + code;
1038+
lbf_feat.at<int>(i*trees_n + j) = (i*trees_n + j)*base + code;
10401039
}
10411040
}
10421041
return lbf_feat;
@@ -1365,7 +1364,7 @@ Mat FacemarkLBFImpl::Regressor::supportVectorRegression(
13651364

13661365
Mat FacemarkLBFImpl::Regressor::globalRegressionPredict(const Mat &lbf, int stage) {
13671366
const Mat_<double> &weight = (Mat_<double>)gl_regression_weights[stage];
1368-
Mat_<double> delta_shape(weight.rows / 2, 2);
1367+
Mat delta_shape(weight.rows / 2, 2, CV_64FC1);
13691368
const double *w_ptr = NULL;
13701369
const int *lbf_ptr = lbf.ptr<int>(0);
13711370

@@ -1374,12 +1373,12 @@ Mat FacemarkLBFImpl::Regressor::globalRegressionPredict(const Mat &lbf, int stag
13741373
w_ptr = weight.ptr<double>(2 * i);
13751374
double y = 0;
13761375
for (int j = 0; j < lbf.cols; j++) y += w_ptr[lbf_ptr[j]];
1377-
delta_shape(i, 0) = y;
1376+
delta_shape.at<double>(i, 0) = y;
13781377

13791378
w_ptr = weight.ptr<double>(2 * i + 1);
13801379
y = 0;
13811380
for (int j = 0; j < lbf.cols; j++) y += w_ptr[lbf_ptr[j]];
1382-
delta_shape(i, 1) = y;
1381+
delta_shape.at<double>(i, 1) = y;
13831382
}
13841383
return delta_shape;
13851384
} // Regressor::globalRegressionPredict

modules/face/src/mace.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ struct MACEImpl CV_FINAL : MACE {
102102
Mat complexInput;
103103
merge(input, 2, complexInput);
104104

105-
Mat_<Vec2d> dftImg(IMGSIZE*2, IMGSIZE*2, 0.0);
105+
Mat dftImg(IMGSIZE*2, IMGSIZE*2, CV_64FC2, 0.0);
106106
complexInput.copyTo(dftImg(Rect(0,0,IMGSIZE,IMGSIZE)));
107107

108108
dft(dftImg, dftImg);

modules/rgbd/perf/perf_tsdf.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ struct SemisphereScene : Scene
133133

134134
Mat depth(Affine3f pose) override
135135
{
136-
Mat_<float> frame(frameSize);
136+
Mat frame(frameSize, CV_32FC1);
137137
Reprojector reproj(intr);
138138

139139
Range range(0, frame.rows);

modules/rgbd/test/ocl/test_tsdf.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ struct SemisphereScene : Scene
137137

138138
Mat depth(Affine3f pose) override
139139
{
140-
Mat_<float> frame(frameSize);
140+
Mat frame(frameSize, CV_32FC1);
141141
Reprojector reproj(intr);
142142

143143
Range range(0, frame.rows);

modules/rgbd/test/test_colored_kinfu.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ struct CubeSpheresScene : Scene
200200

201201
Mat depth(Affine3f pose) override
202202
{
203-
Mat_<float> frame(frameSize);
203+
Mat frame(frameSize, CV_32FC1);
204204
Reprojector reproj(intr);
205205

206206
Range range(0, frame.rows);
@@ -211,7 +211,7 @@ struct CubeSpheresScene : Scene
211211

212212
Mat rgb(Affine3f pose) override
213213
{
214-
Mat_<Vec3f> frame(frameSize);
214+
Mat frame(frameSize, CV_32FC3);
215215
Reprojector reproj(intr);
216216

217217
Range range(0, frame.rows);
@@ -307,7 +307,7 @@ struct RotatingScene : Scene
307307

308308
Mat depth(Affine3f pose) override
309309
{
310-
Mat_<float> frame(frameSize);
310+
Mat frame(frameSize, CV_32FC1);
311311
Reprojector reproj(intr);
312312

313313
Range range(0, frame.rows);
@@ -318,7 +318,7 @@ struct RotatingScene : Scene
318318

319319
Mat rgb(Affine3f pose) override
320320
{
321-
Mat_<Vec3f> frame(frameSize);
321+
Mat frame(frameSize, CV_32FC3);
322322
Reprojector reproj(intr);
323323

324324
Range range(0, frame.rows);

modules/rgbd/test/test_kinfu.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ struct CubeSpheresScene : Scene
135135

136136
Mat depth(Affine3f pose) override
137137
{
138-
Mat_<float> frame(frameSize);
138+
Mat frame(frameSize, CV_32FC1);
139139
Reprojector reproj(intr);
140140

141141
Range range(0, frame.rows);
@@ -231,7 +231,7 @@ struct RotatingScene : Scene
231231

232232
Mat depth(Affine3f pose) override
233233
{
234-
Mat_<float> frame(frameSize);
234+
Mat frame(frameSize, CV_32FC1);
235235
Reprojector reproj(intr);
236236

237237
Range range(0, frame.rows);

modules/rgbd/test/test_tsdf.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ struct SemisphereScene : Scene
134134

135135
Mat depth(Affine3f pose) override
136136
{
137-
Mat_<float> frame(frameSize);
137+
Mat frame(frameSize, CV_32FC1);
138138
Reprojector reproj(intr);
139139

140140
Range range(0, frame.rows);

modules/videostab/src/global_motion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ namespace videostab
8282
{
8383

8484
// does isotropic normalization
85-
static Mat normalizePoints(int npoints, Point2f *points)
85+
static Mat_<float> normalizePoints(int npoints, Point2f *points)
8686
{
8787
float cx = 0.f, cy = 0.f;
8888
for (int i = 0; i < npoints; ++i)

modules/ximgproc/test/test_sparse_match_interpolator.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Mat readOpticalFlow( const String& path )
1717
// CV_Assert(sizeof(float) == 4);
1818
//FIXME: ensure right sizes of int and float - here and in writeOpticalFlow()
1919

20-
Mat_<Point2f> flow;
20+
Mat flow;
2121
std::ifstream file(path.c_str(), std::ios_base::binary);
2222
if ( !file.good() )
2323
return flow; // no file - return empty matrix
@@ -32,7 +32,7 @@ Mat readOpticalFlow( const String& path )
3232
file.read((char*) &width, 4);
3333
file.read((char*) &height, 4);
3434

35-
flow.create(height, width);
35+
flow.create(height, width, CV_32FC2);
3636

3737
for ( int i = 0; i < flow.rows; ++i )
3838
{
@@ -47,7 +47,7 @@ Mat readOpticalFlow( const String& path )
4747
return flow;
4848
}
4949

50-
flow(i, j) = u;
50+
flow.at<Point2f>(i, j) = u;
5151
}
5252
}
5353
file.close();

0 commit comments

Comments
 (0)