imreadで画像をロード
#geshi(c++){{ using namespace cv; Mat input; input = imread("./test.bmp", IMREAD_UNCHANGED ); }}
#geshi(c++){{ using namespace cv; Mat input; input = imread("./test.bmp", IMREAD_GRAYSCALE ); }}
#geshi(c++){{ using namespace cv; Mat input; input = imread("./test.bmp", IMREAD_COLOR ); }}
#geshi(c++){{ cv::imread("./test.bmp", IMREAD_COLOR+IMREAD_ANYDEPTH ); }}
#geshi(c++){{
#include <opencv2/imgcodecs.hpp>
#include <opencv2/core.hpp>
#include <iostream> const char filename_lena[] = "file/path/to/color/image"; // 512x512 px 3 channels const char filename_gray[] = "file/path/to/gray/image"; // 512x512 px 1 channel const char optionNameDefault[] = "default "; const int options[] = {
cv::IMREAD_UNCHANGED, cv::IMREAD_GRAYSCALE, cv::IMREAD_COLOR, cv::IMREAD_ANYDEPTH, cv::IMREAD_ANYCOLOR,
}; const char *optionNames[] = {
"IMREAD_UNCHANGED", "IMREAD_GRAYSCALE", "IMREAD_COLOR ", "IMREAD_ANYDEPTH ", "IMREAD_ANYCOLOR ", '\0',
}; const char *typeNames[] = {
"CV_8U ", "CV_8S ", "CV_16U", "CV_16S", "CV_32S", "CV_32F", "CV_64F",
};
void dumpImageFormatInformation(cv::Mat& image, const char* option) {
std::cout << "== option " << option << " == "; std::cout << "width:" << image.cols << ' '; std::cout << "height:" << image.rows << ' '; std::cout << "steps:" << image.step << '\t'; std::cout << "channel:" << CV_MAT_CN(image.flags) << ' '; std::cout << "type:" << typeNames[CV_MAT_DEPTH(image.flags)] << '(' << CV_MAT_DEPTH(image.flags) << ')' << std::endl;
}
int main() {
using namespace cv; std::cout << "== Color image ==" << std::endl;
Mat inputLena; inputLena = imread(filename_lena); dumpImageFormatInformation(inputLena, optionNameDefault);
int index = 0; while(optionNames[index] != '\0') { inputLena = imread(filename_lena, options[index]); dumpImageFormatInformation(inputLena, optionNames[index]); index++; }
std::cout << std::endl; std::cout << "== Gray image ==" << std::endl; Mat inputGray; inputGray = imread(filename_gray); dumpImageFormatInformation(inputGray, optionNameDefault);
index = 0; while(optionNames[index] != '\0') { inputGray = imread(filename_gray, options[index]); dumpImageFormatInformation(inputGray, optionNames[index]); index++; }
} }}
== Color image == == option default == width:512 height:512 steps:1536 channel:3 type:CV_8U (0) == option IMREAD_UNCHANGED == width:512 height:512 steps:1536 channel:3 type:CV_8U (0) == option IMREAD_GRAYSCALE == width:512 height:512 steps:512 channel:1 type:CV_8U (0) == option IMREAD_COLOR == width:512 height:512 steps:1536 channel:3 type:CV_8U (0) == option IMREAD_ANYDEPTH == width:512 height:512 steps:512 channel:1 type:CV_8U (0) == option IMREAD_ANYCOLOR == width:512 height:512 steps:1536 channel:3 type:CV_8U (0) == Gray image == == option default == width:512 height:512 steps:1536 channel:3 type:CV_8U (0) == option IMREAD_UNCHANGED == width:512 height:512 steps:512 channel:1 type:CV_8U (0) == option IMREAD_GRAYSCALE == width:512 height:512 steps:512 channel:1 type:CV_8U (0) == option IMREAD_COLOR == width:512 height:512 steps:1536 channel:3 type:CV_8U (0) == option IMREAD_ANYDEPTH == width:512 height:512 steps:512 channel:1 type:CV_8U (0) == option IMREAD_ANYCOLOR == width:512 height:512 steps:512 channel:1 type:CV_8U (0)