Ask Your Question
0

I want to get the bright area of my picture(opencv3 Blob Detection)

asked 2016-12-17 02:20:47 -0600

Ruby_Sheng gravatar image

updated 2016-12-17 21:01:59 -0600

  • I am using opencv3,
  • and I want to "circle" the bright area of the picture I read by using
  • Blob Detection

Be more specific, I want to "circle" the biggest red area.

image description

  • I checked this document

http://docs.opencv.org/master/d0/d7a/...

  • But I really don't know how to write the code...

Thank you very much.

  • this is my code
 #include <opencv2\opencv.hpp>
    #include <iostream>
        using namespace cv;
        using namespace std;


    int main()
    {
        Mat image = imread("reid.jpg");

        namedWindow("img");

        imshow("img", image);

        Mat dstImage;
        threshold(image, dstImage, 200, 255, 3);

        Mat element = getStructuringElement(MORPH_RECT, Size(15, 15));
        Mat out;
        erode(dstImage, out, element);

        Ptr<cv::SimpleBlobDetector> detector = cv::SimpleBlobDetector::create();
        std::vector<KeyPoint> keyImg;
        detector->detect(out, keyImg);

        Mat result;
        drawKeypoints(out, keyImg, result);

        int i = 0;
        for (vector<KeyPoint>::iterator k = keyImg.begin(); k != keyImg.end(); ++k, ++i)
            circle(result, k->pt, (int)k->size, Scalar(0,0,0)[i % 65536]);

        namedWindow("pic", WINDOW_AUTOSIZE);
        imshow("pic", result);

        waitKey(0);
    }
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-12-17 03:21:19 -0600

LBerger gravatar image

updated 2016-12-17 03:21:48 -0600

I think you can find answer in this example

            Ptr<SimpleBlobDetector> sbd = b.dynamicCast<SimpleBlobDetector>();
            sbd->detect(img, keyImg, Mat());
            drawKeypoints(img, keyImg, result);
            int i = 0;
            for (vector<KeyPoint>::iterator k = keyImg.begin(); k != keyImg.end(); ++k, ++i)
                  circle(result, k->pt, (int)k->size, palette[i % 65536]);
edit flag offensive delete link more

Comments

well... - palette is underlined by red line...

Ruby_Sheng gravatar imageRuby_Sheng ( 2016-12-17 08:41:13 -0600 )edit

full code is in example. You can use Scalar(255,255,255) instead of palette.

LBerger gravatar imageLBerger ( 2016-12-17 08:59:25 -0600 )edit
  • the Scalar is really cool

    • however the image seems has no difference:( .......

    • maybe there's sth wrong with my blob code

Ruby_Sheng gravatar imageRuby_Sheng ( 2016-12-17 20:58:06 -0600 )edit

I paste my code on the question :) thanks a lot

Ruby_Sheng gravatar imageRuby_Sheng ( 2016-12-17 21:02:35 -0600 )edit

use Scalar(255,255,255) and remove the [i % 65536] part.

berak gravatar imageberak ( 2016-12-18 02:01:34 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-12-17 02:20:47 -0600

Seen: 632 times

Last updated: Dec 17 '16