Comme demandé voici mon code exact où je veux calculer centroïdes du contour Mon code exact est comme ça 1) Prenant l'image RVB comme entrée 2) x = 0, y = 0, w = largeur de trame, h = hauteur de trame. Sont les données passant
void cRecursiveCentroids :: ComputeCentroid (int x, int y, int w, int h, données IplImage *, bool splitOnUpDown, int niveau, id int, int addToId) {
if (level == m_Levels-1) return;
int Channels = data->nChannels; // Number of channels
std::cout << "Channels: " << Channels << "\n";
int xPos = 0;
int yPos = 0;
int nPix = 0;
for (int i = x; i < x+h; i++) //Tracing the contour
{
for (int j = y; j < y+w; j++)
{
int pos = i * m_Wid * Channels + j; // Here may be the error i am thinking
// if any data exists
if (data->imageData[pos]>0)
{
xPos += j;
//std::cout << "xPos: " << xPos << "\n";
yPos += i;
// std::cout << "yPos: " << yPos << "\n";
nPix++;
}
}
}
Check = nPix;
if (nPix > 0){ // Calculating Position
xPos = (int)((float)xPos/(float)nPix);
yPos = (int)((float)yPos/(float)nPix);
int num = (id + addToId) > 16 ? 16 : (id+addToId);
m_Cent[num].posx = xPos;
m_Cent[num].posy = yPos;
m_Cent[num].level = level;
splitOnUpDown = !splitOnUpDown;
level = level+1;
if (splitOnUpDown) //Recursive calling for centroids
{
id *= 2;
ComputeCentroid(x,y,w,(yPos - y), data, splitOnUpDown, level, id, addToId);
ComputeCentroid(x,yPos,w,h-(yPos-y), data, splitOnUpDown, level, id+1, addToId);
} else {
id *= 2;
ComputeCentroid(x,y,(xPos-x),h, data, splitOnUpDown, level, id, addToId);
ComputeCentroid(xPos,y,w - (xPos-x),h, data, splitOnUpDown, level, id+1, addToId);
}
}
DrawCentroidPoints(); //Draw Centroid Points
}
hey, pouvez-vous mettre le code comme un "bloc de code" ... il est difficile de le lire, pour voir ce que vous voulez faire – Aishwar
éventuellement dupe de sa propre question: http://stackoverflow.com/questions/2325576/how-to-access-image-data-from-a-rgb-image-3channel-image-in-opencv – erelender
Oui - dupliquer de sa propre question http://stackoverflow.com/questions/2325576 et ne semble pas avoir lu la réponse fournie à la question précédente –