免責事項:この記事はブロガーオリジナル記事ですが、許可ブロガーなく再生してはなりません。https://blog.csdn.net/withlonger/article/details/81191967
今日はOpenCVのを習い始め、単にどのような学習過程を記録します。表示画面上でOpenCVのを学ぶことが始まりました。データ構造のマットと一緒に写真を保存し、機能の関数imreadで絵をお読みください。以下に詳細に定義され、画像パスへの言及は、列挙定数の2つのパラメータは、列挙定数は13の値をとることができます。
Mat imread( const String& filename, int flags = IMREAD_COLOR );
//! Imread flags
enum ImreadModes {
IMREAD_UNCHANGED = -1, //!< If set, return the loaded image as is (with alpha channel, otherwise it gets cropped).
IMREAD_GRAYSCALE = 0, //!< If set, always convert image to the single channel grayscale image.
IMREAD_COLOR = 1, //!< If set, always convert image to the 3 channel BGR color image.
IMREAD_ANYDEPTH = 2, //!< If set, return 16-bit/32-bit image when the input has the corresponding depth, otherwise convert it to 8-bit.
IMREAD_ANYCOLOR = 4, //!< If set, the image is read in any possible color format.
IMREAD_LOAD_GDAL = 8, //!< If set, use the gdal driver for loading the image.
IMREAD_REDUCED_GRAYSCALE_2 = 16, //!< If set, always convert image to the single channel grayscale image and the image size reduced 1/2.
IMREAD_REDUCED_COLOR_2 = 17, //!< If set, always convert image to the 3 channel BGR color image and the image size reduced 1/2.
IMREAD_REDUCED_GRAYSCALE_4 = 32, //!< If set, always convert image to the single channel grayscale image and the image size reduced 1/4.
IMREAD_REDUCED_COLOR_4 = 33, //!< If set, always convert image to the 3 channel BGR color image and the image size reduced 1/4.
IMREAD_REDUCED_GRAYSCALE_8 = 64, //!< If set, always convert image to the single channel grayscale image and the image size reduced 1/8.
IMREAD_REDUCED_COLOR_8 = 65, //!< If set, always convert image to the 3 channel BGR color image and the image size reduced 1/8.
IMREAD_IGNORE_ORIENTATION = 128 //!< If set, do not rotate the image according to EXIF's orientation flag.
};
関数imshowをして、画像を表示します。次のようにソースコード文のOpenCVの関数である、InputArrayは、マットの種類を通過することができます。
void imshow(const String& winname, InputArray mat);
以下は、使用の例です。
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
void main() {
//读入一张图片,一参为图片的绝对路径,二参为枚举常量,有 IMREAD_COLOR、IMREAD_GRAYSCALE等
Mat srcImg = imread("d:/data/test.png",IMREAD_LOAD_GDAL);
imshow("源图像", srcImg);
waitKey();//暂停窗口
}