-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathImage.cpp
More file actions
60 lines (47 loc) · 1.2 KB
/
Copy pathImage.cpp
File metadata and controls
60 lines (47 loc) · 1.2 KB
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
52
53
54
55
56
57
58
59
60
#define NOMINMAX
#undef min
#undef max
#include "stdafx.h"
#include "Image.h"
Image::Image() {
;
}
Image::Image(std::string dir) {
this->image_dir = dir;
this->load();
}
void Image::load() {
this->load_mat();
this->ToTensor();
}
void Image::load(std::string path) {
this->image_dir = path;
this->load();
}
std::string Image::_image_dir() {
return this->image_dir;
}
void Image::ToTensor() {
cv::Mat img = this->feature_mat.clone();
int h = img.rows;
int w = img.cols;
int channels = img.channels();
at::Tensor img_t = torch::from_blob(img.data, { 1, h, w, channels }, at::kByte);
img_t = img_t.permute({ 0, 3, 1, 2 });
img_t = img_t.toType(c10::kFloat).div(255.0);
img_t.to(c10::DeviceType::CPU);
this->feature = img_t;
}
void Image::load_mat() {
this->feature_mat = cv::imread(this->image_dir);
}
void Image::save(std::string save_dir) {
cv::imwrite(save_dir, this->feature_mat);
}
void Image::imshow(std::string window_name) {
cv::imshow(window_name, this->feature_mat);
}
void Image::resize(int h, int w) {
cv::resize(this->feature_mat, this->feature_mat, cv::Size(w, h), 0, 0, cv::INTER_AREA);
this->ToTensor();
}