Вот исходный код из MATLAB:OpenCV 2.4.10 bwlabel - связные компоненты
% Calculate each separated object area
cDist=regionprops(bwImg, 'Area');
cDist=[cDist.Area];
% Label each object
[bwImgLabeled, ~]=bwlabel(bwImg);
% Calculate min and max object size based on assumptions on the color
% checker size
maxLabelSize = prod(size(imageData)./[4 6]);
minLabelSize = prod(size(imageData)./[4 6]./10);
% Find label indices for objects that are too large or too small
remInd = find(cDist > maxLabelSize);
remInd = [remInd find(cDist < minLabelSize)];
% Remove over/undersized objects
for n=1:length(remInd)
ri = bwImgLabeled == remInd(n);
bwImgLabeled(ri) = 0;
Здесь используется мой код OpenCV
//regionprops(bwImg, 'Area');
// cDist=[cDist.Area]
//cv::FileStorage file("C:\\Users\\gdarmon\\Desktop\\gili.txt", cv::FileStorage::WRITE);
//
//file << dst;
dst.convertTo(dst,CV_8U);
cv::vector<cv::vector<cv::Point> > contours;
cv::vector<cv::Vec4i> hierarchy;
cv::findContours(dst,contours,hierarchy,CV_RETR_CCOMP, CV_CHAIN_APPROX_NONE);
std::vector<cv::Moments> mu(contours.size());
for (int i = 0; i < contours.size(); i++)
{
mu[i] = cv::moments(contours[i],false);
}
vector<cv::Point2f> mc(contours.size());
for(int i = 0; i < contours.size(); i++)
{
mc[i] = cv::Point2f(mu[i].m10/mu[i].m00 , mu[i].m01/mu[i].m00);
}
Поскольку в настоящее время Ihave контуров Я хотел бы пользователь bwlabel function
1. Я понял, что этикетирование сделано для подключения 4-8 объектов. не могли бы вы объяснить, что такое маркировка на самом деле? Я бы сделал ажиотаж любой ссылкой.
2. connected components in OpenCV В этой статье некоторые люди говорят о CVblob, а некоторые о cvContourArea от opecv, можете ли вы объяснить разницу. и что будет лучше подходит для моего случая использования?
Update: вот что я попытался с помощью cvBlobs
IplImage* img_bw = new IplImage(dst);
CBlobResult blobs;
CBlob *currentBlob;
blobs = CBlobResult(img_bw, NULL, 0);
// Exclude all white blobs smaller than the given value (80)
// The bigger the last parameter, the bigger the blobs need
// to be for inclusion
blobs.Filter(blobs,
B_EXCLUDE,
CBlobGetArea(),
B_LESS,
80);
// Get the number of blobs discovered
int num_blobs = blobs.GetNumBlobs();
// Display the filtered blobs
IplImage* filtered = cvCreateImage(cvGetSize(img_bw),
IPL_DEPTH_8U,
3);
cvMerge(img_bw, img_bw, img_bw, NULL, filtered);
for (int i = 0; i < num_blobs; i++)
{
currentBlob = blobs.GetBlob(i);
currentBlob->FillBlob(filtered, CV_RGB(255,0,0));
}
// Display the input/output windows and images
cvNamedWindow("input");
cvNamedWindow("output");
cvShowImage("input", img_bw);
cvShowImage("output", filtered);
cv::waitKey(0);
/*% Calculate min and max object size based on assumptions on the color
% checker size
maxLabelSize = prod(size(imageData)./[4 6]);
minLabelSize = prod(size(imageData)./[4 6]./10);*/
double maxLabelSize = (dst.rows/4.0) * (dst.cols/6.0);
double minLabelSize = ((dst.rows/40.0) * (dst.cols/60.0));
если вы голос близко пожалуйста, объясните почему. – Gilad