gpt4 book ai didi

C++ BLOB 平均值

转载 作者:行者123 更新时间:2023-11-28 06:59:34 29 4
gpt4 key购买 nike

我想计算所有事件 blob 的平均位置。为此,首先我需要所有 XY 位置的总和。在这种情况下我该怎么做?

    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;

更新:

        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;

最佳答案

试试这个:

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;

关于C++ BLOB 平均值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22683003/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com