Find the laser based on an image without the laser in it and with the laser in it Return an array that is the height of the image with a floating-point sub-pixel value of the laser You need to release the vector that gets returned
| 210 | // Return an array that is the height of the image with a floating-point sub-pixel value of the laser |
| 211 | // You need to release the vector that gets returned |
| 212 | vector<float>* ScanThread::FindLaser2(IplImage *withLaser) |
| 213 | { |
| 214 | // subtract the image with the laser in (withLaser) it from the image without the laser (noLaser) |
| 215 | // to find where the laser is |
| 216 | |
| 217 | IplImage *withLaserBlur = cvCloneImage(withLaser); |
| 218 | cvSmooth(noLaser, noLaserBlur, CV_GAUSSIAN, BLUR_AMOUNT); |
| 219 | |
| 220 | // copy images so we don't modify given images |
| 221 | IplImage *noLaserCopy = cvCloneImage(noLaserBlur); |
| 222 | IplImage *withLaserCopy = cvCloneImage(withLaserBlur); |
| 223 | |
| 224 | // create a single-channel image for processing |
| 225 | CvSize sz = cvSize(noLaser->width & -2, noLaser->height & -2); |
| 226 | IplImage *bwNoLaser = cvCreateImage(sz, 8, 1); |
| 227 | IplImage *bwWithLaser = cvCreateImage(sz, 8, 1); |
| 228 | IplImage *subImage = cvCreateImage(sz, 8, 1); |
| 229 | |
| 230 | // create the return vector |
| 231 | vector<float> *pxLocations = new vector<float>(sz.height, -1); |
| 232 | |
| 233 | // convert color images to black and white |
| 234 | |
| 235 | // the cvCvtColor function segfaults on windows. Not sure why. |
| 236 | cvCvtColor(noLaserCopy, bwNoLaser,CV_BGR2GRAY); |
| 237 | cvCvtColor(withLaserCopy, bwWithLaser,CV_BGR2GRAY); |
| 238 | |
| 239 | // subtract the no laser image from the with-laser image |
| 240 | // if nothing else moved, we should just see where the laser is now |
| 241 | cvSub(bwWithLaser, bwNoLaser, subImage); |
| 242 | |
| 243 | //captureThread->SendFrame(subImage); |
| 244 | |
| 245 | // set up single-pixel access to the subtracted and original image |
| 246 | RgbImage noLaserPx(noLaserCopy); |
| 247 | BwImage subPx(subImage); |
| 248 | BwImage bwWithLaserPx(bwWithLaser); |
| 249 | |
| 250 | // identify the laser in the top 25 rows |
| 251 | for (int h=0;h<25;h++) |
| 252 | { |
| 253 | (*pxLocations)[h] = FindBrightestPointInRow(subPx, h, sz.width); |
| 254 | } |
| 255 | |
| 256 | // compute the brightness of those laser hits |
| 257 | float brightSum = 0, brightAverage = 0; |
| 258 | |
| 259 | for (int h=0;h<25;h++) |
| 260 | { |
| 261 | brightSum += bwWithLaserPx[h][ int( (*pxLocations)[h] + 0.5) ]; |
| 262 | } |
| 263 | brightAverage = brightSum / 25.0; |
| 264 | |
| 265 | int bestPx; |
| 266 | |
| 267 | // for loop that loops through every row in the image |
| 268 | for (int h = 25; h < sz.height; h++) |
| 269 | { |
nothing calls this directly
no outgoing calls
no test coverage detected