5 unsigned char black
=255;
6 unsigned char white
=0;
8 struct track itrack
[80];
10 int image_prc(char *data
, int v
, int h
){
16 t
=image_head(data
, v
, h
,itrack
);
21 //itrack[0].vector = 0;
24 tt
=image_trail(data
,v
,h
,t
,itrack
);
43 int image_head(char *data
, int v
, int h
,struct track
*itrack
){
47 int pf
=0,nf
=0,j
=0,k
=0,t
=0,offset
=0,f
=0,po
=0,flag
=0;
48 int left
=h
, right
=0,it
=0,local
=0,crital
=0;
54 for(po
=v
-1; po
>9; po
--){
68 if(po
== 15) offset
=10;
69 if(po
<=40 && it
==0) return 0;
71 for(i
=local
-12; i
< h
-6; i
++){
73 j
=(unsigned char)*(data
+temp
+i
) ;
74 k
=(unsigned char)*(data
+temp
+i
+5) ;
75 if(j
-k
>offset
&& flag
==0){
81 if(k
-j
>offset
&& flag
==1){
84 if(right
-left
<20){ //Add start line searching here
89 //itrack[it].vector = i - itrack[it-1].x;
101 if(crital
>=2 && po
<40) return it
;
108 int image_trail(char *data
, int v
, int h
, int offset
,struct track
*itrack
){
110 unsigned char j
=0,k
=0;
118 temp
=itrack
[offset
-2].x
;
120 if(yo
<8) return offset
;
121 if(xo
-temp
>-3 && xo
-temp
<3) return offset
;
133 j
=*(data
+(yo
+i
)*h
+xo
);
134 k
=*(data
+(yo
+i
-2)*h
+xo
);
138 itrack
[offset
].y
=yo
+i
-2;
145 if(flag
==0) { crital
++;
146 printf("cri:%d\n",crital
);
147 printf("flag==1 crital:%d\n",crital
);
155 //if(crital>15) return offset;
164 j
=*(data
+(yo
+i
)*h
+xo
);
165 k
=*(data
+(yo
+i
-2)*h
+xo
);
169 itrack
[offset
].y
=yo
+i
-2;
177 printf("cri:%d\n",crital
);
185 //if(crital>15) return offset;
193 int image_body(char *data, int v, int h, char start){
195 int i=0,j=0,k=0,t=0,offset=0,f=0,po=0,flag=0,sline=0;
196 int scale=0,temp=0,vo=0,pos=0,neg=0,toggle=0,q=0,m=0;
200 sline=itrack[start].y-1;
201 vo=itrack[start].vector;
209 for(t=sline; t>5; t--){
223 for(i=0; i<scale; i++){
228 if(po+i*toggle+3<h && po+i*toggle>0) {
231 j=(unsigned char)*(data+temp+po+i*toggle) ;
232 k=(unsigned char)*(data+temp+po+i*toggle+2) ;
237 while(i*toggle+po+3+m<h && po+i*toggle+m>0){
239 j=(unsigned char)*(data+temp+po+i*toggle+m) ;
240 k=(unsigned char)*(data+temp+po+i*toggle+m+2) ;
244 //po=(pos+i*toggle+po)/2;
245 itrack[f].x=po+i*toggle+m;
247 itrack[f].vector=i*toggle+m;
248 //*(data+temp+po+i)=255;
249 po=2*(i*toggle+m)+po;
266 while(inthere+po+3+m<h && po+inthere+m>0){
268 j=(unsigned char)*(data+temp+po+inthere+m) ;
269 k=(unsigned char)*(data+temp+po+inthere+m+2) ;
273 //po=(pos+inthere+po)/2;
274 itrack[f].x=po+inthere+m;
276 itrack[f].vector=inthere+m;
277 //*(data+temp+po+i)=255;
312 int image_trail_old_new(char *data, int v, int h, int offset){
314 int vo=0, po=0,line=0;
322 vo = itrack[offset].vector;
323 po = itrack[offset].x;
324 line = itrack[offset].y;
327 for(line=offset; line>5; line--){
330 for(i=0; i<h-3; i++){
333 if(m-n>step && pf==0) {
339 if(n-m>step && pf==1){
342 if(neg-pos>1 && neg-pos<10){
343 itrack[offset++].x = (neg+pos)/2;
344 itrack[offset].y = line;
345 itrack[offset].vector=itrack[offset].x - itrack[offset-1].x;
354 itrack[offset++].x=-1;
356 itrack[offset].vector=0;
366 int image_body_old(char *data, int v, int h, char start){
387 itrack[0].vector = 0;
391 for(i =0; i<50; i++){
396 //if(black >white) black=white-20;
397 //if(white>220) white=black;
401 base = itrack[i].vector;
404 // printf("i%d: px=%d py=%d\n",i,px,py);
405 if(py<20 || px<2 || px>h-1) {
408 // itrack[i+1].vector=itrack[i].vector;
417 for(cal=0; cal < li; cal++){
419 if(j==0) temp = base+cal;
420 else temp = base -cal;
421 //printf("-%d",temp);
427 val = (unsigned char)*(data+(py-4)*h+px);
431 if(*(data+(py-4)*h+px-k)>black) break;
432 //printf("--%d",*(data+(py-4)*h+px-k));
436 *(data+(py-4)*h+px-k)=255;
439 itrack[i+1].y = py-4;
440 itrack[i+1].vector =0;
446 if(py-4 <0 || px +2>h) break;
447 val = (unsigned char)*(data+(py-4)*h+px+1);
448 // printf("in case 1: black is %d, val is %d\n",black,val);
451 if(*(data+(py-4)*h+px+1-k)>black) break;
455 *(data+(py-4)*h+px+1-k)=255;//black=val;
456 itrack[i+1].x = px+1-k;
457 itrack[i+1].y = py-4;
458 itrack[i+1].vector =1;
464 if(py-4 <0 || px-1<0) break;
465 val = (unsigned char)*(data+(py-4)*h+px-1);
468 if(*(data+(py-4)*h+px-1+k)>black) break;
472 *(data+(py-4)*h+px-1+k)=255;//black=val;
473 itrack[i+1].x = px-1+k;
474 itrack[i+1].y = py-4;
475 itrack[i+1].vector =-1;
481 if(py-4 <0 || px+3>h) break;
482 val = (unsigned char)*(data+(py-4)*h+px+2);
485 if(*(data+(py-4)*h+px+2-k)>black) break;
489 *(data+(py-4)*h+px+2-k)=255;//black=val;
490 itrack[i+1].x = px+2-k;
491 itrack[i+1].y = py-4;
492 itrack[i+1].vector =2;
498 if(py-4 <0 || px -2<0) break;
499 val = (unsigned char)*(data+(py-4)*h+px-2);
502 if(*(data+(py-4)*h+px-2+k)>black) break;
506 *(data+(py-4)*h+px-2+k)=255;//black=val;
507 itrack[i+1].x = px-2+k;
508 itrack[i+1].y = py-4;
509 itrack[i+1].vector =-2;
515 if(py-4 <0 || px+3>h) break;
516 val = (unsigned char)*(data+(py-3)*h+px+2);
519 if(*(data+(py-3)*h+px+2-k)>black) break;
523 *(data+(py-3)*h+px+2-k)=255;//black=val;
524 itrack[i+1].x = px+2-k;
525 itrack[i+1].y = py-3;
526 itrack[i+1].vector =3;
532 if(py-4 <0 || px -2<0) break;
533 val = (unsigned char)*(data+(py-3)*h+px-2);
536 if(*(data+(py-3)*h+px-2+k)>black) break;
540 *(data+(py-3)*h+px-2+k)=255;//black=val;
541 itrack[i+1].x = px-2+k;
542 itrack[i+1].y = py-3;
543 itrack[i+1].vector =-3;
549 if(py-4 <0 || px+3>h) break;
550 val = (unsigned char)*(data+(py-2)*h+px+2);
553 if(*(data+(py-2)*h+px+2-k)>black) break;
557 *(data+(py-2)*h+px+2-k)=255;//black=val;
558 itrack[i+1].x = px+2-k;
559 itrack[i+1].y = py-2;
560 itrack[i+1].vector =4;
566 if(py-4 <0 || px -2<0) break;
567 val = (unsigned char)*(data+(py-2)*h+px-2);
570 if(*(data+(py-2)*h+px-2+k)>black) break;
574 *(data+(py-2)*h+px-2+k)=255;//black=val;
575 itrack[i+1].x = px-2+k;
576 itrack[i+1].y = py-2;
577 itrack[i+1].vector =-4;
584 if(py-4 <0 || px+3>h) break;
585 val = (unsigned char)*(data+(py-1)*h+px+2);
588 if(*(data+(py-1)*h+px+2-k)>black) break;
593 *(data+(py-1)*h+px+2+k)=255;//black=val;
594 itrack[i+1].x = px+2;
595 itrack[i+1].y = py-1;
596 itrack[i+1].vector =5;
602 if(py-4 <0 || px -2<0) break;
603 val = (unsigned char)*(data+(py-1)*h+px-2);
606 if(*(data+(py-2)*h+px-2+k)>black) break;
610 *(data+(py-1)*h+px-2)=255;//black=val;
611 itrack[i+1].x = px-2;
612 itrack[i+1].y = py-1;
613 itrack[i+1].vector =-5;
620 val = (unsigned char)*(data+(py)*h+px+2);
623 if(*(data+(py)*h+px+2-k)>black) break;
628 *(data+(py)*h+px+2-k)=255;//black=val;
629 itrack[i+1].x = px+2;
631 itrack[i+1].vector =6;
638 val = (unsigned char)*(data+(py)*h+px-2);
641 if(*(data+(py-2)*h+px-2+k)>black) break;
645 *(data+(py)*h+px-2)=255;//black=val;
646 itrack[i+1].x = px-2;
648 itrack[i+1].vector =-6;
655 if(py+5> v ||px+3>h) break;
656 val = (unsigned char)*(data+(py+1)*h+px+2);
658 *(data+(py+1)*h+px+2)=255;//black=val;
659 itrack[i+1].x = px+2;
660 itrack[i+1].y = py+1;
661 itrack[i+1].vector =7;
666 if(py+5> v || px -2<0) break;
667 val = (unsigned char)*(data+(py+1)*h+px-2);
669 *(data+(py+1)*h+px-2)=255;//black=val;
670 itrack[i+1].x = px-2;
671 itrack[i+1].y = py+1;
672 itrack[i+1].vector =-7;
677 if(py+5> v || px+3>h) break;
678 val = (unsigned char)*(data+(py+2)*h+px+2);
680 *(data+(py+2)*h+px+2)=255;//black=val;
681 itrack[i+1].x = px+2;
682 itrack[i+1].y = py+2;
683 itrack[i+1].vector =8;
688 if(py+5> v|| px -2<0) break;
689 val = (unsigned char)*(data+(py+2)*h+px-2);
691 *(data+(py+2)*h+px-2)=255;//black=val;
692 itrack[i+1].x = px-2;
693 itrack[i+1].y = py+2;
694 itrack[i+1].vector =-8;
699 if(py+5> v || px+3>h) break;
700 val = (unsigned char)*(data+(py+3)*h+px+2);
702 *(data+(py+3)*h+px+2)=255;//black=val;
703 itrack[i+1].x = px+2;
704 itrack[i+1].y = py+3;
705 itrack[i+1].vector =9;
710 if(py+5> v ||px -2<0) break;
711 val = (unsigned char)*(data+(py+3)*h+px-2);
713 *(data+(py+3)*h+px-2)=255;//black=val;
714 itrack[i+1].x = px-2;
715 itrack[i+1].y = py+3;
716 itrack[i+1].vector =-9;
721 if(py+5> v || px+3>h ) break;
722 val = (unsigned char)*(data+(py+4)*h+px+2);
724 *(data+(py+4)*h+px+2)=255;//black=val;
725 itrack[i+1].x = px+2;
726 itrack[i+1].y = py+4;
727 itrack[i+1].vector =10;
732 if(py+5> v || px -2<0) break;
733 val = (unsigned char)*(data+(py+4)*h+px-2);
735 *(data+(py+4)*h+px-2)=255;//black=val;
736 itrack[i+1].x = px-2;
737 itrack[i+1].y = py+4;
738 itrack[i+1].vector =-10;
743 if(py+5> v || px+3>h) break;
744 val = (unsigned char)*(data+(py+4)*h+px+1);
746 *(data+(py+4)*h+px+1)=255;//black=val;
747 itrack[i+1].x = px+1;
748 itrack[i+1].y = py+4;
749 itrack[i+1].vector =11;
754 if(py+5> v || px -2<0) break;
755 val = (unsigned char)*(data+(py+4)*h+px-1);
757 *(data+(py+4)*h+px-1)=255;//black=val;
758 itrack[i+1].x = px-1;
759 itrack[i+1].y = py+4;
760 itrack[i+1].vector =-11;
767 val = (unsigned char)*(data+(py+4)*h+px);
769 *(data+(py+4)*h+px)=255;//black=val;
771 itrack[i+1].y = py+4;
772 itrack[i+1].vector =12;
782 if(py<35&& flag==1) {
783 if(itrack[i+1].vector<-1 || itrack[i+1].vector>1)
784 itrack[i+1].vector -=2;
797 itrack[i+1].vector=itrack[i].vector;
803 if(remote==1) py=py-2;
804 if(py<10 || px<1 || px>h-2) {
807 itrack[i+1].vector=itrack[i].vector;
811 if((unsigned char)*(data+(py-1)*h+px) < black) {
812 black = (unsigned char)*(data+(py-1)*h+px);
815 itrack[i+1].vector=itrack[i].vector;
818 if((unsigned char)*(data+(py-1)*h+px+1) < black) {
819 black = (unsigned char)*(data+(py-1)*h+px+1);
822 itrack[i+1].vector=itrack[i].vector;
825 if((unsigned char)*(data+(py-1)*h+px-1) < black) {
826 black = (unsigned char)*(data+(py-1)*h+px-1);
829 itrack[i+1].vector=itrack[i].vector;
832 if((unsigned char)*(data+py*h+px+1) < black) {
833 black = (unsigned char)*(data+py*h+px+1);
836 itrack[i+1].vector=itrack[i].vector;
839 if((unsigned char)*(data+py*h+px-1) < black) {
840 black = (unsigned char)*(data+py*h+px-1);
843 itrack[i+1].vector=itrack[i].vector;
848 itrack[i+1].vector=itrack[i].vector;
860 itrack[i+1].vector=itrack[i].vector;
864 int image_trail_old(char *data, int v, int h, int offset){
867 int i=0,j=0,left=0,right=0,last=0;
871 x=itrack[offset+j].x;
872 y=itrack[offset+j].y;
873 vt=itrack[offset+j].vector;
875 if(y<5 || x<1 || x>=h-1 || j+offset>49) return j;
880 left=*(data+y*h+x-1)+*(data+(y-1)*h+x-1);
881 right=*(data+y*h+x+1)+*(data+(y-1)*h+x+1);
886 else if(last>0) left+=1;
887 else return offset+j;
888 }else if(left<right){
890 if(*(data+y*h+x-1) < *(data+(y-1)*h+x-1)){
891 itrack[offset+j].x=x-1;
892 itrack[offset+j].y=y;
893 itrack[offset+j].vector=-6;
896 itrack[offset+j].x=x-1;
897 itrack[offset+j].y=y-1;
898 itrack[offset+j].vector=-5;
899 *(data+(y-1)*h+x-1)=255;
901 }else if(left>right){
903 if(*(data+y*h+x+1) < *(data+(y-1)*h+x+1)){
904 itrack[offset+j].x=x+1;
905 itrack[offset+j].y=y;
906 itrack[offset+j].vector=6;
909 itrack[offset+j].x=x+1;
910 itrack[offset+j].y=y-1;
911 itrack[offset+j].vector=5;
912 *(data+(y-1)*h+x+1)=255;