2014-03-27 2 views
0

모든 활성 상태의 평균 위치를 계산하고 싶습니다. blobs. 이를 위해서는 먼저 XY 위치의 합계가 필요합니다. 이 경우 어떻게해야합니까?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; 

답변

1

이 시도 :

int blobSize = contourFinder.blobs.size(); 
int sumX = 0; 
int sumY = 0; 

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; 

    sumX += xpos; 
    sumY += ypos; 

    // Manage each point here ... 
} 

float averageX = sumX/blobSize; 
float averageY = sumY/blobSize; 
+0

감사합니다! 너 멋지다! :디 –