十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
如何进行OpenCV imread 图片读取,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。
成都创新互联公司是一家集成都网站制作、成都做网站、网站页面设计、网站优化SEO优化为一体的专业网络公司,已为成都等多地近百家企业提供网站建设服务。追求良好的浏览体验,以探求精品塑造与理念升华,设计最适合用户的网站页面。 合作只是第一步,服务才是根本,我们始终坚持讲诚信,负责任的原则,为您进行细心、贴心、认真的服务,与众多客户在蓬勃发展的市场环境中,互促共生。
函数原型
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
#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("直方图均衡化图像增强效果", p_w_picpath);
waitKey();
return 0;
}
看完上述内容,你们掌握如何进行OpenCV imread 图片读取的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注创新互联行业资讯频道,感谢各位的阅读!