您好,登錄后才能下訂單哦!
如何進(jìn)行OpenCV imread 圖片讀取,相信很多沒(méi)有經(jīng)驗(yàn)的人對(duì)此束手無(wú)策,為此本文總結(jié)了問(wèn)題出現(xiàn)的原因和解決方法,通過(guò)這篇文章希望你能解決這個(gè)問(wèn)題。
函數(shù)原型
CV_EXPORTS_W Mat imread( const String& filename, int flags = IMREAD_COLOR );
參數(shù)說(shuō)明
第一個(gè)參數(shù)是圖片路徑名稱(chēng),強(qiáng)烈建議使用/作為目錄的分割符號(hào),例如
第二參數(shù)具有如下的值,說(shuō)明了讀取過(guò)程中是否需要進(jìn)行像素的操作,例如取值0,表示讀取過(guò)程中將像素轉(zhuǎn)換為灰度值,默認(rèn)參數(shù)是1, 表示不改變?cè)瓐D像的像素
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;
}
注意:
在進(jìn)行圖像的灰度值處理之后,默認(rèn)情況下, 不會(huì)進(jìn)行圖像的直方圖進(jìn)行圖像的增強(qiáng),否則會(huì)出現(xiàn)運(yùn)行異常
代碼
#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 << "打開(kāi)圖片失敗,請(qǐng)檢查" << 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("直方圖均衡化圖像增強(qiáng)效果", p_w_picpath);
waitKey();
return 0;
}
看完上述內(nèi)容,你們掌握如何進(jìn)行OpenCV imread 圖片讀取的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。