Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I am pretty sure that your problem is the C-api... apart that you are displaying a white image instead of crop; so:

  1. Switch to C++:

    void main(){ std::string imagine = "C:\Users\Silvia\Desktop\procesare imagini\images2\T4.png"; cv::Mat img = cv::imread(imagine); cv::Scalar currPixel; cv::Mat imgLUM = cv::imreadimagine); for (int y = imgLUM.rows/1.3; y > 0; y--) { for (int x = imgLUM.cols/1.3; x < imgLUM.cols; x++) { // ??? } } cv::imshow("Image", img); cv::imshow("Image2", imgLUM); cv::waitKey(0); }

  2. Then do a crop:

    cv::Mat image = cv::imread(imagine); cv::Rect cropArea(image.cols/3, image.rows/3, image.cols/3, image.rows/3); // play with values to obtain what you need, now it is the meddle of the image cv::Mat croppedImage = image(cropArea); cv::imshow("image", image); cv::imshow("cropped image", croppedImage); cv::waitKey();

  3. If you want to remove the cropped area of the image, then just do

    image(cropArea).setTo(cv::Scalar(0, 0, 0, 0));

click to hide/show revision 2
No.2 Revision

updated 2016-01-07 03:06:27 -0600

berak gravatar image

I am pretty sure that your problem is the C-api... apart that you are displaying a white image instead of crop; so:

  1. 1: Switch to C++:

    void main(){
    std::string imagine = "C:\Users\Silvia\Desktop\procesare imagini\images2\T4.png";
    cv::Mat img = cv::imread(imagine);
    cv::Scalar currPixel;
    cv::Mat imgLUM = cv::imreadimagine);
    for (int y = imgLUM.rows/1.3; y > 0; y--)
    {
    for (int x = imgLUM.cols/1.3; x < imgLUM.cols; x++)
    {
    // ???
    }
    }
    cv::imshow("Image", img);
    cv::imshow("Image2", imgLUM);
    cv::waitKey(0);
    }

  2. }

    2: Then do a crop:

    cv::Mat image = cv::imread(imagine);
    cv::Rect cropArea(image.cols/3, image.rows/3, image.cols/3, image.rows/3); // play with values to obtain what you need, now it is the meddle middle of the image
    cv::Mat croppedImage = image(cropArea);
    cv::imshow("image", image);
    cv::imshow("cropped image", croppedImage);
    cv::waitKey();

  3. cv::waitKey();

    3: If you want to remove the cropped area of the image, then just do

    image(cropArea).setTo(cv::Scalar(0, 0, 0, 0));

0));