zoukankan      html  css  js  c++  java
  • OpenCV3读取、写入和保存图像

    需要说明的是在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;
    }

    显示的图片效果如下:

  • 相关阅读:
    浅谈隔板法
    最短路spaf及dijkstra模板
    P1219 最优贸易
    P1211 街道赛跑
    图结构模板
    P1218 过路费
    使用Asp.net Identity 创建用户 、登录代码
    asp.net identity 介绍
    响应式图像
    glyphicon 图标的使用
  • 原文地址:https://www.cnblogs.com/xiaomanon/p/5506645.html
Copyright © 2011-2022 走看看