Ask Your Question

Revision history [back]

do you want to find red areas like in this result image ?

morphological operators: Erosion and Dilation will help on this kind of shapes

image description

#include <iostream>
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"

using namespace cv;
using namespace std;

int main(int argc, const char* argv[])
{

    Mat src,gray,thresh,diff;

    src = imread("15920212749451237.png"); //reads as greyscale
    cvtColor(src, gray, COLOR_BGR2GRAY);

    gray = gray > 127;
    thresh = gray > 127;

    dilate(thresh, thresh, Mat(), Point(-1, -1), 20);
    erode(thresh, thresh, Mat(), Point(-1, -1), 20);

    absdiff(gray, thresh, diff);

    src.setTo(Scalar(0, 0, 255), diff);

    imshow("src", src);
    imshow("diff", diff);
    waitKey();
    return 0;
}

image description

do you want to find red areas like in this result image ?

morphological operators: Erosion and Dilation will help on this kind of shapes

image description

#include <iostream>
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"

using namespace cv;
using namespace std;

int main(int argc, const char* argv[])
{

    Mat src,gray,thresh,diff;

    src = imread("15920212749451237.png"); //reads as greyscale
imread("15920212749451237.png");
    cvtColor(src, gray, COLOR_BGR2GRAY);

    gray = gray > 127;
    thresh = gray > 127;

    dilate(thresh, thresh, Mat(), Point(-1, -1), 20);
    erode(thresh, thresh, Mat(), Point(-1, -1), 20);

    absdiff(gray, thresh, diff);

    src.setTo(Scalar(0, 0, 255), diff);

    imshow("src", src);
    imshow("diff", diff);
    waitKey();
    return 0;
}

image description