Index: trunk/code/projects/colonet/vision/vision_driver.c
===================================================================
--- trunk/code/projects/colonet/vision/vision_driver.c	(nonexistent)
+++ trunk/code/projects/colonet/vision/vision_driver.c	(revision 431)
@@ -0,0 +1,28 @@
+/**
+ * Driver for testing vision library.
+ */
+
+#include <vision.h>
+
+int main(int argc, char** argv) {
+  const char* filename = (argc == 2) ? argv[1] : (char*)"colonet.jpg";
+
+  if (init_vision(filename) != 0) {
+    fprintf(stderr, "init_vision failed.\n");
+    return -1;
+  }
+
+  VisionPosition* positions;
+  int num_positions = vision_get_robot_positions(&positions);
+
+  int i;
+  for (i = 0; i < num_positions; i++) {
+    printf("%d,%d\n", positions[i].x, positions[i].y);
+  }
+
+  free(positions);
+
+  vision_destroy();
+
+  return 0;
+}
Index: trunk/code/projects/colonet/vision/vision.c
===================================================================
--- trunk/code/projects/colonet/vision/vision.c	(revision 430)
+++ trunk/code/projects/colonet/vision/vision.c	(revision 431)
@@ -5,14 +5,12 @@
  * @author Rich Hong
  * @date 11/18/2007
  */
-#ifdef _CH_
-#pragma package <opencv>
-#endif
 
-#ifndef _EiC
-#include "cv.h"
-#include "highgui.h"
-#endif
+#include <vision.h>
+
+#include <cv.h>
+#include <highgui.h>
+
 #include <stdio.h>
 #include <stdlib.h>
 
@@ -20,19 +18,19 @@
 #define MAXH 150 //max threshold level
 #define DEBUG 0 //Debug to find threshold level
 
-// Load the source image. HighGUI use.
-IplImage *image02 = 0, *image03 = 0, *image04 = 0;
-
-void loop_image(void);
-
 struct CenterP {
   CvPoint center;
   int count;
 };
 
-int main( int argc, char** argv ) {
-  const char* filename = argc == 2 ? argv[1] : (char*)"colonet.jpg";
+static IplImage *image02, *image03, *image04;
 
+int vision_init(const char* filename) {
+  if ((image03 = cvLoadImage(filename, 0)) == 0) {
+    fprintf(stderr, "Failed to load image.\n");
+    return -1;
+  }
+
   // load image and force it to be grayscale
   if ((image03 = cvLoadImage(filename, 0)) == 0) {
     fprintf(stderr, "Failed to load image.\n");
@@ -40,26 +38,24 @@
   }
 
   // Create the destination images
-  image02 = cvCloneImage( image03 );
-  image04 = cvCloneImage( image03 );
+  image02 = cvCloneImage(image03);
+  image04 = cvCloneImage(image03);
 
   if (DEBUG) cvNamedWindow("Result", 1);
 
-  loop_image();
+  return 0;
+}
 
+void vision_destroy() {
   if (DEBUG) cvWaitKey(0);
 
   cvReleaseImage(&image02);
   cvReleaseImage(&image03);
 
-  if (DEBUG) {
-    cvDestroyWindow("Result");
-  }
-
-  return 0;
+  if (DEBUG) cvDestroyWindow("Result");
 }
 
-void loop_image() {
+int vision_get_robot_positions(VisionPosition** positions) {
   CvMemStorage* stor;
   CvSeq* cont;
   CvBox2D32f* box;
@@ -124,14 +120,15 @@
       if (size.width>10&&size.height>10&&size.width<20&&size.height<20){
         //printf("%d %d %d %d\n",center.x,center.y,size.width,size.height);
 
-        int found=0;
-        int j;
-        for (j=0;j<index;j++)
-          if (abs(bestc[j].center.x-center.x)<9&&abs(bestc[j].center.y-center.y)<9){
+        int found=0, j;
+        for (j = 0; j < index; j++) {
+          if (abs(bestc[j].center.x-center.x)<9&&abs(bestc[j].center.y-center.y)<9) {
             bestc[j].count++;
             found=1;
             break;
           }
+	}
+
         if (!found){
           struct CenterP c;
           c.center=center;
@@ -140,6 +137,7 @@
           index++;
         }
       }
+
       // Free memory.
       free(PointArray);
       free(PointArray2D32f);
@@ -147,11 +145,23 @@
     }
   }
 
-  image04 = cvCloneImage( image03 );
+  image04 = cvCloneImage(image03);
+
+  int count = 0;
+
   int i;
-  for (i=0; i < index; i++) {
-    if (bestc[i].count>7){
-      printf("%d,%d\n",bestc[i].center.x,bestc[i].center.y);
+  for (i = 0; i < index; i++) {
+    if (bestc[i].count > 7){
+      count++;
+    }
+  }
+
+  VisionPosition* pos = (VisionPosition*)malloc(sizeof(VisionPosition) * count);
+  for (i = 0; i < index; i++) {
+    if (bestc[i].count > 7){
+      pos[i].x = bestc[i].center.x;
+      pos[i].y = bestc[i].center.y;
+
       if (DEBUG) cvCircle(image04,bestc[i].center, 20, CV_RGB(0,0,0),5,8,0);
     }
   }
@@ -158,9 +168,7 @@
 
   // Show image. HighGUI use.
   if (DEBUG) cvShowImage( "Result", image04 );
+
+  *positions = pos;
+  return count;
 }
-/*
-#ifdef _EiC
-main(1,"vision.c");
-#endif
-*/
Index: trunk/code/projects/colonet/vision/Makefile
===================================================================
--- trunk/code/projects/colonet/vision/Makefile	(revision 430)
+++ trunk/code/projects/colonet/vision/Makefile	(revision 431)
@@ -2,13 +2,14 @@
 
 default: vision fitellipse
 
+driver: vision_driver.c
+
 vision: vision.c
 	mkdir -p bin
-	gcc -ggdb `pkg-config opencv --cflags --libs` vision.c -o bin/vision
+	gcc -ggdb `pkg-config opencv --cflags --libs` -I . vision.c -o vision
 
 fitellipse: fitellipse.c
-	mkdir -p bin
-	gcc -ggdb `pkg-config opencv --cflags --libs` fitellipse.c -o bin/fitellipse
+	gcc -ggdb `pkg-config opencv --cflags --libs` fitellipse.c -o fitellipse
 
 clean:
-	rm -rf bin *~
+	rm -rf vision fitellipse *~
