1 /* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef COLORCHECKERTEST_H 18 #define COLORCHECKERTEST_H 19 20 #include <vector> 21 #include <string> 22 23 #include "testingimage.h" 24 #include "imagetesthandler.h" 25 26 class ColorCheckerTest : public ImageTestHandler { 27 public: 28 ColorCheckerTest() : ImageTestHandler() { 29 mImage = NULL; 30 mSuccess = false; 31 } 32 ColorCheckerTest(int debugHeight, int inputWidth) : 33 ImageTestHandler(debugHeight, inputWidth) { 34 mImage = NULL; 35 mSuccess = false; 36 } 37 ~ColorCheckerTest(); 38 39 void addTestingImage(TestingImage* inputImage); 40 void processData(); 41 42 const std::vector<std::vector<Vec2f> >* getCheckerCenterAdd() const { 43 std::vector<std::vector<Vec2f> >* returnPositions = 44 new std::vector<std::vector<Vec2f> >( 45 4, std::vector<Vec2f>(6, Vec2f(0.f, 0.f))); 46 47 for (int i = 0; i < 4; ++i) { 48 for (int j = 0; j < 6; ++j) { 49 (*returnPositions)[i][j] = (*mMatchPositions[i][j]); 50 } 51 } 52 return (returnPositions); 53 } 54 55 const std::vector<std::vector<float> >* getCheckerRadiusAdd() const { 56 std::vector<std::vector<float> >* returnRadius= 57 new std::vector<std::vector<float> >( 58 4, std::vector<float>(6, 0.f)); 59 60 for (int i = 0; i < 4; ++i) { 61 for (int j = 0; j < 6; ++j) { 62 (*returnRadius)[i][j] = mMatchRadius[i][j]; 63 } 64 } 65 return (returnRadius); 66 } 67 68 bool getSuccess() const { 69 return mSuccess; 70 } 71 72 private: 73 void initializeRefColor(); 74 75 void edgeDetection(); 76 void computeGradient(unsigned char* layer, float* gradientMap); 77 void houghLineDetection(bool* edgeMap, float* gradientAbsolute, 78 float* gradientDirection); 79 80 void findCheckerBoards(std::vector<std::vector<int> > linesDir1, 81 std::vector<std::vector<int> > linesDir2); 82 Vec2f findCrossing(std::vector<int> line1, std::vector<int> line2); 83 void findBestMatch(int i1, int i2, int j1, int j2); 84 85 bool verifyPointPair(Vec2f pointUpperLeft, Vec2f pointBottomRight, 86 Vec2f* pointCenter, Vec3i* color); 87 void verifyColorGrid(); 88 89 void fillRefColorGrid(); 90 91 TestingImage* mImage; 92 93 std::vector<std::vector< Vec3i* > > mCandidateColors; 94 std::vector<std::vector< Vec2f* > > mCandidatePositions; 95 96 std::vector<std::vector< Vec3i* > > mReferenceColors; 97 std::vector<std::vector< Vec2f* > > mMatchPositions; 98 std::vector<std::vector< Vec3f* > > mMatchColors; 99 std::vector<std::vector< float > > mMatchRadius; 100 101 bool mSuccess; 102 }; 103 104 #endif 105