您好,登錄后才能下訂單哦!
如何進行OpenCV imread 圖片讀取,相信很多沒有經驗的人對此束手無策,為此本文總結了問題出現的原因和解決方法,通過這篇文章希望你能解決這個問題。
函數原型
CV_EXPORTS_W Mat imread( const String& filename, int flags = IMREAD_COLOR );
參數說明
第一個參數是圖片路徑名稱,強烈建議使用/作為目錄的分割符號,例如
第二參數具有如下的值,說明了讀取過程中是否需要進行像素的操作,例如取值0,表示讀取過程中將像素轉換為灰度值,默認參數是1, 表示不改變原圖像的像素
enum ImreadModes {
IMREAD_UNCHANGED = -1, //!< If set, return the loaded p_w_picpath as is (with alpha channel, otherwise it gets cropped).
IMREAD_GRAYSCALE = 0, //!< If set, always convert p_w_picpath to the single channel grayscale p_w_picpath.
IMREAD_COLOR = 1, //!< If set, always convert p_w_picpath to the 3 channel BGR color p_w_picpath.
IMREAD_ANYDEPTH = 2, //!< If set, return 16-bit/32-bit p_w_picpath when the input has the corresponding depth, otherwise convert it to 8-bit.
IMREAD_ANYCOLOR = 4, //!< If set, the p_w_picpath is read in any possible color format.
IMREAD_LOAD_GDAL = 8, //!< If set, use the gdal driver for loading the p_w_picpath.
IMREAD_REDUCED_GRAYSCALE_2 = 16, //!< If set, always convert p_w_picpath to the single channel grayscale p_w_picpath and the p_w_picpath size reduced 1/2.
IMREAD_REDUCED_COLOR_2 = 17, //!< If set, always convert p_w_picpath to the 3 channel BGR color p_w_picpath and the p_w_picpath size reduced 1/2.
IMREAD_REDUCED_GRAYSCALE_4 = 32, //!< If set, always convert p_w_picpath to the single channel grayscale p_w_picpath and the p_w_picpath size reduced 1/4.
IMREAD_REDUCED_COLOR_4 = 33, //!< If set, always convert p_w_picpath to the 3 channel BGR color p_w_picpath and the p_w_picpath size reduced 1/4.
IMREAD_REDUCED_GRAYSCALE_8 = 64, //!< If set, always convert p_w_picpath to the single channel grayscale p_w_picpath and the p_w_picpath size reduced 1/8.
IMREAD_REDUCED_COLOR_8 = 65, //!< If set, always convert p_w_picpath to the 3 channel BGR color p_w_picpath and the p_w_picpath size reduced 1/8.
IMREAD_IGNORE_ORIENTATION = 128 //!< If set, do not rotate the p_w_picpath according to EXIF's orientation flag.
};
例子
#include "opencv2/opencv.hpp"
int main(int argc, char *argv[])
{
cv::Mat srcImg = cv::imread("F:/test2.png", 1);
return 0;
}
注意:
在進行圖像的灰度值處理之后,默認情況下, 不會進行圖像的直方圖進行圖像的增強,否則會出現運行異常
代碼
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
using namespace cv;
int main(int argc, char *argv[])
{
Mat p_w_picpath = imread("D:/20170601092226.png", 0);
if (p_w_picpath.empty())
{
std::cout << "打開圖片失敗,請檢查" << std::endl;
return -1;
}
imshow("原圖像", p_w_picpath);
waitKey();
return 0;
Mat p_w_picpathRGB[3];
split(p_w_picpath, p_w_picpathRGB);
for (int i = 0; i < 3; i++)
{
equalizeHist(p_w_picpathRGB[i], p_w_picpathRGB[i]);
}
merge(p_w_picpathRGB, 3, p_w_picpath);
imshow("直方圖均衡化圖像增強效果", p_w_picpath);
waitKey();
return 0;
}
看完上述內容,你們掌握如何進行OpenCV imread 圖片讀取的方法了嗎?如果還想學到更多技能或想了解更多相關內容,歡迎關注億速云行業資訊頻道,感謝各位的閱讀!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。