Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As requested here is my exact code where i want to calculate centroids from contour My exact code is like this 1) Taking RGB image as input 2) x=0,y=0,w=width of frame,h=height of frame.are the data passing</p> <p>void cRecursiveCentroids::ComputeCentroid(int x, int y, int w, int h, IplImage *data, bool splitOnUpDown, int level, int id, int addToId){</p> <pre><code>if (level == m_Levels-1 ) return; int Channels = data-&gt;nChannels; // Number of channels std::cout &lt;&lt; "Channels: " &lt;&lt; Channels &lt;&lt; "\n"; int xPos = 0; int yPos = 0; int nPix = 0; for (int i = x; i &lt; x+h; i++) //Tracing the contour { for (int j = y; j &lt; y+w; j++) { int pos = i * m_Wid * Channels + j; // Here may be the error i am thinking // if any data exists if (data-&gt;imageData[pos]&gt;0) { xPos += j; //std::cout &lt;&lt; "xPos: " &lt;&lt; xPos &lt;&lt; "\n"; yPos += i; // std::cout &lt;&lt; "yPos: " &lt;&lt; yPos &lt;&lt; "\n"; nPix++; } } } Check = nPix; if (nPix &gt; 0){ // Calculating Position xPos = (int)((float)xPos / (float)nPix); yPos = (int)((float)yPos / (float)nPix); int num = ( id + addToId ) &gt; 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 </code></pre> <p>}</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload