-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathimage.cpp
More file actions
32 lines (25 loc) · 979 Bytes
/
Copy pathimage.cpp
File metadata and controls
32 lines (25 loc) · 979 Bytes
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
#include "image.h"
#include "utils.h"
Image::Image(const std::wstring& imagePath) {
mat = cv::imread(wideStringToUtf8(imagePath), cv::IMREAD_COLOR);
if (mat.empty()) {
throw std::runtime_error("Error: Could not open or find the image!");
}
width = mat.cols;
height = mat.rows;
nPixels = static_cast<size_t>(width) * height;
size = nPixels * 3;
}
void Image::save(const std::wstring& savePath) {
if (cv::imwrite(wideStringToUtf8(savePath), mat)) {
std::wcout << L"Image saved successfully as \"" << savePath << L'"' << std::endl;
}
else {
std::cerr << "Error: Could not save the image!" << std::endl;
}
}
size_t Image::getSize() const noexcept { return size; }
size_t Image::getNumPixels() const noexcept { return nPixels; }
int Image::getWidth() const noexcept { return width; }
int Image::getHeight() const noexcept { return height; }
unsigned char* Image::getData() const noexcept { return mat.data; }