opencv Mat对象
Posted hehe2014
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了opencv Mat对象相关的知识,希望对你有一定的参考价值。
#include <opencv2/opencv.hpp> #include <iostream> using namespace std; using namespace cv; int main(int argc, char** argv) { Mat src; src = imread("D:/vcprojects/images/test.png"); if (src.empty()) { cout << "could not load image..." << endl; return -1; } namedWindow("input", CV_WINDOW_AUTOSIZE); imshow("input", src); //Mat dst; //dst = Mat(src.size(), src.type()); //dst = Scalar(127, 0, 255); //namedWindow("output", CV_WINDOW_AUTOSIZE); //imshow("output", dst); //Mat dst = src.clone(); //namedWindow("output", CV_WINDOW_AUTOSIZE); //imshow("output", dst); //Mat dst; //src.copyTo(dst); //namedWindow("output", CV_WINDOW_AUTOSIZE); //imshow("output", dst); Mat dst; cvtColor(src, dst, CV_BGR2GRAY); printf("input image channels : %d ", src.channels()); printf("output image channels : %d ", dst.channels()); int cols = dst.cols; int rows = dst.rows; printf("rows : %d cols : %d ", rows, cols); const uchar* firstRow = dst.ptr<uchar>(0); printf("fist pixel value : %d ", *firstRow); namedWindow("output", CV_WINDOW_AUTOSIZE); imshow("output", dst); Mat M(100, 100, CV_8UC1, Scalar(127)); //cout << "M =" << endl << M << endl; namedWindow("333", CV_WINDOW_AUTOSIZE); imshow("333", M); Mat m1; m1.create(src.size(), src.type()); m1 = Scalar(0, 0, 255); namedWindow("44", CV_WINDOW_AUTOSIZE); imshow("44", m1); Mat csrc; Mat kernel = (Mat_<char>(3, 3) << 0, -1, 0, -1, 5, -1, 0, -1, 0); filter2D(src, csrc, -1, kernel); namedWindow("55", CV_WINDOW_AUTOSIZE); imshow("55", csrc); waitKey(0); return 0; }
以上是关于opencv Mat对象的主要内容,如果未能解决你的问题,请参考以下文章
OpenCV源代码赏析: Mat对象step属性含义及使用深入分析