程式語言 - OpenCV - Image Processing - Pixels Manipulation



參考資訊:
https://docs.opencv.org/master/d7/d9f/tutorial_linux_install.html

main.cpp

#include <stdio.h>
#include <opencv2/opencv.hpp>

using namespace cv;

int main(int argc, char **argv)
{
    Mat image;

    image = imread("main.jpg", 1);
    if (!image.data)
    {
        printf("No image data \n");
        return -1;
    }

    for (int y = 0; y < 50; y++)
    {
        for (int x = 0; x < 100; x++)
        {
            image.at<cv::Vec3b>(y, x)[0] = 255;
            image.at<cv::Vec3b>(y, x)[1] = 0;
            image.at<cv::Vec3b>(y, x)[2] = 0;
        }
    }

    namedWindow("show image", WINDOW_AUTOSIZE);
    imshow("show image", image);
    waitKey(0);
    return 0;
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.8)
project(main)
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(main main.cpp)
target_link_libraries(main ${OpenCV_LIBS})

編譯並且執行

$ cmake .
$ make
$ ./main

完成