QQQ

Dependencies:   mbed-rtos mbed

Fork of BX-car_s by Tony Lin

Revision:
18:88b083db7491
Parent:
17:af867c7512bb
Child:
19:eb0552a0ddae
--- a/camera_api.cpp	Sat Jun 28 18:59:41 2014 +0000
+++ b/camera_api.cpp	Sun Jun 29 06:41:21 2014 +0000
@@ -1,9 +1,7 @@
 #include "mbed.h"
 #include "camera_api.h"
-
 #define clk 2  //ms
 
-
 BX_camera::BX_camera(void)
 {
 
@@ -43,7 +41,7 @@
     bool f3=false;
     bool f4=false;
     int w_thr_up=32;
-    int w_thr_dn=0;
+    int w_thr_dn=2;
 
     b_start=b_center=b_end=b2_start=b2_center=b2_end=offset;
 
@@ -57,42 +55,34 @@
         
         switch(find_type) {
             case 0x01:
-                if(f1==false&&sign_line_imageR[i]==' ') {
-                    if(f1==false) {
+                if(f1==false && sign_line_imageR[i]==' ') {
                         b_start=i;
                         f1=true;
-                    }
                 }
-                if(f1== true&& f2==false&&sign_line_imageR[i]=='O') {
-                    if(f2==false) {
+                if(f1== true && f2==false && sign_line_imageR[i]=='O') {
                         b_end=i-1;
                         f2=true;
-                    }
                 }
-                if(f3==false&&sign_line_imageR[j]==' ') {
-                    if(f3==false) {
-                        b2_end=j;
+                if(f3==false && sign_line_imageR[j]==' ') {
+                        b2_start=j;
                         f3=true;
-                    }
                 }
-                if(f3==true&&f4==false&&sign_line_imageR[j]=='O') {
-                    if(f4==false) {
-                        b2_start=j+1;
+                if(f3==true && f4==false && sign_line_imageR[j]=='O') {
+                        b2_end=j+1;
                         f4=true;
-                    }
                 }
                 break;
 
             case 0x02:
                 if(sign_line_imageR[i]=='O') {
                     if(f1==false) {
-                        b_end=i;
+                        b_end=i-1;
                         f1=true;
                     }
                 }
                 if(sign_line_imageR[j]=='O') {
                     if(f2==false) {
-                        b_start=j;
+                        b_start=j+1;
                         f2=true;
                     }
                 }
@@ -100,8 +90,8 @@
         }
     }
 
-    b_w=b_start-b_end;
-    b2_w=b2_start-b2_end;
+    b_w=b_end-b_start+1;
+    b2_w=b2_start-b2_end+1;
 
     de_v=b_start;
     de_v2=b_end;
@@ -110,10 +100,13 @@
         case 0x01:
             b_center=(b_end+b_start)/2;
             b2_center=(b2_end+b2_start)/2;
-            if(w_thr_up>b_w && (b_center!=offset) && (b_center-offset)<(offset-b2_center))
+
+            if(w_thr_up>b_w && w_thr_dn<b_w && (b_center!=offset) && (b_center-offset)<(offset-b2_center))
                 center=b_center;
+            else if(w_thr_up>b2_w && w_thr_dn<b2_w && (b2_center!=offset)) 
+                center=b2_center;
             else
-                center=b2_center;
+                center=offset;
 
             /*            if( ( w_thr_up- (b_w))>0  &&( ( w_thr_up- (b_w)) < (w_thr_up-(b2_w)) )           ) {
                             center=(b_end+b_start)/2;