Changeset 14 for liacs/mss/project
- Timestamp:
- Dec 1, 2009, 12:55:10 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
liacs/mss/project/colour-tracking.c
r10 r14 29 29 int cvInitSystem(int argc, char *argv[]) { 30 30 // Don't care which camera to use. Use specified number elsewise 31 int cam_number = atoi(argv[1]) > 0 ? atoi(argv[1]) : -1; 31 int cam_number = -1; 32 if (argc > 1) 33 cam_number = atoi(argv[1]) > 0 ? atoi(argv[1]) : -1; 34 printf("Using camera %i\n", cam_number); 32 35 CvCapture *capture = cvCaptureFromCAM(cam_number); 33 36 int width = cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH); … … 35 38 36 39 37 uchar *filterdata, *outdata, *routdata, *goutdata, *boutdata ;40 uchar *filterdata, *outdata, *routdata, *goutdata, *boutdata, *targetdata; 38 41 39 42 … … 66 69 67 70 71 int cvalue = 0; 72 int xmax = -10; 73 int ymax = -10; 68 74 // Video run starts here ... 69 75 while (1) … … 90 96 goutdata = (uchar *) goutput->imageData; 91 97 boutdata = (uchar *) boutput->imageData; 98 targetdata = (uchar *) target->imageData; 92 99 93 k = 0, p = 0; 100 cvSub(output,filter,target,NULL); 101 cvalue = 20; 102 k = 0, p = 0, q = 0; 94 103 for( m = 0; m < image->height; m++) //row 95 104 { 96 105 for( n = 0; n < image->width; n++) //column 97 106 { 107 //p = targetdata[RVALUE(m,n,step)] + targetdata[GVALUE(m,n,step)] + targetdata[BVALUE(m,n,step)]; 108 p = targetdata[RVALUE(m,n,step)] + targetdata[GVALUE(m,n,step)]; 109 if ( p > cvalue) 110 { 111 q++; 112 if (q > 5) { 113 cvalue = p; 114 xmax = n; 115 ymax = m; 116 printf("Current value: %ix%i=%i\n", xmax, ymax, cvalue); 117 } 118 } else { 119 q = 0; 120 } 98 121 routdata[BVALUE(m,n,step)] = 0; // clear blue part 99 122 routdata[GVALUE(m,n,step)] = 0; // clear green part … … 117 140 // XXX: Use stuff like cvMat, cvGetRawData instead of internal hacking 118 141 // Make green 'fade' out by the presence of many red as well 119 filterdata = (uchar *) filter->imageData; 120 for( m = 0; m < image->height; m++) //row 121 { 122 for( n = 0; n < image->width; n++) //column 123 { 124 r = outdata[RVALUE(m,n,step)]; 125 g = outdata[GVALUE(m,n,step)]; 126 b = outdata[BVALUE(m,n,step)]; 127 // Many red, less blue and green. Good for laser pointer tracing 128 p = (r < 220) ? 0 : r; 129 p = (b < 180 || g < 180) ? 0 : p; 130 //p = (abs(p - filterdata[GVALUE(m,n,step)]) > 20) ? p : 0; 131 filterdata[GVALUE(m,n,step)] = p; 132 } 133 } 134 135 136 int xmin = 0, xmax = 0; 137 int ymin = 0, ymax = 0; 138 int value = 0, cmax = 0; 139 140 // Find the 'very' green point and mark it's surroundings 141 const int stepSize = 5; 142 for(m = 0; m < image->height; m = m+stepSize) 143 { 144 for(n = 0; n < image->width; n = n+stepSize) 145 { 146 // Make it stop processing all points, pick the ones with high value 147 value = filterdata[GVALUE(m,n,step)]; 148 if (value > cmax) 149 { 150 // detect 'square' 151 p = 0; 152 int SIZE = 3; 153 for (i = m; i < min(m+SIZE,height); i++) 154 { 155 for (j = n; j < min(n+SIZE,width); j++) 156 { 157 value = filterdata[GVALUE(i,j,step)]; 158 if (value > cmax) 159 { 160 p++; 161 } 162 } 163 } 164 165 166 SIZE = 6; 167 /* Make sure envirionment is 'low' */ 168 for (i = max(m-SIZE,0); i < m; i++) 169 { 170 for (j = max(n-SIZE,0); j < n; j++) 171 { 172 q = filterdata[GVALUE(i,j,step)]; 173 if (q > value) 174 { 175 p--; 176 } 177 } 178 } 179 for (i = min(m+SIZE,height); i < min(m+(2*SIZE),height); i++) 180 { 181 for (j= min(m+SIZE,width); j < min(m+(2*SIZE),width); j++) 182 { 183 q = filterdata[GVALUE(i,j,step)]; 184 if (q > value) 185 { 186 p--; 187 } 188 } 189 } 190 191 if (p > SIZE) 192 { 193 //printf("%ix%i=%i\n",n,m,value); 194 cmax = value; 195 xmax = n; 196 ymax = m; 197 } 198 } 199 } 200 } 142 // filterdata = (uchar *) filter->imageData; 201 143 202 144 // Prepare combined output 203 145 // Some way of making the picture more pretty 204 146 //cvSmooth(filter,target, CV_MEDIAN, 3, 3, 3, 3); 205 cvCopy( filter,target, NULL);147 cvCopy(output,filter, NULL); 206 148 cvCircle(target, cvPoint(xmax, ymax), 10, CV_RGB(255,0,0),4, 8, 0); 207 149 … … 217 159 // wait for any to press to quit 218 160 // Eeks! also HACK to make it refresh properly 219 if (cvWaitKey(20 ) != -1) {161 if (cvWaitKey(200) != -1) { 220 162 break; 221 163 }
Note:
See TracChangeset
for help on using the changeset viewer.