In my project, I am trying to detect empty space using openCV in C++.
This is my code:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
Mat img = imread("D:/Downloads/residence-g1678df24f_1280.jpg",IMREAD_COLOR);
Mat img2;
Mat img3;
Canny(img, img2, 100, 100);
threshold(img2, img3,100,255,THRESH_BINARY);
if (img.empty())
{
cout << "There was an error while opening your image";
}
vector<KeyPoint> keypoints;
SimpleBlobDetector::Params params;
params.minThreshold = 10;
params.maxThreshold = 200;
params.filterByColor = true;
params.blobColor = 0;
Ptr<SimpleBlobDetector> detector = SimpleBlobDetector::create(params);
detector->detect( img3, keypoints);
Mat im_with_keypoints;
drawKeypoints(img3, keypoints, im_with_keypoints, Scalar(0, 0, 255), DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
imshow("Blob", im_with_keypoints);
waitKey(0);
return 0;
}
The output that I get is this:
What I want to get as an output is an image that detects the groups of pixels of a specific color (in this case- black) that together have an area greater than some
value. To illustrate what I want, I have attached an image below which I have altered using paint
manually:
Is there any library that will allow me to do this ? I even tried training a HAAR Cascade classifier with only black images as positive, but even that didn't work. Is there like a predefined library that will help me do this, or do I have to make one myself ? If possible, I want to find the biggest group (area) of pixels of the same color. It need not be of any particular shape.
NOTE: I even looked at this approach How to detect region of large # of white pixels using OpenCV?, but it does not seem to meet my requirements.