Ask Your Question

u9009's profile - activity

2017-02-11 14:15:29 -0600 received badge  Famous Question (source)
2016-11-07 05:58:29 -0600 received badge  Notable Question (source)
2016-09-14 03:36:41 -0600 received badge  Popular Question (source)
2015-12-11 12:14:14 -0600 commented question How to crop an image using C/C++ ?

The window was the main problem, and now I can rewrite the image, thanks a lot.

2015-12-11 09:58:24 -0600 received badge  Editor (source)
2015-12-11 09:44:22 -0600 asked a question 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 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.