I don't think this is an easy task Sergey, perhaps the question is not clear enough. For the algorithm to find the center of a visual object,the first thing is to detect it, I can suggest using voting based methods such as generalized hough transform
http://www.cs.utexas.edu/~dana/HoughT.pdf[
^] or geometric hashing
http://graphics.stanford.edu/courses/cs468-01-winter/papers/wr-ghao-97.pdf[
^], each feature point should vote for the object center, the feature point can be a point on an edge detected by canny edge detector or SIFT key points, which one to use depends on the application. For simple images even segmentation using pixel grouping can find the center of the visual object.
In that case try using the methods cvFindContours and cvBoundingRect, the center of the of the bounding rectangle will give the approximate if not the exact center of your objects.
#include <iostream>
#include <vector>
#include <cv.h>
#include <highgui.h>
using namespace std;
int main(int argc, char** argv){
IplImage* img_in = cvLoadImage("your_image.jpg",1);
IplImage* img_working = cvCreateImage(cvGetSize(img_in), 8, 1);
cvCvtColor(img_in, img_working, CV_BGR2GRAY);
CvSeq* seq;
vector<CvRect> boxes;
CvMemStorage* storage = cvCreateMemStorage(0);
cvClearMemStorage(storage);
cvFindContours(img_working, storage, &seq, sizeof(CvContour), CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE, cvPoint(600,200));
CvRect boundbox ;
for(; seq; seq = seq->h_next) {
boundbox = cvBoundingRect(seq);
boxes.push_back(boundbox);
}
cvWaitKey(0);
return 0;
}