Load Modify and Save Image Using OpenCV Highgui

This is simple example for load image, do some image manipulation and save the result.


#include <iostream>
#include "opencv2/highgui/highgui.hpp"
#include "opencv/cv.h"

using namespace std;

int main()
{
    cv::Mat src;
    cv::Mat src_binary;

    src=cv::imread("source.jpeg");
    if(src.empty()){
        cout<<"Cannot load the image !"<<endl;
        return 0;
        }

    imshow("src",src);

     cvtColor(src, src_binary, CV_BGR2GRAY); // Convert BGR  to gray
     cv::threshold(src_binary, src_binary, 100, 255, 0); // Threshold the image to convert binary image

    imshow("src_binary",src_binary);
    imwrite("/sdcard/result.jpeg",src_binary); // save image

     cvWaitKey(0); // Wait for key press
     return 0;
}


Comments