Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to crop an image using C++ ?

I tried this example: http://stackoverflow.com/a/15748297, but when I launch it some windows appears and it can't rewrite existing image, it can write to another one, but I don't need it, I want it to do silently - without windows, and better to rewrite existing image.

How to crop an image using C++ ?

I tried this example: http://stackoverflow.com/a/15748297, but when I launch it some windows appears and it can't rewrite existing image, it can write to another one, but I don't need it, I want it to do silently - without windows, and better to rewrite existing image. (or at least in C)

How to crop an image using C++ C/C++ ?

I tried this example: http://stackoverflow.com/a/15748297, but when I launch it some windows appears and it can't rewrite existing image, it can write to another one, but I don't need it, I want it to do silently - without windows, and better to rewrite existing image. (or at least in C)C++ is preferable.

How to crop an image using C/C++ ?

I tried this example: http://stackoverflow.com/a/15748297,

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

int main(int argc, char* argv[])
{
    cv::Mat img = cv::imread(argv[1]);
    if (img.empty())
    {
        std::cout << "!!! imread() failed to open target image" << std::endl;
        return -1;        
    }

    /* Set Region of Interest */

    int offset_x = 129;
    int offset_y = 129;

    cv::Rect roi;
    roi.x = offset_x;
    roi.y = offset_y;
    roi.width = img.size().width - (offset_x*2);
    roi.height = img.size().height - (offset_y*2);

    /* Crop the original image to the defined ROI */

    cv::Mat crop = img(roi);
    cv::imshow("crop", crop);
    cv::waitKey(0);

    cv::imwrite("noises_cropped.png", crop);

    return 0;
}

but when I launch it some windows appears and it can't rewrite existing image, it can write to another one, but I don't need it, I want it to do silently - without windows, and better to rewrite existing image. C++ is preferable.

How to crop an image using C/C++ ?

I tried this example:

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

int main(int argc, char* argv[])
{
    cv::Mat img = cv::imread(argv[1]);
    if (img.empty())
    {
        std::cout << "!!! imread() failed to open target image" << std::endl;
        return -1;        
    }

    /* Set Region of Interest */

    int offset_x = 129;
    int offset_y = 129;

    cv::Rect roi;
    roi.x = offset_x;
    roi.y = offset_y;
    roi.width = img.size().width - (offset_x*2);
    roi.height = img.size().height - (offset_y*2);

    /* Crop the original image to the defined ROI */

    cv::Mat crop = img(roi);
    cv::imshow("crop", crop);
    cv::waitKey(0);

    cv::imwrite("noises_cropped.png", crop);

    return 0;
}

but when I launch it some windows window appears and it can't rewrite existing image, it can write to another one, but I don't need it, I want it to do silently - without windows, and better to rewrite existing image. C++ is preferable.