0
def CalcCentre(data):
    centre = array([0,0,0])
    count = 0
    for p in data:
        centre = add(centre, array(p[:3]))
        count += 1
    centre = dot(1./count, centre)
    return centre
4
Contributors
5
Replies
7
Views
4 Years
Discussion Span
Last Post by Inshu
Featured Replies
  • As posted over we need more info,like input data. Code use [Numpy](http://numpy.scipy.org/) and it use function add() and dot(). To see what these numpy function dos,look into numpy doc here is [add()](http://www.scipy.org/add?highlight=%28add%29) To test function so it work i guessed for a nested list as input data. from numpy import … Read More

2

As posted over we need more info,like input data.
Code use Numpy and it use function add() and dot().
To see what these numpy function dos,look into numpy doc here is add()
To test function so it work i guessed for a nested list as input data.

from numpy import *

def CalcCentre(data):
    centre = array([0,0,0])
    count = 0
    for p in data:
        centre = add(centre, array(p[:3]))
        count += 1
    centre = dot(1./count, centre)
    return centre

print CalcCentre(array([[1,2,3], [4,5,6]]))
#--> [ 2.5  3.5  4.5]

Edited by snippsat

Comments
well spotted
0
import cv
from math import floor, sqrt, ceil
from numpy import array, dot, subtract, add, linalg as lin



def CalcCentre(data):
    centre = array([0,0,0])
    count = 0
    n = 0
    #data = list(data) 
    for p in data[n:n+3]:
        centre = add(centre, array(p[:3]))
        count += 1
        centre = dot(1./count, centre)
        return centre
    n += 1         
def ReadPointCloud(filename):
    f = open(filename)
    result = []
    for l in f:
        sp = l.split()
        t = tuple(map(float, sp[1:4]))
        result.append(t)
    return result

def main (data):


    j = 0
    for  i in len (data):
        while j != 3:
         centre = CalcCentre(data)
         j += 1 
         print centre 


if __name__ == '__main__':
    data = ReadPointCloud(r'Z:\data\NEHreflectance_Scanner 1_part.txt')

main(data)

Edited by Inshu

0

now this is the full prog or code..i want to find the centroid of every three points in a 3D data point cloud... but the code is printing the centroid for whole data 3 times...

also i want to know what does 'dot() ' function do ?? Also why len(data) is not working in the code ??

Edited by Inshu

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.