0
我想計算所有活動的blobs
的平均位置。爲此,首先我需要所有X
和Y
職位的總和。我如何在這種情況下做到這一點?C++ BLOB平均值
contourFinder.findContours(grayImg, minBlobSize, maxBlobSize, blobNum, false);
blobTracker.trackBlobs(contourFinder.blobs);
std::vector<ofxCvBlob>::iterator blob;
for (auto blob = contourFinder.blobs.begin(); blob!= contourFinder.blobs.end(); blob++) {
float xpos = (*blob).center.x;
float ypos = (*blob).center.y;
int blobSize = contourFinder.blobs.size();
int sumX = ?
int sumY = ?
float averageX = sumX/blobSize;
float averageY = sumY/blobSize;
UPDATE:
contourFinder.findContours(grayImg, minBlobSize, maxBlobSize, blobNum, false);
blobTracker.trackBlobs(contourFinder.blobs);
std::vector<ofxCvBlob>::iterator blob;
int blobSize = contourFinder.blobs.size();
int sumX = 0;
int sumY = 0;
int sumArea = 0;
if(blobSize > 0){
for (auto blob = contourFinder.blobs.begin(); blob!= contourFinder.blobs.end(); blob++) {
float xpos = (*blob).center.x;
float ypos = (*blob).center.y;
float areaBlob = (*blob).area;
sumX += xpos * areaBlob;
sumY += ypos * areaBlob;
sumArea += areaBlob;
}
float averageX = sumX/sumArea;
float averageY = sumY/sumArea;
謝謝!你真棒! :d –