计算图片的质心
#! /usr/bin/env python
import cv
if __name__ == '__main__':
im = cv.LoadImage( "c:\\3.jpg", cv.CV_LOAD_IMAGE_COLOR)
gray = cv.CreateImage((im.width, im.height), 8, 1)
cv.CvtColor(im, gray, cv.CV_BGR2GRAY)
w = gray.width
h = gray.height
x0 = 0;
x1 = 0;
y0 = 0;
y1 = 0;
for x in range(w) :
for y in range(h) :
val = cv.Get2D(gray, y, x)
x0 = x0 + val[0] * x
x1 = x1 + val[0]
y0 = y0 + val[0] * y
y1 = y1 + val[0]
xx = int(x0/x1)
yy = int(y0/y1)
#cv.Set2D(gray, yy, xx, cv.#79df85)
cv.NamedWindow("gray", cv.CV_WINDOW_AUTOSIZE)
cv.ShowImage("gray", gray)
cv.WaitKey(0)