opencv(c++)学习笔记1

开始用Visual studio安装使用opencv。
建议创建头文件,声明所有函数和include,并命名

/*
Read an image OPENCV
author: Chunying
date: 2016/06/13
*/

#ifndef KELE_H
#define KELE_H
#include <opencv2\core\core.hpp>  // cv::Mat
#include <opencv2\highgui\highgui.hpp> // cv::imshow
#include <iostream>
using namespace cv;
using namespace std;

#endif

然后在源文件,直接引用头文件,定义函数,cpp与h文件名字对应

读图像,显示图像

#include "kele.h"

int main(int argc, char ** argv) {
    // read an image
    char * filename = "../../data/chessbord.png";
    //char* filename = argv[1];
    Mat img;
    img = imread(filename,IMREAD_COLOR);

    //copy an image
    Mat B(img);
    Mat C = img;

    // show an image
    namedWindow("img",WINDOW_NORMAL);  //可以自动调节窗口
    imshow("img", img);
    waitKey(0);

    // if not image
    if (argc != 2 || !img.data) {
        cout << "no img\n";
        return -1;
    }

    // convert to gray image
    Mat gray;
    cvtColor(img, gray, COLOR_BGR2GRAY);
    imwrite("../../data/gray.png", gray);

    return 0;
}

argc是参数数量
argv是参数值,可以通过cout打出参数,一般argv[0]为程序本身,第二个参数可以文件名或其他
argv[0] kele.exe
argv[1] ….\img1.png

最小的数据类型是 char(1 byte 或者 8 bits, values from 0 to 255),更精细的颜色 ,对于各个颜色组成(G,B, R) 4 byte = 32 bit) or double (8 byte = 64 bit)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值