60 lines
1.8 KiB
C++
60 lines
1.8 KiB
C++
#include "image.hpp"
|
|
|
|
Image::Image () {
|
|
|
|
}
|
|
|
|
Mat Image::getBlank () {
|
|
if (blank.empty()) {
|
|
blank = Mat::zeros(Size(width, height), CV_8UC3);
|
|
}
|
|
return blank.clone();
|
|
}
|
|
|
|
Mat Image::loadImage (string& image_path, uint64_t& x, uint64_t& y, uint64_t& w, uint64_t& h) {
|
|
string located_path = samples::findFile(image_path);
|
|
string ext = getExtLower(located_path);
|
|
//cout << "{ \"image_extension\" : \"" << ext << "\" }" << endl;
|
|
if (ext == "dpx") {
|
|
DpxReader in;
|
|
//in.open(image_path);
|
|
//DPX dpx(located_path);
|
|
//loaded = dpx.convertTo8Bit();
|
|
cout << "{ \"dpx\" : \"" << image_path << "\" }" << endl;
|
|
} else {
|
|
loaded = imread(located_path, IMREAD_COLOR);
|
|
}
|
|
image = getBlank();
|
|
|
|
if (loaded.empty()) {
|
|
cerr << "{ \"error\" : \"" << image_path << " empty\" }" << endl;
|
|
} else {
|
|
resize(loaded, resized, Size(w, h));
|
|
|
|
cout << "{ \"loaded\" : \"" << image_path << "\", ";
|
|
cout << "\"original\" : { \"w\" : " << loaded.cols << ", \"h\" : " << loaded.rows << " }, ";
|
|
cout << "\"resized\" : { \"w\" : " << resized.cols << ", \"h\" : " << resized.rows << " } }" << endl;
|
|
|
|
resized.copyTo(image(Rect(x, y, resized.cols, resized.rows)));
|
|
flip(image, image, 0);
|
|
|
|
#if (CV_VERSION_MAJOR >= 4)
|
|
cvtColor(image, image, cv::COLOR_BGR2RGB);
|
|
#else
|
|
cvtColor(image, image, CV_BGR2RGB);
|
|
#endif
|
|
loaded.release();
|
|
resized.release();
|
|
}
|
|
return image;
|
|
}
|
|
|
|
string Image::getExtLower (const string& path) {
|
|
size_t pos = path.find_last_of('.');
|
|
if (pos != string::npos) {
|
|
string ext = path.substr(pos + 1);
|
|
transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
|
|
return ext;
|
|
}
|
|
return "";
|
|
} |