cmakelists:
cmake_minimum_required(VERSION 3.7)
project(useMat)
set(CMAKE_CXX_STANDARD 11)
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_DIRS})
set(SOURCE_FILES main.cpp)
add_executable(useMat ${SOURCE_FILES})
target_link_libraries(useMat ${OpenCV_LIBS})
程序:
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
int main()
{
Mat image = imread("ubuntu.png", CV_LOAD_IMAGE_COLOR);
imshow("原始图像", image);
waitKey(0);
//用指针直接访问图像元素,本质上图像是二维矩阵,所以用指针一定能实现
Mat outimage1 = image.clone();
for (int i = 0; i < outimage1.rows; ++i)//这里注意,行就是行
{
for (int j =