-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImage.cpp
51 lines (43 loc) · 1.22 KB
/
Image.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//
// Created by henry on 18-2-1.
//
#include "Image.h"
using namespace cv;
Image::Image() {
image_ = nullptr;
grad_ = nullptr;
plane_ = nullptr;
cost_ = nullptr;
}
Image::~Image() {
delete[] image_;
image_ = nullptr;
delete[] grad_;
grad_ = nullptr;
delete[] plane_;
plane_ = nullptr;
delete[] cost_;
cost_ = nullptr;
delete[] normal_;
normal_ = nullptr;
}
void Image::load(std::string image_path) {
cv::Mat image_mat = imread(image_path);
rows_ = image_mat.rows;
cols_ = image_mat.cols;
image_ = new uint8_t[rows_ * cols_ * 3];
grad_ = new short[rows_ * cols_ * 3];
plane_ = new float[rows_ * cols_ * 3];
cost_ = new float[rows_ * cols_];
normal_ = new float[rows_ * cols_ * 3];
memcpy(image_, image_mat.data, rows_ * cols_ * 3 * sizeof(uint8_t));
memset(grad_, 0, rows_ * cols_ * 3 * sizeof(short));
for (int i = 0; i < rows_ - 1; ++i) {
for (int j = 0; j < cols_ - 1; ++j) {
for (int k = 0; k < 3; ++k) {
int center_loc = (i * cols_ + j) * 3 + k;
grad_[center_loc] = image_[center_loc + 3 * cols_] + image_[center_loc + 3] - (image_[center_loc] << 1);
}
}
}
}