如何進(jìn)行OpenCV imread 圖片讀取,相信很多沒有經(jīng)驗(yàn)的人對此束手無策,為此本文總結(jié)了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個(gè)問題。
成都創(chuàng)新互聯(lián)公司是一家集成都網(wǎng)站制作、成都做網(wǎng)站、網(wǎng)站頁面設(shè)計(jì)、網(wǎng)站優(yōu)化SEO優(yōu)化為一體的專業(yè)網(wǎng)絡(luò)公司,已為成都等多地近百家企業(yè)提供網(wǎng)站建設(shè)服務(wù)。追求良好的瀏覽體驗(yàn),以探求精品塑造與理念升華,設(shè)計(jì)最適合用戶的網(wǎng)站頁面。 合作只是第一步,服務(wù)才是根本,我們始終堅(jiān)持講誠信,負(fù)責(zé)任的原則,為您進(jìn)行細(xì)心、貼心、認(rèn)真的服務(wù),與眾多客戶在蓬勃發(fā)展的市場環(huán)境中,互促共生。
函數(shù)原型
CV_EXPORTS_W Mat imread( const String& filename, int flags = IMREAD_COLOR );
參數(shù)說明
第一個(gè)參數(shù)是圖片路徑名稱,強(qiáng)烈建議使用/作為目錄的分割符號,例如
第二參數(shù)具有如下的值,說明了讀取過程中是否需要進(jìn)行像素的操作,例如取值0,表示讀取過程中將像素轉(zhuǎn)換為灰度值,默認(rèn)參數(shù)是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;
}
注意:
在進(jìn)行圖像的灰度值處理之后,默認(rèn)情況下, 不會進(jìn)行圖像的直方圖進(jìn)行圖像的增強(qiáng),否則會出現(xiàn)運(yùn)行異常
代碼
#include
#include
#include
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("直方圖均衡化圖像增強(qiáng)效果", p_w_picpath);
waitKey();
return 0;
}
看完上述內(nèi)容,你們掌握如何進(jìn)行OpenCV imread 圖片讀取的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!