你好,游客 登录 注册 搜索
背景:
阅读新闻

OpenCV3读取、写入和保存图像

[日期:2016-05-21] 来源:Linux社区  作者:xiaomanon [字体:大 中 小]

需要说明的是在OpenCV3中已经将imread()和imwrite()函数转移到imgcodecs模块中,因此读写图像时,需要包含imgcodecs.hpp头文件,但是highgui.hpp头文件中已经包含了该头文件,因此不用再显式包含了。

#include <iostream>
#include <string>
using namespace std;

// OpenCV includes
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;

int main(int argc, const char** argv)
{
    // Read images
    Mat color = imread("../images/eating.jpg");
    Mat gray  = imread("../images/eating.jpg", 0);

    // Write images
    imwrite("gray.jpg", gray);

    // Get same pixel with opencv function
    int myRow = color.cols - 1;
    int myCol = color.rows - 1;
    Vec3b pixel = color.at<Vec3b>(myRow, myCol);
    cout << "Pixel Value (B, G, R): ("
        << (int)pixel[0] << ", "
        << (int)pixel[1] << ", "
        << (int)pixel[2] << ")" << endl;

    // Show images
    imshow("Color Image", color);
    imshow("Gray Image", gray);

    // Wait for any key
    waitKey(0);
    return 0;
}

显示的图片效果如下:

OpenCV官方教程中文版(For Python) PDF  http://www.linuxidc.com/Linux/2015-08/121400.htm

Ubuntu Linux下安装OpenCV2.4.1所需包 http://www.linuxidc.com/Linux/2012-08/68184.htm

Ubuntu 12.04 安装 OpenCV2.4.2 http://www.linuxidc.com/Linux/2012-09/70158.htm

CentOS下OpenCV无法读取视频文件 http://www.linuxidc.com/Linux/2011-07/39295.htm

Ubuntu 12.04下安装OpenCV 2.4.5总结 http://www.linuxidc.com/Linux/2013-06/86704.htm

Ubuntu 10.04中安装OpenCv2.1九步曲 http://www.linuxidc.com/Linux/2010-09/28678.htm

基于QT和OpenCV的人脸识别系统 http://www.linuxidc.com/Linux/2011-11/47806.htm

[翻译]Ubuntu 14.04, 13.10 下安装 OpenCV 2.4.9  http://www.linuxidc.com/Linux/2014-12/110045.htm

OpenCV的详细介绍:请点这里
OpenCV的下载地址:请点这里

本文永久更新链接地址:http://www.linuxidc.com/Linux/2016-05/131619.htm

linux
相关资讯       OpenCV读取图像 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款