Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3 | PointedEar | 1 | /*------------------------------------------------------------------------------------------*\ |
2 | This file contains material supporting chapter 3 of the cookbook: |
||
3 | Computer Vision Programming using the OpenCV Library. |
||
4 | by Robert Laganiere, Packt Publishing, 2011. |
||
5 | |||
6 | This program is free software; permission is hereby granted to use, copy, modify, |
||
7 | and distribute this source code, or portions thereof, for any purpose, without fee, |
||
8 | subject to the restriction that the copyright notice may not be removed |
||
9 | or altered from any source or altered source distribution. |
||
10 | The software is released on an as-is basis and without any warranties of any kind. |
||
11 | In particular, the software is not guaranteed to be fault-tolerant or free from failure. |
||
12 | The author disclaims all warranties with regard to this software, any use, |
||
13 | and any consequent failure, is purely the responsibility of the user. |
||
14 | |||
15 | Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name |
||
16 | \*------------------------------------------------------------------------------------------*/ |
||
17 | |||
18 | #include "colordetector.h" |
||
19 | |||
20 | cv::Mat ColorDetector::process(const cv::Mat &image) { |
||
21 | |||
22 | // re-allocate binary map if necessary |
||
23 | // same size as input image, but 1-channel |
||
24 | result.create(image.rows,image.cols,CV_8U); |
||
25 | |||
26 | // get the iterators |
||
27 | cv::Mat_<cv::Vec3b>::const_iterator it= image.begin<cv::Vec3b>(); |
||
28 | cv::Mat_<cv::Vec3b>::const_iterator itend= image.end<cv::Vec3b>(); |
||
29 | cv::Mat_<uchar>::iterator itout= result.begin<uchar>(); |
||
30 | |||
31 | // for each pixel |
||
32 | for ( ; it!= itend; ++it, ++itout) { |
||
33 | |||
34 | // process each pixel --------------------- |
||
35 | |||
36 | // compute distance from target color |
||
37 | if (getDistance(*it)<minDist) { |
||
38 | |||
39 | *itout= 255; |
||
40 | |||
41 | } else { |
||
42 | |||
43 | *itout= 0; |
||
44 | } |
||
45 | |||
46 | // end of pixel processing ---------------- |
||
47 | } |
||
48 | |||
49 | return result; |
||
50 | } |
||
51 |