I am looking for an OpenCV function that can find connected components and perform a few tasks on them ( like getting the number of pixels, contour, list of pixels in the ob
You can use cv::connectedComponentsWithStats() function.
Here is an example.
// ...
cv::Mat labels, stats, centroids;
int connectivity = 8; // or 4
int label_count = cv::connectedComponentsWithStats(src, labels, stats, centroids, connectivity);
for (int i = 0; i < label_count; i++)
{
int x = stats.at(i, cv::CC_STAT_LEFT);
int y = stats.at(i, cv::CC_STAT_TOP);
int w = stats.at(i, cv::CC_STAT_WIDTH);
int h = stats.at(i, cv::CC_STAT_HEIGHT);
int area = stats.at(i, cv::CC_STAT_AREA);
double cx = centroids.at(i, 0);
double cy = centroids.at(i, 1);
// ...
}