├── README.md ├── imageMSRA ├── 0_0_280.jpg ├── 0_0_280_symmetry.jpg ├── 0_0_284.jpg ├── 0_0_284_symmetry.jpg ├── 0_0_307.jpg ├── 0_0_307_symmetry.jpg ├── 0_0_547.jpg ├── 0_0_547_symmetry.jpg ├── 0_0_735.jpg ├── 0_0_735_symmetry.jpg ├── 0_0_77.jpg ├── 0_0_77_symmetry.jpg ├── 0_1_1339.jpg ├── 0_1_1339_symmetry.jpg ├── 0_3_3514.jpg └── 0_3_3514_symmetry.jpg ├── myself_symmetry.sln └── myself_symmetry ├── Color.cpp ├── Color.h ├── ColorHistogram.cpp ├── ColorHistogram.h ├── DispHistogram.cpp ├── DispHistogram.h ├── Input.cpp ├── Input.h ├── PlaneEstimate.cpp ├── PlaneEstimate.h ├── Symmetry.cpp ├── Symmetry.h ├── additional.cpp ├── additional.h ├── main.cpp ├── myTypes.h ├── myTypes2.h ├── myTypes_sp.h ├── myself_symmetry.vcxproj ├── myself_symmetry.vcxproj.filters ├── myself_symmetry.vcxproj.user └── unistd.h /README.md: -------------------------------------------------------------------------------- 1 | # SymmetryDetection 2 | 该项目是基于VS2010+Opencv2.4.8实现的图像对称性检测,可用于其它计算机视觉领域底层实现,或者对称特征提取。 3 | 4 | 图片对称性检测,越对称核心区域越高亮,根据特征梯度对称检测得到对称性分布结果。 5 | ### 检测效果图: 6 | ![](https://github.com/DUTFangXiang/SymmetryDetection/blob/master/imageMSRA/0_0_735.jpg "输入图像"); 7 | ![](https://github.com/DUTFangXiang/SymmetryDetection/blob/master/imageMSRA/0_0_735_symmetry.jpg "对称检测结果"); 8 | 9 | ![](https://github.com/DUTFangXiang/SymmetryDetection/blob/master/imageMSRA/0_3_3514.jpg "输入图像"); 10 | ![](https://github.com/DUTFangXiang/SymmetryDetection/blob/master/imageMSRA/0_3_3514_symmetry.jpg "对称检测结果"); 11 | 12 | ---------------------- 13 | ### 调试环境: 14 | Visual Studio 2010 x86 opencv 2.4.8 15 | 16 | imageMSRA 文件夹中放置输入图像以及保存输出结果 17 | 18 | ----------------------- 19 | ### 实现参考论文: 20 | 2010 ICPR Using Symmetry to Select Fixation Points for Segmentation 21 | 22 | 原文是实现关注点检测,也就是对称最核心点,源程序实现在Linux下。我对源程序做了修改,移植到Windows下VS工程中,并且输出整个对称分布图。 23 | 24 | ----------------------- 25 | ### Openvc配置: 26 | #### 环境:win7 VC2010 + opencv2.4.8 27 | 1、Project -> Properties -> VC++director:“include library” 28 | #### 添加 ”%opencv%\build\include” 29 | 2、Project -> Properties -> VC++director:“library director” 30 | #### 添加行”%opencv%\build\x86\vc10\lib” 31 | 3、Project ->Properties->Linker-> input ->additional dependencies 32 | 添加:opencv_calib3d248d.lib 、opencv_contrib248d.lib 33 | opencv_core248d.lib、opencv_features2d248d.lib 34 | opencv_flann248d.lib、opencv_gpu240d.lib、opencv_highgui248d.lib 35 | opencv_imgproc248d.lib、opencv_legacy248d.lib、opencv_ml248d.lib 36 | opencv_objdetect248d.lib、opencv_ts248d.lib、opencv_video248d.lib 37 | #### 关闭warning 38 | 4、调试关闭warning,Alt+F7,打开Project Setting对话框,点C++选项卡, 39 | Warning level ,选take off 40 | 41 | ---------------------- 42 | ### 修改日志: 43 | 1、是linux接口头文件,windows可以添加自建一个该头文件; 44 | 45 | 2、在windows的vc下面sys只有utime.h; 46 | 47 | 3、加入#define M_PI 3.14159265358979323846。vc2010版本中没有该定义,此时加入additional.h 48 | 49 | 4、sqrt()要求数据为float类型 50 | 51 | 5、没有DIR目录处理头 52 | 53 | 6、rint函数不存在vc中,需要自己写,放在了additional.cpp中了 54 | 55 | 7、project->xx Properties -> Manifest->Input and Output->Embed Manifest修改成 NO 56 | 57 | -------------------------------------------------------------------------------- /imageMSRA/0_0_280.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DUTFangXiang/SymmetryDetection/80d25c326d57dc037430b4d99fc31f1755adc0e3/imageMSRA/0_0_280.jpg -------------------------------------------------------------------------------- /imageMSRA/0_0_280_symmetry.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DUTFangXiang/SymmetryDetection/80d25c326d57dc037430b4d99fc31f1755adc0e3/imageMSRA/0_0_280_symmetry.jpg -------------------------------------------------------------------------------- /imageMSRA/0_0_284.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DUTFangXiang/SymmetryDetection/80d25c326d57dc037430b4d99fc31f1755adc0e3/imageMSRA/0_0_284.jpg -------------------------------------------------------------------------------- /imageMSRA/0_0_284_symmetry.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DUTFangXiang/SymmetryDetection/80d25c326d57dc037430b4d99fc31f1755adc0e3/imageMSRA/0_0_284_symmetry.jpg -------------------------------------------------------------------------------- /imageMSRA/0_0_307.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DUTFangXiang/SymmetryDetection/80d25c326d57dc037430b4d99fc31f1755adc0e3/imageMSRA/0_0_307.jpg -------------------------------------------------------------------------------- /imageMSRA/0_0_307_symmetry.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DUTFangXiang/SymmetryDetection/80d25c326d57dc037430b4d99fc31f1755adc0e3/imageMSRA/0_0_307_symmetry.jpg -------------------------------------------------------------------------------- /imageMSRA/0_0_547.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DUTFangXiang/SymmetryDetection/80d25c326d57dc037430b4d99fc31f1755adc0e3/imageMSRA/0_0_547.jpg -------------------------------------------------------------------------------- /imageMSRA/0_0_547_symmetry.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DUTFangXiang/SymmetryDetection/80d25c326d57dc037430b4d99fc31f1755adc0e3/imageMSRA/0_0_547_symmetry.jpg -------------------------------------------------------------------------------- /imageMSRA/0_0_735.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DUTFangXiang/SymmetryDetection/80d25c326d57dc037430b4d99fc31f1755adc0e3/imageMSRA/0_0_735.jpg -------------------------------------------------------------------------------- /imageMSRA/0_0_735_symmetry.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DUTFangXiang/SymmetryDetection/80d25c326d57dc037430b4d99fc31f1755adc0e3/imageMSRA/0_0_735_symmetry.jpg -------------------------------------------------------------------------------- /imageMSRA/0_0_77.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DUTFangXiang/SymmetryDetection/80d25c326d57dc037430b4d99fc31f1755adc0e3/imageMSRA/0_0_77.jpg -------------------------------------------------------------------------------- /imageMSRA/0_0_77_symmetry.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DUTFangXiang/SymmetryDetection/80d25c326d57dc037430b4d99fc31f1755adc0e3/imageMSRA/0_0_77_symmetry.jpg -------------------------------------------------------------------------------- /imageMSRA/0_1_1339.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DUTFangXiang/SymmetryDetection/80d25c326d57dc037430b4d99fc31f1755adc0e3/imageMSRA/0_1_1339.jpg -------------------------------------------------------------------------------- /imageMSRA/0_1_1339_symmetry.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DUTFangXiang/SymmetryDetection/80d25c326d57dc037430b4d99fc31f1755adc0e3/imageMSRA/0_1_1339_symmetry.jpg -------------------------------------------------------------------------------- /imageMSRA/0_3_3514.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DUTFangXiang/SymmetryDetection/80d25c326d57dc037430b4d99fc31f1755adc0e3/imageMSRA/0_3_3514.jpg -------------------------------------------------------------------------------- /imageMSRA/0_3_3514_symmetry.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DUTFangXiang/SymmetryDetection/80d25c326d57dc037430b4d99fc31f1755adc0e3/imageMSRA/0_3_3514_symmetry.jpg -------------------------------------------------------------------------------- /myself_symmetry.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "myself_symmetry", "myself_symmetry\myself_symmetry.vcxproj", "{9C2DE40C-59E8-4902-A48A-8263E2E3CE3D}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {9C2DE40C-59E8-4902-A48A-8263E2E3CE3D}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {9C2DE40C-59E8-4902-A48A-8263E2E3CE3D}.Debug|Win32.Build.0 = Debug|Win32 14 | {9C2DE40C-59E8-4902-A48A-8263E2E3CE3D}.Release|Win32.ActiveCfg = Release|Win32 15 | {9C2DE40C-59E8-4902-A48A-8263E2E3CE3D}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /myself_symmetry/Color.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * FAST AND AUTOMATIC DETECTION AND SEGMENTATION OF UNKNOWN OBJECTS (ADAS) 3 | * 4 | * Author: Gert Kootstra, Niklas Bergstrom 5 | * Email: gertkootstra@gmail.com 6 | * Website: http://www.csc.kth.se/~kootstra/ 7 | * Date: 22 Jul 2010 8 | * 9 | * Copyright (C) 2010, Gert Kootstra 10 | * 11 | * See README.txt and the html directory for documentation 12 | * and terms. 13 | */ 14 | 15 | #include "Color.h" 16 | #include "additional.h" 17 | 18 | using namespace Saliency; 19 | 20 | Saliency::Color::Color() { 21 | jetSize = 256; 22 | float jetTmp[] = { 23 | 0.000, 0.000, 0.516, 24 | 0.000, 0.000, 0.531, 25 | 0.000, 0.000, 0.547, 26 | 0.000, 0.000, 0.562, 27 | 0.000, 0.000, 0.578, 28 | 0.000, 0.000, 0.594, 29 | 0.000, 0.000, 0.609, 30 | 0.000, 0.000, 0.625, 31 | 0.000, 0.000, 0.641, 32 | 0.000, 0.000, 0.656, 33 | 0.000, 0.000, 0.672, 34 | 0.000, 0.000, 0.688, 35 | 0.000, 0.000, 0.703, 36 | 0.000, 0.000, 0.719, 37 | 0.000, 0.000, 0.734, 38 | 0.000, 0.000, 0.750, 39 | 0.000, 0.000, 0.766, 40 | 0.000, 0.000, 0.781, 41 | 0.000, 0.000, 0.797, 42 | 0.000, 0.000, 0.812, 43 | 0.000, 0.000, 0.828, 44 | 0.000, 0.000, 0.844, 45 | 0.000, 0.000, 0.859, 46 | 0.000, 0.000, 0.875, 47 | 0.000, 0.000, 0.891, 48 | 0.000, 0.000, 0.906, 49 | 0.000, 0.000, 0.922, 50 | 0.000, 0.000, 0.938, 51 | 0.000, 0.000, 0.953, 52 | 0.000, 0.000, 0.969, 53 | 0.000, 0.000, 0.984, 54 | 0.000, 0.000, 1.000, 55 | 0.000, 0.016, 1.000, 56 | 0.000, 0.031, 1.000, 57 | 0.000, 0.047, 1.000, 58 | 0.000, 0.062, 1.000, 59 | 0.000, 0.078, 1.000, 60 | 0.000, 0.094, 1.000, 61 | 0.000, 0.109, 1.000, 62 | 0.000, 0.125, 1.000, 63 | 0.000, 0.141, 1.000, 64 | 0.000, 0.156, 1.000, 65 | 0.000, 0.172, 1.000, 66 | 0.000, 0.188, 1.000, 67 | 0.000, 0.203, 1.000, 68 | 0.000, 0.219, 1.000, 69 | 0.000, 0.234, 1.000, 70 | 0.000, 0.250, 1.000, 71 | 0.000, 0.266, 1.000, 72 | 0.000, 0.281, 1.000, 73 | 0.000, 0.297, 1.000, 74 | 0.000, 0.312, 1.000, 75 | 0.000, 0.328, 1.000, 76 | 0.000, 0.344, 1.000, 77 | 0.000, 0.359, 1.000, 78 | 0.000, 0.375, 1.000, 79 | 0.000, 0.391, 1.000, 80 | 0.000, 0.406, 1.000, 81 | 0.000, 0.422, 1.000, 82 | 0.000, 0.438, 1.000, 83 | 0.000, 0.453, 1.000, 84 | 0.000, 0.469, 1.000, 85 | 0.000, 0.484, 1.000, 86 | 0.000, 0.500, 1.000, 87 | 0.000, 0.516, 1.000, 88 | 0.000, 0.531, 1.000, 89 | 0.000, 0.547, 1.000, 90 | 0.000, 0.562, 1.000, 91 | 0.000, 0.578, 1.000, 92 | 0.000, 0.594, 1.000, 93 | 0.000, 0.609, 1.000, 94 | 0.000, 0.625, 1.000, 95 | 0.000, 0.641, 1.000, 96 | 0.000, 0.656, 1.000, 97 | 0.000, 0.672, 1.000, 98 | 0.000, 0.688, 1.000, 99 | 0.000, 0.703, 1.000, 100 | 0.000, 0.719, 1.000, 101 | 0.000, 0.734, 1.000, 102 | 0.000, 0.750, 1.000, 103 | 0.000, 0.766, 1.000, 104 | 0.000, 0.781, 1.000, 105 | 0.000, 0.797, 1.000, 106 | 0.000, 0.812, 1.000, 107 | 0.000, 0.828, 1.000, 108 | 0.000, 0.844, 1.000, 109 | 0.000, 0.859, 1.000, 110 | 0.000, 0.875, 1.000, 111 | 0.000, 0.891, 1.000, 112 | 0.000, 0.906, 1.000, 113 | 0.000, 0.922, 1.000, 114 | 0.000, 0.938, 1.000, 115 | 0.000, 0.953, 1.000, 116 | 0.000, 0.969, 1.000, 117 | 0.000, 0.984, 1.000, 118 | 0.000, 1.000, 1.000, 119 | 0.016, 1.000, 0.984, 120 | 0.031, 1.000, 0.969, 121 | 0.047, 1.000, 0.953, 122 | 0.062, 1.000, 0.938, 123 | 0.078, 1.000, 0.922, 124 | 0.094, 1.000, 0.906, 125 | 0.109, 1.000, 0.891, 126 | 0.125, 1.000, 0.875, 127 | 0.141, 1.000, 0.859, 128 | 0.156, 1.000, 0.844, 129 | 0.172, 1.000, 0.828, 130 | 0.188, 1.000, 0.812, 131 | 0.203, 1.000, 0.797, 132 | 0.219, 1.000, 0.781, 133 | 0.234, 1.000, 0.766, 134 | 0.250, 1.000, 0.750, 135 | 0.266, 1.000, 0.734, 136 | 0.281, 1.000, 0.719, 137 | 0.297, 1.000, 0.703, 138 | 0.312, 1.000, 0.688, 139 | 0.328, 1.000, 0.672, 140 | 0.344, 1.000, 0.656, 141 | 0.359, 1.000, 0.641, 142 | 0.375, 1.000, 0.625, 143 | 0.391, 1.000, 0.609, 144 | 0.406, 1.000, 0.594, 145 | 0.422, 1.000, 0.578, 146 | 0.438, 1.000, 0.562, 147 | 0.453, 1.000, 0.547, 148 | 0.469, 1.000, 0.531, 149 | 0.484, 1.000, 0.516, 150 | 0.500, 1.000, 0.500, 151 | 0.516, 1.000, 0.484, 152 | 0.531, 1.000, 0.469, 153 | 0.547, 1.000, 0.453, 154 | 0.562, 1.000, 0.438, 155 | 0.578, 1.000, 0.422, 156 | 0.594, 1.000, 0.406, 157 | 0.609, 1.000, 0.391, 158 | 0.625, 1.000, 0.375, 159 | 0.641, 1.000, 0.359, 160 | 0.656, 1.000, 0.344, 161 | 0.672, 1.000, 0.328, 162 | 0.688, 1.000, 0.312, 163 | 0.703, 1.000, 0.297, 164 | 0.719, 1.000, 0.281, 165 | 0.734, 1.000, 0.266, 166 | 0.750, 1.000, 0.250, 167 | 0.766, 1.000, 0.234, 168 | 0.781, 1.000, 0.219, 169 | 0.797, 1.000, 0.203, 170 | 0.812, 1.000, 0.188, 171 | 0.828, 1.000, 0.172, 172 | 0.844, 1.000, 0.156, 173 | 0.859, 1.000, 0.141, 174 | 0.875, 1.000, 0.125, 175 | 0.891, 1.000, 0.109, 176 | 0.906, 1.000, 0.094, 177 | 0.922, 1.000, 0.078, 178 | 0.938, 1.000, 0.062, 179 | 0.953, 1.000, 0.047, 180 | 0.969, 1.000, 0.031, 181 | 0.984, 1.000, 0.016, 182 | 1.000, 1.000, 0.000, 183 | 1.000, 0.984, 0.000, 184 | 1.000, 0.969, 0.000, 185 | 1.000, 0.953, 0.000, 186 | 1.000, 0.938, 0.000, 187 | 1.000, 0.922, 0.000, 188 | 1.000, 0.906, 0.000, 189 | 1.000, 0.891, 0.000, 190 | 1.000, 0.875, 0.000, 191 | 1.000, 0.859, 0.000, 192 | 1.000, 0.844, 0.000, 193 | 1.000, 0.828, 0.000, 194 | 1.000, 0.812, 0.000, 195 | 1.000, 0.797, 0.000, 196 | 1.000, 0.781, 0.000, 197 | 1.000, 0.766, 0.000, 198 | 1.000, 0.750, 0.000, 199 | 1.000, 0.734, 0.000, 200 | 1.000, 0.719, 0.000, 201 | 1.000, 0.703, 0.000, 202 | 1.000, 0.688, 0.000, 203 | 1.000, 0.672, 0.000, 204 | 1.000, 0.656, 0.000, 205 | 1.000, 0.641, 0.000, 206 | 1.000, 0.625, 0.000, 207 | 1.000, 0.609, 0.000, 208 | 1.000, 0.594, 0.000, 209 | 1.000, 0.578, 0.000, 210 | 1.000, 0.562, 0.000, 211 | 1.000, 0.547, 0.000, 212 | 1.000, 0.531, 0.000, 213 | 1.000, 0.516, 0.000, 214 | 1.000, 0.500, 0.000, 215 | 1.000, 0.484, 0.000, 216 | 1.000, 0.469, 0.000, 217 | 1.000, 0.453, 0.000, 218 | 1.000, 0.438, 0.000, 219 | 1.000, 0.422, 0.000, 220 | 1.000, 0.406, 0.000, 221 | 1.000, 0.391, 0.000, 222 | 1.000, 0.375, 0.000, 223 | 1.000, 0.359, 0.000, 224 | 1.000, 0.344, 0.000, 225 | 1.000, 0.328, 0.000, 226 | 1.000, 0.312, 0.000, 227 | 1.000, 0.297, 0.000, 228 | 1.000, 0.281, 0.000, 229 | 1.000, 0.266, 0.000, 230 | 1.000, 0.250, 0.000, 231 | 1.000, 0.234, 0.000, 232 | 1.000, 0.219, 0.000, 233 | 1.000, 0.203, 0.000, 234 | 1.000, 0.188, 0.000, 235 | 1.000, 0.172, 0.000, 236 | 1.000, 0.156, 0.000, 237 | 1.000, 0.141, 0.000, 238 | 1.000, 0.125, 0.000, 239 | 1.000, 0.109, 0.000, 240 | 1.000, 0.094, 0.000, 241 | 1.000, 0.078, 0.000, 242 | 1.000, 0.062, 0.000, 243 | 1.000, 0.047, 0.000, 244 | 1.000, 0.031, 0.000, 245 | 1.000, 0.016, 0.000, 246 | 1.000, 0.000, 0.000, 247 | 0.984, 0.000, 0.000, 248 | 0.969, 0.000, 0.000, 249 | 0.953, 0.000, 0.000, 250 | 0.938, 0.000, 0.000, 251 | 0.922, 0.000, 0.000, 252 | 0.906, 0.000, 0.000, 253 | 0.891, 0.000, 0.000, 254 | 0.875, 0.000, 0.000, 255 | 0.859, 0.000, 0.000, 256 | 0.844, 0.000, 0.000, 257 | 0.828, 0.000, 0.000, 258 | 0.812, 0.000, 0.000, 259 | 0.797, 0.000, 0.000, 260 | 0.781, 0.000, 0.000, 261 | 0.766, 0.000, 0.000, 262 | 0.750, 0.000, 0.000, 263 | 0.734, 0.000, 0.000, 264 | 0.719, 0.000, 0.000, 265 | 0.703, 0.000, 0.000, 266 | 0.688, 0.000, 0.000, 267 | 0.672, 0.000, 0.000, 268 | 0.656, 0.000, 0.000, 269 | 0.641, 0.000, 0.000, 270 | 0.625, 0.000, 0.000, 271 | 0.609, 0.000, 0.000, 272 | 0.594, 0.000, 0.000, 273 | 0.578, 0.000, 0.000, 274 | 0.562, 0.000, 0.000, 275 | 0.547, 0.000, 0.000, 276 | 0.531, 0.000, 0.000, 277 | 0.516, 0.000, 0.000, 278 | 0.500, 0.000, 0.000}; 279 | 280 | jetF32 = new float[jetSize*3]; 281 | jetU8 = new unsigned char[jetSize*3]; 282 | for(int i=0; i 19 | 20 | namespace Saliency { 21 | //! Class with arrays to do a conversion of a value to the jet color coding 22 | class Color { 23 | public: 24 | Color(); 25 | ~Color(); 26 | 27 | float *jetF32; //!< Float array of size 3 * jetSize containing the RGB values of the jet colors (0.0 - 1.0) 28 | unsigned char *jetU8; //!< Unsigned char array of size 3 * jetSize containing the RGB values of the jet colors (0 - 255) 29 | int jetSize; 30 | }; 31 | } 32 | #endif 33 | -------------------------------------------------------------------------------- /myself_symmetry/ColorHistogram.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * FAST AND AUTOMATIC DETECTION AND SEGMENTATION OF UNKNOWN OBJECTS (ADAS) 3 | * 4 | * Author: Gert Kootstra, Niklas Bergstrom 5 | * Email: gertkootstra@gmail.com 6 | * Website: http://www.csc.kth.se/~kootstra/ 7 | * Date: 22 Jul 2010 8 | * 9 | * Copyright (C) 2010, Gert Kootstra 10 | * 11 | * See README.txt and the html directory for documentation 12 | * and terms. 13 | */ 14 | 15 | #include "ColorHistogram.h" 16 | #include "additional.h" 17 | ColorHistogram::ColorHistogram(ColorHistogram *cH2, bool copyPDF) { 18 | // Makes a copy of the color histogram. NB: Does not copy the pdf array is copyPDF==false, only allocates memory!! 19 | nrBins = cH2->nrBins; 20 | nrBinsT = cH2->nrBinsT; 21 | colorModel = cH2->colorModel; 22 | nrChannels = cH2->nrChannels; 23 | nrDataPoints = cH2->nrDataPoints; 24 | filterSize = cH2->filterSize; 25 | filterSigma = cH2->filterSigma; 26 | 27 | histogram = new int[nrBinsT]; 28 | for(int i=0; ihistogram[i]; 30 | pdf = new float[nrBinsT]; 31 | if(copyPDF) 32 | for(int i=0; ipdf[i]; 34 | 35 | } 36 | 37 | ColorHistogram::ColorHistogram(int nB, ColorModel cm) { 38 | // pow(nB, 3) should fit in an int 39 | filterSize = 5; 40 | filterSigma = 1.0f; 41 | nrBins = nB; 42 | colorModel = cm; 43 | if(colorModel==CM_RGB || colorModel==CM_LAB) { 44 | nrBinsT = nrBins*nrBins*nrBins; 45 | nrChannels = 3; 46 | } 47 | else { //CM_AB 48 | nrBinsT = nrBins*nrBins; 49 | nrChannels = 2; 50 | } 51 | histogram = new int[nrBinsT]; 52 | pdf = new float[nrBinsT]; 53 | //signature = cvCreateMat(nrBinsT, nrChannels+1, CV_32FC1); 54 | emptyHistogram(); 55 | } 56 | 57 | ColorHistogram::~ColorHistogram() { 58 | delete[] histogram; 59 | delete[] pdf; 60 | //cvReleaseMat(&signature); 61 | } 62 | 63 | void ColorHistogram::emptyHistogram() { 64 | for(int i=0; i0) 71 | emptyHistogram(); 72 | 73 | int idx; 74 | float binWidth = 1.0f/nrBins; 75 | 76 | if(colorModel==CM_RGB) { 77 | int rI, gI, bI; 78 | for(unsigned int i=0; ipixels.size(); i++) { 79 | idx = 3*spPixels->pixels[i]; 80 | rI = (int)(imgData[idx+2]/(binWidth+FLT_EPSILON)); 81 | gI = (int)(imgData[idx+1]/(binWidth+FLT_EPSILON)); 82 | bI = (int)(imgData[idx]/(binWidth+FLT_EPSILON)); 83 | histogram[histI3(rI,gI,bI)]++; 84 | nrDataPoints++; 85 | } 86 | } 87 | else if(colorModel==CM_LAB) { 88 | int yI, crI, cbI; 89 | for(unsigned int i=0; ipixels.size(); i++) { 90 | idx = 3*spPixels->pixels[i]; 91 | yI = (int)(imgData[idx]/(binWidth+FLT_EPSILON)); 92 | crI = (int)(imgData[idx+1]/(binWidth+FLT_EPSILON)); 93 | cbI = (int)(imgData[idx+2]/(binWidth+FLT_EPSILON)); 94 | histogram[histI3(yI,crI,cbI)]++; 95 | nrDataPoints++; 96 | } 97 | } 98 | else { // if(colorModel==CM_AB 99 | int crI, cbI; 100 | for(unsigned int i=0; ipixels.size(); i++) { 101 | idx = 3*spPixels->pixels[i]; 102 | crI = (int)(imgData[idx+1]/(binWidth+FLT_EPSILON)); 103 | cbI = (int)(imgData[idx+2]/(binWidth+FLT_EPSILON)); 104 | histogram[histI2(crI,cbI)]++; 105 | nrDataPoints++; 106 | } 107 | } 108 | 109 | smoothHistogram(); 110 | calcPDF(); 111 | //calcSignature(); 112 | } 113 | 114 | void ColorHistogram::makeHistogram(float *imgData, int width, int height, int x0, int y0, int x1, int y1) { 115 | // Makes a histogram from the data in imgData that is inside the square defined by x0, y0, x1, y1 116 | // imgData needs to be a pointer to bgr image data. 117 | // TODO: smoothing of histogram for generalisation 118 | if(nrDataPoints>0) 119 | emptyHistogram(); 120 | 121 | int i; 122 | float binWidth = 1.0f/nrBins; 123 | 124 | if(colorModel==CM_RGB) { 125 | int rI, gI, bI; 126 | for(int y=y0; ymaxV) 177 | maxV = histogram[i]; 178 | for(int i=0; idata.fl; 188 | 189 | if(colorModel==CM_RGB) { 190 | for(int rI=0; rIcolorModel || nrBins!=h2->nrBins) { 305 | float x = 0.0, x2 = 0.0; 306 | float y = 0.0, y2 = 0.0; 307 | for(int i=0; ipdf[i]; 310 | x2 += pdf[i]*pdf[i]; 311 | y2 += h2->pdf[i]*h2->pdf[i]; 312 | } 313 | float meanX = x/(nrBinsT); 314 | float meanY = y/(nrBinsT); 315 | float varX = x2 - x*x/(nrBinsT); 316 | float varY = y2 - y*y/(nrBinsT); 317 | float xy = 0.0; 318 | for(int i=0; ipdf[i]-meanY); 320 | float corr = xy / sqrt(varX*varY); 321 | corr = corr>0?corr:0; 322 | corr = corr>1?1:corr; 323 | return(corr); 324 | } 325 | else { 326 | printf("ERROR: ColorHistogram::getProbability, histograms have different color models or different number of bins\n"); 327 | exit(0); 328 | return(0); 329 | } 330 | } 331 | 332 | 333 | float ColorHistogram::getQuadraticDistance(ColorHistogram *h2) { 334 | printf("NOT IMPLEMENTED\n"); 335 | /* 336 | float *aRGB = new float[nrBinsT*nrBinsT]; 337 | float normA = sqrt(3)*nrBins; 338 | int i, i2; 339 | for(int rI=0; rIpdf[i2]); 360 | } 361 | sumD += (pdf[i] - h2->pdf[i]) * partSumD; 362 | } 363 | //printf("%f\n", sumD); 364 | 365 | delete[] aRGB; 366 | return(sqrt(sumD)); 367 | */ 368 | return(0.0); 369 | } 370 | 371 | /* 372 | float ColorHistogram::getEMD(ColorHistogram *h2) { 373 | // Calculate the Earth Movers Distance. This includes the distance between bins and is therefore 374 | // more appropriate for color histograms, since bins are not independent. 375 | // TODO: precaclulate the CvArrs to increase speed 376 | //cvReleaseMat(&signature); 377 | //signature = cvCreateMat(nrBinsT, nrChannels+1, CV_32FC1); 378 | 379 | if(colorModel==h2->colorModel || nrBins!=h2->nrBins) { 380 | float emd; 381 | if(colorModel==CM_RGB) 382 | emd = cvCalcEMD2(signature, h2->signature, CV_DIST_L2) / sqrt(3); // sqrt(3) maximum L2 measure in RGB 383 | else if(colorModel==CM_LAB) 384 | emd = cvCalcEMD2(signature, h2->signature, CV_DIST_L2) / sqrt(3); // sqrt(3) maximum L2 measure in RGB 385 | else // colorModel==CM_AB 386 | emd = cvCalcEMD2(signature, h2->signature, CV_DIST_L2) / sqrt(2); // sqrt(3) maximum L2 measure in RGB 387 | return(emd); 388 | } 389 | else{ 390 | printf("ERROR: ColorHistogram::getEMD, histograms have different color models or different number of bins\n"); 391 | exit(0); 392 | return(0); 393 | } 394 | //float emd = cvCalcEMD2(signature, signature2, CV_DIST_L2) / sqrt(3); // sqrt(3) maximum L2 measure in RGB 395 | //printf("emd: %f\n", emd); 396 | //cvReleaseMat(&signature2); 397 | } 398 | */ 399 | 400 | float *ColorHistogram::gaussFilter1D(int size, float sigma) { 401 | float *y = new float[size]; 402 | float m = ((float)size-1)/2; 403 | float sumY = 0.0f; 404 | for(int i=0; i= cH2.histogram[i] !! 562 | for(int i=0; ihistogram[i]; 564 | nrDataPoints -= cH2->nrDataPoints; 565 | } 566 | 567 | void ColorHistogram::addHistogram(ColorHistogram *cH2) { 568 | for(int i=0; ihistogram[i]; 570 | nrDataPoints += cH2->nrDataPoints; 571 | } 572 | 573 | -------------------------------------------------------------------------------- /myself_symmetry/ColorHistogram.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FAST AND AUTOMATIC DETECTION AND SEGMENTATION OF UNKNOWN OBJECTS (ADAS) 3 | * 4 | * Author: Gert Kootstra, Niklas Bergstrom 5 | * Email: gertkootstra@gmail.com 6 | * Website: http://www.csc.kth.se/~kootstra/ 7 | * Date: 22 Jul 2010 8 | * 9 | * Copyright (C) 2010, Gert Kootstra 10 | * 11 | * See README.txt and the html directory for documentation 12 | * and terms. 13 | */ 14 | 15 | #ifndef COLORHISTOGRAM_H 16 | #define COLORHISTOGRAM_H 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include "myTypes2.h" 28 | 29 | #define uchar unsigned char 30 | 31 | using namespace std; 32 | 33 | enum ColorModel {CM_RGB, CM_LAB, CM_AB}; 34 | 35 | //! Class containing the color histogram and methods to manipulate the histogram and calculate probabilities 36 | class ColorHistogram { 37 | public: 38 | ColorHistogram(int nB, ColorModel cm); 39 | ColorHistogram(ColorHistogram *colorHist, bool copyPDF); 40 | ~ColorHistogram(); 41 | void makeHistogram(float *imgData, int width, int height, int x0, int y0, int x1, int y1); 42 | void makeHistogram(float *imgData, int width, int height, Pixels *pixels, int spI); 43 | void extendHistogram(uchar *imgData, int width, int height, int x0, int y0, int x1, int y1); 44 | void print(); 45 | float getProbability(float r, float g, float b); 46 | float getProbability(ColorHistogram *hist2); 47 | float getQuadraticDistance(ColorHistogram *hist2); 48 | //float getEMD(ColorHistogram *hist2); 49 | void subtractHistogram(ColorHistogram *cH2); 50 | void addHistogram(ColorHistogram *cH2); 51 | void calcPDF(); 52 | 53 | float *pdf; 54 | int *histogram; 55 | //CvMat *signature; 56 | int nrBins; 57 | ColorModel colorModel; 58 | int nrBinsT; // total nr of bins 59 | int nrChannels; 60 | int nrDataPoints; 61 | int filterSize; // Size of the 1D gaussian filter. Should be an odd number and (filterSize-1)/2 < nrBins 62 | float filterSigma; // The standard deviation of the gaussian filter 63 | private: 64 | void emptyHistogram(); 65 | void calcPDFNorm0to1(); 66 | //void calcSignature(); 67 | int histI3(int c1I, int c2I, int c3I) { return(c1I*nrBins*nrBins + c2I*nrBins + c3I); }; 68 | int histI2(int c1I, int c2I) { return(c1I*nrBins + c2I); }; 69 | static float *gaussFilter1D(int size, float sigma); 70 | void smoothHistogram(); 71 | 72 | }; 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /myself_symmetry/DispHistogram.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * FAST AND AUTOMATIC DETECTION AND SEGMENTATION OF UNKNOWN OBJECTS (ADAS) 3 | * 4 | * Author: Gert Kootstra, Niklas Bergstrom 5 | * Email: gertkootstra@gmail.com 6 | * Website: http://www.csc.kth.se/~kootstra/ 7 | * Date: 22 Jul 2010 8 | * 9 | * Copyright (C) 2010, Gert Kootstra 10 | * 11 | * See README.txt and the html directory for documentation 12 | * and terms. 13 | */ 14 | 15 | #include "DispHistogram.h" 16 | #include "additional.h" 17 | 18 | DispHistogram::DispHistogram(int nrB) { 19 | filterSize = 9; 20 | filterSigma = 4.0f; 21 | nrBins = nrB; 22 | histogram = new int[nrBins]; 23 | pdf = new float[nrBins]; 24 | emptyHistogram(); 25 | } 26 | 27 | DispHistogram::DispHistogram(DispHistogram *dH2, bool copyPDF) { 28 | nrBins = dH2->nrBins; 29 | nrDataPoints = dH2->nrDataPoints; 30 | nrPixelPoints = dH2->nrPixelPoints; 31 | filterSize = dH2->filterSize; 32 | filterSigma = dH2->filterSigma; 33 | 34 | histogram = new int[nrBins]; 35 | for(int i=0; ihistogram[i]; 37 | pdf = new float[nrBins]; 38 | if(copyPDF) 39 | for(int i=0; ipdf[i]; 41 | } 42 | 43 | DispHistogram::~DispHistogram() { 44 | delete[] histogram; 45 | delete[] pdf; 46 | } 47 | 48 | void DispHistogram::makeHistogram(float *dispData, int width, int height, int x0, int y0, int x1, int y1) { 49 | if(nrDataPoints>0) 50 | emptyHistogram(); 51 | 52 | int i, dI; 53 | float binWidth = 1.0f/nrBins; 54 | 55 | for(int y=y0; y=0) { 59 | dI = (int)(dispData[i]/(binWidth+FLT_EPSILON)); 60 | histogram[dI]++; 61 | nrDataPoints++; 62 | } 63 | nrPixelPoints++; 64 | } 65 | } 66 | smoothHistogram(); 67 | calcPDF(); 68 | //calcSignature(); 69 | } 70 | 71 | void DispHistogram::makeHistogram(float *dispData, int width, int height, Pixels *spPixels, int spI) { 72 | if(nrDataPoints>0) 73 | emptyHistogram(); 74 | 75 | int idx, dI; 76 | float binWidth = 1.0f/nrBins; 77 | 78 | for(unsigned int i=0; ipixels.size(); i++) { 79 | idx = spPixels->pixels[i]; 80 | if(dispData[idx]>=0) { 81 | dI = (int)(dispData[idx]/(binWidth+FLT_EPSILON)); 82 | histogram[dI]++; 83 | nrDataPoints++; 84 | } 85 | nrPixelPoints++; 86 | } 87 | smoothHistogram(); 88 | calcPDF(); 89 | } 90 | 91 | float DispHistogram::getProbability(DispHistogram *h2) { 92 | // Compare the two histrograms. Use correlation. Correlations < 0 are set to 0 93 | float x = 0.0, x2 = 0.0; 94 | float y = 0.0, y2 = 0.0; 95 | for(int i=0; ipdf[i]; 98 | x2 += pdf[i]*pdf[i]; 99 | y2 += h2->pdf[i]*h2->pdf[i]; 100 | } 101 | float meanX = x/(nrBins); 102 | float meanY = y/(nrBins); 103 | float varX = x2 - x*x/(nrBins); 104 | float varY = y2 - y*y/(nrBins); 105 | float xy = 0.0; 106 | for(int i=0; ipdf[i]-meanY); 108 | float corr = xy / sqrt(varX*varY); 109 | corr = corr>0?corr:0; 110 | corr = corr>1?1:corr; 111 | return(corr); 112 | } 113 | 114 | void DispHistogram::subtractHistogram(DispHistogram *cH2) { 115 | for(int i=0; ihistogram[i]; 117 | nrDataPoints -= cH2->nrDataPoints; 118 | nrPixelPoints -= cH2->nrPixelPoints; 119 | } 120 | 121 | void DispHistogram::addHistogram(DispHistogram *cH2) { 122 | for(int i=0; ihistogram[i]; 124 | nrDataPoints += cH2->nrDataPoints; 125 | nrPixelPoints += cH2->nrPixelPoints; 126 | } 127 | 128 | void DispHistogram::calcPDF() { 129 | for(int i=0; i 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include "myTypes2.h" 27 | 28 | #define uchar unsigned char 29 | 30 | using namespace std; 31 | 32 | //! Class containing the disparity histogram and methods to manipulate the histogram and calculate probabilities 33 | class DispHistogram { 34 | public: 35 | DispHistogram(int nrB); 36 | DispHistogram(DispHistogram *dH, bool copyPDF); 37 | ~DispHistogram(); 38 | void makeHistogram(float *dispData, int width, int height, int x0, int y0, int x1, int y1); 39 | void makeHistogram(float *dispData, int width, int height, Pixels *spPixels, int spI); 40 | float getProbability(DispHistogram *hist2); 41 | void subtractHistogram(DispHistogram *cH2); 42 | void addHistogram(DispHistogram *cH2); 43 | void calcPDF(); 44 | void print(); 45 | float *pdf; 46 | int *histogram; 47 | int nrBins; 48 | int nrDataPoints; 49 | int nrPixelPoints; 50 | int filterSize; // Size of the 1D gaussian filter. Should be an odd number and (filterSize-1)/2 < nrBins 51 | float filterSigma; // The standard deviation of the gaussian filter 52 | 53 | private: 54 | void emptyHistogram(); 55 | static float *gaussFilter1D(int size, float sigma); 56 | void smoothHistogram(); 57 | }; 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /myself_symmetry/Input.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DUTFangXiang/SymmetryDetection/80d25c326d57dc037430b4d99fc31f1755adc0e3/myself_symmetry/Input.cpp -------------------------------------------------------------------------------- /myself_symmetry/Input.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FAST AND AUTOMATIC DETECTION AND SEGMENTATION OF UNKNOWN OBJECTS (ADAS) 3 | * 4 | * Author: Gert Kootstra, Niklas Bergstrom 5 | * Email: gertkootstra@gmail.com 6 | * Website: http://www.csc.kth.se/~kootstra/ 7 | * Date: 22 Jul 2010 8 | * 9 | * Copyright (C) 2010, Gert Kootstra 10 | * 11 | * See README.txt and the html directory for documentation 12 | * and terms. 13 | */ 14 | 15 | #ifndef INPUT_H 16 | #define INPUT_H 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include "Color.h" 24 | 25 | using namespace Saliency; 26 | 27 | //! Class to read the images and disparity maps of the KOD database and transform the values to the right format and value ranges. 28 | class Input { 29 | public: 30 | Input(char *imgFile,int widthScaled, int heightScaled); 31 | ~Input(); 32 | void calcLab(); 33 | IplImage *getImgOriginal() { return imgOriginal; }; 34 | IplImage *getDispOriginal() { return dispOriginal; }; 35 | IplImage *getImgScaled() { return imgScaled; }; 36 | IplImage *getDispScaled() { return dispScaled; }; 37 | IplImage *getYCrCbImgScaled() { return yCrCbImgScaled; }; 38 | float *getImgDataScaled() { return imgDataScaled; }; 39 | float *getDispDataScaled() { return dispDataScaled; }; 40 | float *getYCrCbImgDataScaled() { return yCrCbImgDataScaled; }; 41 | float getResizePropX() { return resizePropX; }; 42 | float getResizePropY() { return resizePropY; }; 43 | int getWidthOriginal() { return widthOriginal; }; 44 | int getHeightOriginal() { return heightOriginal; }; 45 | int getWidthScaled() { return widthScaled; }; 46 | int getHeightScaled() { return heightScaled; }; 47 | IplImage *getDispImage(); 48 | 49 | private: 50 | float *readDisparityData(char *dispFile, int width, int height); 51 | float *copyImageDataFloat(IplImage *img); 52 | float *copyDispDataFloat(IplImage *_dImg, int distMedianSize); 53 | float *copyDispDataFloat2(IplImage *_dImg, int distMedianSize); 54 | 55 | int widthScaled, heightScaled, widthOriginal, heightOriginal; 56 | IplImage *dispOriginal; 57 | IplImage *imgOriginal; 58 | IplImage *dispScaled; 59 | IplImage *imgScaled; 60 | IplImage *yCrCbImgScaled; 61 | float *imgDataScaled; 62 | float *dispDataScaled; 63 | float *yCrCbImgDataScaled; 64 | float resizePropX; 65 | float resizePropY; 66 | }; 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /myself_symmetry/PlaneEstimate.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * FAST AND AUTOMATIC DETECTION AND SEGMENTATION OF UNKNOWN OBJECTS (ADAS) 3 | * 4 | * Author: Gert Kootstra, Niklas Bergstrom 5 | * Email: gertkootstra@gmail.com 6 | * Website: http://www.csc.kth.se/~kootstra/ 7 | * Date: 22 Jul 2010 8 | * 9 | * Copyright (C) 2010, Gert Kootstra 10 | * 11 | * See README.txt and the html directory for documentation 12 | * and terms. 13 | */ 14 | 15 | #include "PlaneEstimate.h" 16 | 17 | /* 18 | void PlaneEstimate::findTablePlane(IplImage* pImg, sSurface &surface) { 19 | 20 | int width = pImg->width; 21 | int height = pImg->height; 22 | 23 | float* lDisps = new float[width*height]; 24 | int* wCoords = new int[width*height]; 25 | int* hCoords = new int[width*height]; 26 | 27 | int counter = 0; 28 | for(int h=0; hwidth; 50 | int height = sp->height; 51 | 52 | float* lDisps = new float[width*height]; 53 | int* wCoords = new int[width*height]; 54 | int* hCoords = new int[width*height]; 55 | 56 | int counter = 0; 57 | for(int h=0; hwidth; 80 | int height = pImg->height; 81 | 82 | int averageNrPixelsPerSP = round(width*height/sp->nrSPixels); 83 | 84 | vector lDisps; 85 | vector wCoords; 86 | vector hCoords; 87 | int* counters = new int[sp->nrSPixels]; 88 | int* maxval = new int[sp->nrSPixels]; 89 | 90 | for(int i=0; inrSPixels; ++i) { 91 | // Allocate 10 times the average super pixel size 92 | lDisps.push_back(new float[10*averageNrPixelsPerSP]); 93 | wCoords.push_back(new int[10*averageNrPixelsPerSP]); 94 | hCoords.push_back(new int[10*averageNrPixelsPerSP]); 95 | counters[i] = 0; 96 | maxval[i] = 10*averageNrPixelsPerSP; 97 | } 98 | 99 | for(int h=0; hsPixels[h*width+w]; 103 | 104 | // If more space is needed, fix 105 | if(counters[label] == maxval[label]) { 106 | float* tmpD = new float[2*maxval[label]]; 107 | int* tmpW = new int[2*maxval[label]]; 108 | int* tmpH = new int[2*maxval[label]]; 109 | memcpy(tmpD, lDisps[label],maxval[label]*sizeof(float)); 110 | memcpy(tmpW, wCoords[label],maxval[label]*sizeof(int)); 111 | memcpy(tmpH, hCoords[label],maxval[label]*sizeof(int)); 112 | float* td = lDisps[label]; 113 | int* tw = wCoords[label]; 114 | int* th = hCoords[label]; 115 | lDisps[label] = tmpD; 116 | wCoords[label] = tmpW; 117 | hCoords[label] = tmpH; 118 | delete [] td; 119 | delete [] tw; 120 | delete [] th; 121 | } 122 | 123 | (lDisps[label])[counters[label]] = CV_IMAGE_ELEM(pImg, unsigned char, h, w ); 124 | (wCoords[label])[counters[label]] = w; 125 | (hCoords[label])[counters[label]] = h; 126 | ++counters[label]; 127 | } 128 | } 129 | } 130 | 131 | struct timeval begin, end; 132 | for(int i=0; inrSPixels; ++i) { 133 | //cout << "Disp points in sp " << i << ": " << counters[i] << endl; 134 | if(counters[i] > 10) { 135 | gettimeofday(&begin, NULL); 136 | findPlane(lDisps[i], wCoords[i], hCoords[i], counters[i], 137 | height, surfaces[i],100); 138 | gettimeofday(&end, NULL); 139 | //cout << " findTablePlane: " << 1000*(end.tv_sec-begin.tv_sec) + (end.tv_usec-begin.tv_usec)/1000 << " ms" << endl; 140 | } else { 141 | surfaces[i].alpha = 0; 142 | surfaces[i].beta = 0; 143 | surfaces[i].disp = 0; 144 | } 145 | } 146 | 147 | 148 | for(int i=0; inrSPixels; ++i) { 149 | delete [] lDisps[i]; 150 | delete [] wCoords[i]; 151 | delete [] hCoords[i]; 152 | } 153 | delete [] counters; 154 | delete [] maxval; 155 | 156 | } 157 | */ 158 | 159 | void PlaneEstimate::findSuperPixelPlane(float *pImg, sSurface* surfaces) { 160 | 161 | int width = sp->width; 162 | int height = sp->height; 163 | 164 | int averageNrPixelsPerSP = round(width*height/sp->nrSPixels); 165 | 166 | vector lDisps; 167 | vector wCoords; 168 | vector hCoords; 169 | int* counters = new int[sp->nrSPixels]; 170 | int* maxval = new int[sp->nrSPixels]; 171 | 172 | for(int i=0; inrSPixels; ++i) { 173 | // Allocate 10 times the average super pixel size 174 | lDisps.push_back(new float[10*averageNrPixelsPerSP]); 175 | wCoords.push_back(new int[10*averageNrPixelsPerSP]); 176 | hCoords.push_back(new int[10*averageNrPixelsPerSP]); 177 | counters[i] = 0; 178 | maxval[i] = 10*averageNrPixelsPerSP; 179 | } 180 | 181 | for(int h=0; hsPixels[h*width+w]; 185 | 186 | // If more space is needed, fix 187 | if(counters[label] == maxval[label]) { 188 | float* tmpD = new float[2*maxval[label]]; 189 | int* tmpW = new int[2*maxval[label]]; 190 | int* tmpH = new int[2*maxval[label]]; 191 | memcpy(tmpD, lDisps[label],maxval[label]*sizeof(float)); 192 | memcpy(tmpW, wCoords[label],maxval[label]*sizeof(int)); 193 | memcpy(tmpH, hCoords[label],maxval[label]*sizeof(int)); 194 | float* td = lDisps[label]; 195 | int* tw = wCoords[label]; 196 | int* th = hCoords[label]; 197 | lDisps[label] = tmpD; 198 | wCoords[label] = tmpW; 199 | hCoords[label] = tmpH; 200 | delete [] td; 201 | delete [] tw; 202 | delete [] th; 203 | } 204 | 205 | (lDisps[label])[counters[label]] = pImg[h*width+w]; 206 | (wCoords[label])[counters[label]] = w; 207 | (hCoords[label])[counters[label]] = h; 208 | ++counters[label]; 209 | } 210 | } 211 | } 212 | 213 | struct timeval begin, end; 214 | for(int i=0; inrSPixels; ++i) { 215 | //cout << "Disp points in sp " << i << ": " << counters[i] << endl; 216 | if(counters[i] > 10) { 217 | gettimeofday(&begin, NULL); 218 | findPlanef(lDisps[i], wCoords[i], hCoords[i], counters[i], 219 | height, surfaces[i],100,0.0); 220 | gettimeofday(&end, NULL); 221 | //cout << " findTablePlane: " << 1000*(end.tv_sec-begin.tv_sec) + (end.tv_usec-begin.tv_usec)/1000 << " ms" << endl; 222 | } else { 223 | surfaces[i].alpha = 0; 224 | surfaces[i].beta = 0; 225 | surfaces[i].disp = 0; 226 | } 227 | } 228 | 229 | 230 | for(int i=0; inrSPixels; ++i) { 231 | delete [] lDisps[i]; 232 | delete [] wCoords[i]; 233 | delete [] hCoords[i]; 234 | } 235 | delete [] counters; 236 | delete [] maxval; 237 | 238 | } 239 | 240 | /* 241 | void PlaneEstimate::findPlane(float* pDisps, int* wCoords, int* hCoords, int pNoPoints, int height, sSurface& surface, int randIter = 1000) { 242 | 243 | const int drange = 64; 244 | float minbeta = 0.0; 245 | 246 | int *hist = new int[height*drange]; 247 | int *totals = new int[height]; 248 | int *validh = new int[height]; 249 | 250 | int counter = 0; 251 | int h; 252 | float d; 253 | // Search through all points 254 | for(int i=0; i1;k--) 272 | histy[k] = histy[k] + 2*histy[k-1] + histy[k-2]; 273 | totals[counter] = 0; 274 | for (int k=0;k=drange) 309 | continue; 310 | float er = d - (dgra*validh[y] + dzer); 311 | sumwei += hist[y*drange + d] / (4.0f + er*er); 312 | } 313 | } 314 | if (sumwei>maxwei && dgra>minbeta) { 315 | maxwei = sumwei; 316 | beta = dgra; 317 | disp = dzer; 318 | } 319 | } 320 | 321 | // Improve line (depends only on y) using m-estimator 322 | for (int l=0;l<3;l++) { 323 | float syy = 0.0, sy1 = 0.0f, s11 = 0.0f; 324 | float sdy = 0.0, sd1 = 0.0f; 325 | for (int yt=0;yt=drange) 330 | continue; 331 | float er = d - (beta*y + disp); 332 | float w = hist[yt*drange + d] / (4.0f + er*er); 333 | syy += w*y*y; 334 | sy1 += w*y; 335 | s11 += w; 336 | sdy += w*d*y; 337 | sd1 += w*d; 338 | } 339 | } 340 | float det = syy*s11 - sy1*sy1; 341 | beta = s11*sdy - sy1*sd1; 342 | disp = syy*sd1 - sy1*sdy; 343 | if (det!=0.0f) { 344 | beta /= det; 345 | disp /= det; 346 | } 347 | } 348 | disp += 0.5f; 349 | 350 | // Improve plane (depends on both x and y) using m-estimator 351 | for (int l=0;l<3;l++) { 352 | float sxx = 0.0, sx1 = 0.0f, s11 = 0.0f; 353 | float sdx = 0.0, sd1 = 0.0f; 354 | 355 | for(int i=0; i=0.0f) { 364 | float d = pd - beta*y; 365 | float er = d - (alpha*x + disp); 366 | float w = 1.0f / (1.0f + er*er); 367 | sxx += w*x*x; 368 | sx1 += w*x; 369 | s11 += w; 370 | sdx += w*d*x; 371 | sd1 += w*d; 372 | } 373 | //} 374 | } 375 | float det = sxx*s11 - sx1*sx1; 376 | alpha = s11*sdx - sx1*sd1; 377 | disp = sxx*sd1 - sx1*sdx; 378 | if (det!=0.0f) { 379 | alpha /= det; 380 | disp /= det; 381 | } 382 | } 383 | 384 | // Compute variance of d 385 | int num = 0; 386 | float vard = 0.0f; 387 | for (int i=0; i=0.0f && d= 1) 427 | lDisps[i] = drange-1; 428 | else 429 | lDisps[i] = (int)floor(pDisps[i]*drange); 430 | } 431 | 432 | int *hist = new int[height*drange]; 433 | int *totals = new int[height]; 434 | int *validh = new int[height]; 435 | 436 | int counter = 0; 437 | int h; 438 | float d; 439 | // Search through all points 440 | for(int i=0; i1;k--) 457 | histy[k] = histy[k] + 2*histy[k-1] + histy[k-2]; 458 | totals[counter] = 0; 459 | for (int k=0;k=drange) 495 | continue; 496 | float er = d - (dgra*validh[y] + dzer); 497 | sumwei += hist[y*drange + d] / (4.0f + er*er); 498 | } 499 | } 500 | if (sumwei>maxwei && (dgra/drange>minbeta || minbeta == 0)) { 501 | maxwei = sumwei; 502 | beta = dgra; 503 | disp = dzer; 504 | } 505 | } 506 | 507 | //std::cout << "first beta: " << beta << endl; 508 | 509 | // Improve line (depends only on y) using m-estimator 510 | for (int l=0;l<3;l++) { 511 | float syy = 0.0, sy1 = 0.0f, s11 = 0.0f; 512 | float sdy = 0.0, sd1 = 0.0f; 513 | for (int yt=0;yt=drange) 518 | continue; 519 | float er = d - (beta*y + disp); 520 | float w = hist[yt*drange + d] / (4.0f + er*er); 521 | syy += w*y*y; 522 | sy1 += w*y; 523 | s11 += w; 524 | sdy += w*d*y; 525 | sd1 += w*d; 526 | } 527 | } 528 | float det = syy*s11 - sy1*sy1; 529 | beta = s11*sdy - sy1*sd1; 530 | disp = syy*sd1 - sy1*sdy; 531 | if (det!=0.0f) { 532 | beta /= det; 533 | disp /= det; 534 | } 535 | } 536 | disp += 0.5f; 537 | 538 | // Improve plane (depends on both x and y) using m-estimator 539 | for (int l=0;l<3;l++) { 540 | float sxx = 0.0, sx1 = 0.0f, s11 = 0.0f; 541 | float sdx = 0.0, sd1 = 0.0f; 542 | 543 | for(int i=0; i=0.0f) { 552 | float d = pd - beta*y; 553 | float er = d - (alpha*x + disp); 554 | float w = 1.0f / (1.0f + er*er); 555 | sxx += w*x*x; 556 | sx1 += w*x; 557 | s11 += w; 558 | sdx += w*d*x; 559 | sd1 += w*d; 560 | } 561 | //} 562 | } 563 | float det = sxx*s11 - sx1*sx1; 564 | alpha = s11*sdx - sx1*sd1; 565 | disp = sxx*sd1 - sx1*sdx; 566 | if (det!=0.0f) { 567 | alpha /= det; 568 | disp /= det; 569 | } 570 | } 571 | 572 | // Compute variance of d 573 | int num = 0; 574 | float vard = 0.0f; 575 | for (int i=0; i=0.0f && dwidth; 618 | int height = pImg->height; 619 | 620 | int drange = 64; 621 | float *dimd = new float[width*height]; 622 | float minbeta = 0.08; 623 | 624 | // Find dominating disparity for each y-value 625 | int *hist = new int[height*drange]; 626 | int *totals = new int[height]; 627 | for (int y=0;y=0 && d1;i--) 641 | histy[i] = histy[i] + 2*histy[i-1] + histy[i-2]; 642 | totals[y] = 0; 643 | for (int i=0;i=drange) 674 | continue; 675 | float er = d - (dgra*y + dzer); 676 | sumwei += hist[y*drange + d] / (4.0f + er*er); 677 | } 678 | } 679 | if (sumwei>maxwei && dgra>minbeta) { 680 | maxwei = sumwei; 681 | beta = dgra; 682 | disp = dzer; 683 | } 684 | } 685 | // Improve line (depends only on y) using m-estimator 686 | for (int l=0;l<3;l++) { 687 | float syy = 0.0, sy1 = 0.0f, s11 = 0.0f; 688 | float sdy = 0.0, sd1 = 0.0f; 689 | for (int y=0;y=drange) 693 | continue; 694 | float er = d - (beta*y + disp); 695 | float w = hist[y*drange + d] / (4.0f + er*er); 696 | syy += w*y*y; 697 | sy1 += w*y; 698 | s11 += w; 699 | sdy += w*d*y; 700 | sd1 += w*d; 701 | } 702 | } 703 | float det = syy*s11 - sy1*sy1; 704 | beta = s11*sdy - sy1*sd1; 705 | disp = syy*sd1 - sy1*sdy; 706 | if (det!=0.0f) { 707 | beta /= det; 708 | disp /= det; 709 | } 710 | } 711 | disp += 0.5f; 712 | // Improve plane (depends on both x and y) using m-estimator 713 | for (int l=0;l<3;l++) { 714 | float sxx = 0.0, sx1 = 0.0f, s11 = 0.0f; 715 | float sdx = 0.0, sd1 = 0.0f; 716 | for (int y=0;y=0.0f) { 719 | float d = dimd[y*width+x] - beta*y; 720 | float er = d - (alpha*x + disp); 721 | float w = 1.0f / (1.0f + er*er); 722 | sxx += w*x*x; 723 | sx1 += w*x; 724 | s11 += w; 725 | sdx += w*d*x; 726 | sd1 += w*d; 727 | } 728 | } 729 | } 730 | float det = sxx*s11 - sx1*sx1; 731 | alpha = s11*sdx - sx1*sd1; 732 | disp = sxx*sd1 - sx1*sdx; 733 | if (det!=0.0f) { 734 | alpha /= det; 735 | disp /= det; 736 | } 737 | } 738 | int num = 0; 739 | float vard = 0.0f; 740 | for (int y=0;y=0.0f && d 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | #include "unistd.h" 36 | //FX:#include "Fixations.h" 37 | #include "Color.h" 38 | #include "myTypes.h" 39 | #include "myTypes_sp.h" 40 | //#include "tictoc.h" 41 | //FX:#include 42 | //#include 43 | 44 | using namespace std; 45 | 46 | namespace Saliency { 47 | 48 | #define SYMTYPE_ISOTROPIC 1 49 | #define SYMTYPE_RADIAL 2 50 | 51 | #define SYMSOURCE_BRIGHTNESSGRADIENT 1 52 | #define SYMSOURCE_COLORGRADIENT 2 53 | #define SYMSOURCE_BRIGHTNESS 3 54 | 55 | #define SYMPERIOD_PI 1 56 | #define SYMPERIOD_2PI 2 57 | 58 | //! Struct containing OpenCL information 59 | struct sCLEnv { 60 | 61 | //FX: cl_program program[1]; 62 | //FX: cl_kernel kernel[7]; 63 | 64 | //FX: cl_command_queue cmd_queue; 65 | //FX: cl_context context; 66 | 67 | size_t buffer_size; 68 | size_t* global_worksize; 69 | size_t* local_worksize; 70 | }; 71 | 72 | //! Struct containing the parameters for the symmetry-saliency method 73 | struct SymParams { 74 | int *scales; //!< Int array of size nrScales containing the scales that need to be calculated relative to the first scale 75 | int *userScales; //!< Int array of size nrScales containing the absolute scales that need to be calculated (relative to input image) 76 | int nrScales; //!< Number of scales 77 | int r1; //!< 'Radius' of the inner square of the symmetry kernel. Pixels within this square are not used for the symmetry calculation 78 | int r2; //!< 'Radius' of the outer square of the symmetry kernel. Pixels out side the inner and inside the outer square are used 79 | float s; //!< The sigma of the Gaussian weighting function on the distance between the pixels in a pixel pair 80 | int symmetryType; //!< Type of symmetry calculation (SYMTYPE_ISOTROPIC or SYMTYPE_RADIAL) 81 | int symmetrySource; //!< Information used by the symmetry calculation (SYMSOURCE_BRIGHTNESSGRADIENT, SYMSOURCE_COLORGRADIENT or SYMSOURCE_BRIGHTNESS). 82 | //!< SYMSOURCE_BRIGHTNESSGRADIENT works best, SYMSOURCE_COLORGRADIENT has not yet been implemented, and SYMSOURCE_BRIGHTNESS needs 83 | //!< to be further developed. 84 | int symmetryPeriod; //!< The period of the symmetry function (SYMPERIOD_PI or SYMPERIOD_2PI). The later is preferred. 85 | bool calcStrongestRadius; //!< Boolean to indicate whether the strongest contributing radii per pixel need to be calculated. Needed to get the proto-objects 86 | int seedR; //!< The 'squared radius' of the area to find local maxima. Used only when proto-objects are calculated 87 | float seedT; //!< Threshold on the seeds of the proto-objects (= local maxima in the saliency map) 88 | float roiT; //!< Threshold on the region growing of proto-object base. Is relative to the seed. 89 | bool objThresholdAbsolute;//!< Boolean to indicate whether seedT is relative to the maximum saliency value, or an absolute threshold 90 | }; 91 | 92 | //! Struct containing info of a symmetry pixel pair 93 | struct SymPair { 94 | float a0, a1; 95 | float symV; 96 | }; 97 | 98 | //! Struct for a point in 2D 99 | struct Point2D { 100 | int x; 101 | int y; 102 | }; 103 | 104 | //! Struct for an object point, position, radius, saliency value, and label 105 | struct ObjectPoint { 106 | int x; 107 | int y; 108 | float r; 109 | float v; 110 | int label; 111 | }; 112 | 113 | //! Struct for a link between two labels 114 | struct LabelLink{ 115 | int labelA; 116 | int labelB; 117 | }; 118 | 119 | //! Class containing the map with the maximum contributing radii 120 | class RadMap { 121 | public: 122 | ~RadMap() { delete[] radiusMap; delete[] valueMap; }; 123 | float *radiusMap; 124 | float *valueMap; 125 | int scale; // Relative to first scale 126 | int userScale; 127 | int width; 128 | int height; 129 | }; 130 | 131 | 132 | //! Class to calculate the symmetry-saliency of an image and select fixation points from the saliency map 133 | class Symmetry { 134 | public: 135 | Symmetry(); 136 | ~Symmetry(); 137 | void setParameters(SymParams symParams); 138 | 139 | void calcSaliencyMap(IplImage *img, int showScaleMaps = 1); 140 | Map *getSymmetryMap(); 141 | IplImage *getSymmetryImage(); 142 | vectorgetObjectMap(); 143 | int getScale(); 144 | 145 | int debug; 146 | 147 | private: 148 | 149 | void calcSaliencyMapCPU(IplImage *img, int showScaleMaps = 1); 150 | void calcSaliencyMapCL(IplImage *img); 151 | 152 | // OpenCL 153 | void cl_init(sCLEnv& clEnv); 154 | char* cl_load_program_source(const char *filename); 155 | //void cl_gray(cl_mem rgbimg, cl_mem grayimg, sCLEnv& clEnv); 156 | 157 | void setImage(IplImage *_image); 158 | float getPatchSymmetry(float *angles, float *magnitudes, float *brightness, int x, int y); 159 | float getPatchSymmetry(float *angles, float *magnitudes, float *brightness, int x, int y, float &strongestRadius, float &strongestValue); 160 | float getPixelSymmetryGradient(float *angles, float *magnitudes, int x0, int y0, int x1, int x2, int d); 161 | float getPixelSymmetryBrightness(float *angles, float *magnitudes, float *brightness, int x0, int y0, int x1, int x2, int d); 162 | int normMap0to1(float* salMap); 163 | void normalizeMap(float* salMap); 164 | void addMapScale(float* sumMap, float* map); 165 | void multiplyMap(float *map, double val); 166 | IplImage *getMapImage(float *map); 167 | void showScaleMap(float *map, int width, int height, int sc); 168 | float cosFn(float x); 169 | float sinFn(float x); 170 | float logFn(float x); 171 | void clearRadiusMaps(); 172 | bool localMaximum(float value, float *symMap, int x, int y, int width, int height); 173 | int toI(int x, int y, int width) { return y*width + x; }; 174 | void sortOutLabels(vector &seeds, int width, int height, vector &labelLinks, int &nrLabels); 175 | void addRowLabels(bool **linkTable, uchar label, int nrLabels, vector &group, bool *added); 176 | 177 | int width, height; 178 | int widthOriginal, heightOriginal; //!< The original size of the image provided to calcSaliencyMap or calcSaliencyMapCL 179 | int widthSymMap, heightSymMap; //!< The size of the symmetry-saliency map. This is the first scale of the image pyramid used. 180 | int patchR1, patchR2; 181 | float sigma; 182 | float *distanceWeight; 183 | float **pixelAngles; 184 | int cosArSize; 185 | float *cosAr; 186 | int sinArSize; 187 | float *sinAr; 188 | int logArSize; 189 | float *logAr; 190 | int *scales; 191 | int *userScales; 192 | int nrScales; 193 | int symmetryType; 194 | int symmetrySource; 195 | int symmetryPeriod; 196 | bool calcStrongestRadius; 197 | int seedR; 198 | bool objThresholdAbsolute; 199 | float seedT; 200 | float roiT; 201 | 202 | IplImage *brightnessIpl; 203 | float *brightness; 204 | float *symMap ; 205 | 206 | Color *color; 207 | 208 | vector strongestRadiusMaps; 209 | 210 | sCLEnv clEnv; 211 | 212 | IplImage *img; 213 | }; 214 | 215 | } 216 | 217 | #endif 218 | -------------------------------------------------------------------------------- /myself_symmetry/additional.cpp: -------------------------------------------------------------------------------- 1 | 2 | long int rint(double x) 3 | { 4 | if ( int(x) == x ) 5 | return (long)( x ); 6 | else 7 | return (long)(x + 1); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /myself_symmetry/additional.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | //FX define 4 | #define M_PI 3.14159265358979323846 5 | 6 | long int rint(double x); -------------------------------------------------------------------------------- /myself_symmetry/main.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DUTFangXiang/SymmetryDetection/80d25c326d57dc037430b4d99fc31f1755adc0e3/myself_symmetry/main.cpp -------------------------------------------------------------------------------- /myself_symmetry/myTypes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FAST AND AUTOMATIC DETECTION AND SEGMENTATION OF UNKNOWN OBJECTS (ADAS) 3 | * 4 | * Author: Gert Kootstra, Niklas Bergstrom 5 | * Email: gertkootstra@gmail.com 6 | * Website: http://www.csc.kth.se/~kootstra/ 7 | * Date: 22 Jul 2010 8 | * 9 | * Copyright (C) 2010, Gert Kootstra 10 | * 11 | * See README.txt and the html directory for documentation 12 | * and terms. 13 | */ 14 | 15 | #ifndef MYTYPES_H 16 | #define MYTYPES_H 17 | 18 | #include 19 | #include 20 | 21 | namespace Saliency { 22 | //! Class to store the saliency map and additional information 23 | class Map { 24 | public: 25 | Map() { map=NULL; }; 26 | ~Map() { }; //if(map) delete[] map; }; // Not, because it is part of the Symmetry etc classes 27 | float *map; //!< Pointer to the symmetry map 28 | int width; //!< Width of the symmetry map 29 | int height; //!< Height of the symmetry map 30 | int widthOriginal; //!< Width of the original input image 31 | int heightOriginal; //!< Height of the original input image 32 | float sizeRatio; //!< original size to symmetry-map size ratio 33 | float scale; //!< Scale of the symmetry map 34 | }; 35 | 36 | //! Class to store proto-object maps and additional information. \b NB. Currently not used for the super-pixel segmentation. 37 | class ObjectMap { 38 | public: 39 | ObjectMap() { map=NULL; descriptor=NULL;}; 40 | ~ObjectMap() { if(map) delete[] map; if(descriptor) delete[] descriptor; }; 41 | uchar *map; 42 | float *descriptor; 43 | int width, height; 44 | int x0, y0, x1, y1; 45 | float x, y; 46 | int x0sc, y0sc, x1sc, y1sc; 47 | float xsc, ysc; 48 | float scale; 49 | }; 50 | 51 | //! Struct to store position and saliency information if a fixation point 52 | struct Fixation { 53 | int x, y; 54 | float sal; 55 | }; 56 | 57 | //! Struct to store the position and size of a bounding box 58 | struct SalRect { 59 | int l,r,t,b; 60 | float x,y; 61 | }; 62 | 63 | //! Struct for the position of a pixel 64 | struct Pixel{ 65 | float x; 66 | float y; 67 | }; 68 | 69 | 70 | //! Struct containing information about the fixation point. 71 | struct SaliencyPeak { 72 | float x; //!< X-position in the image scale 73 | float y; //!< Y-position in the image scale 74 | float xSc; //!< X-position in the map scale 75 | float ySc; //!< Y-position in the map scale 76 | float sal; //!< Peak saliency value 77 | float salNorm; //!< Peak saliency value, normalized to maximum peak 78 | }; 79 | 80 | } 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /myself_symmetry/myTypes2.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FAST AND AUTOMATIC DETECTION AND SEGMENTATION OF UNKNOWN OBJECTS (ADAS) 3 | * 4 | * Author: Gert Kootstra, Niklas Bergstrom 5 | * Email: gertkootstra@gmail.com 6 | * Website: http://www.csc.kth.se/~kootstra/ 7 | * Date: 22 Jul 2010 8 | * 9 | * Copyright (C) 2010, Gert Kootstra 10 | * 11 | * See README.txt and the html directory for documentation 12 | * and terms. 13 | */ 14 | 15 | #ifndef MYTYPES2_H 16 | #define MYTYPES2_H 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | using namespace std; 24 | 25 | //! Struct containing a vector of ints, which are the ids of pixels 26 | struct Pixels { 27 | vector pixels; 28 | }; 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /myself_symmetry/myTypes_sp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FAST AND AUTOMATIC DETECTION AND SEGMENTATION OF UNKNOWN OBJECTS (ADAS) 3 | * 4 | * Author: Gert Kootstra, Niklas Bergstrom 5 | * Email: gertkootstra@gmail.com 6 | * Website: http://www.csc.kth.se/~kootstra/ 7 | * Date: 22 Jul 2010 8 | * 9 | * Copyright (C) 2010, Gert Kootstra 10 | * 11 | * See README.txt and the html directory for documentation 12 | * and terms. 13 | */ 14 | 15 | #ifndef MYTYPES_SP_H 16 | #define MYTYPES_SP_H 17 | 18 | #include "myTypes2.h" 19 | #include "ColorHistogram.h" 20 | #include "DispHistogram.h" 21 | //#include "SuperPixels.h" 22 | 23 | class SuperPixels; 24 | 25 | //! Struct for the position of a pixel 26 | struct Pixel { 27 | int x,y; 28 | }; 29 | 30 | //! Struct storing surface-plane information 31 | struct sSurface { 32 | float alpha; 33 | float beta; 34 | float disp; 35 | float spread_d; 36 | }; 37 | 38 | //! Struct storing the link between two labels 39 | struct LabelLink{ 40 | int labelA; 41 | int labelB; 42 | }; 43 | 44 | //! Class containing information about a super pixel 45 | class SPInfo { 46 | public: 47 | SPInfo() {neighbors=NULL; neighborsIDs=NULL; colorHist=NULL; colorProb=NULL; dispHist=NULL; dispProb=NULL;}; 48 | ~SPInfo() { 49 | if(neighbors) 50 | delete[] neighbors; 51 | if(neighborsIDs) 52 | delete[] neighborsIDs; 53 | if(colorHist) 54 | delete colorHist; 55 | if(dispHist) 56 | delete dispHist; 57 | if(colorProb) 58 | delete[] colorProb; 59 | if(dispProb) 60 | delete[] dispProb; 61 | }; 62 | void copy(SPInfo &spInfo) { 63 | label = 0;//segmInfo.label; 64 | neighbors = NULL; 65 | nrNeighbors = 0; 66 | //nrNeighbors = segmInfo.nrNeighbors; 67 | //neighbors = new int[nrNeighbors]; 68 | //for(unsigned int i=0; i group; 104 | }; 105 | 106 | //! Struct containing top-down information of fore- or background for segmentation. 107 | struct TDInfo { 108 | ColorHistogram *colorHist; //!< Color histogram 109 | DispHistogram *dispHist; //!< Disparity histogram. \b NB. Not used in segmentation 110 | float *colorProb; //!< Float array of size nrSPixles with probabilities of being similar to all super-pixels based on color histograms 111 | float *dispProb; //!< Float array of size nrSPixles with probabilities of being similar to all super-pixels based on disparity histograms 112 | float dispMean, dispVar; //!< Mean and variance of disparities in the fore-/background 113 | float *dispProbFGauss; //!< Float array of size nrSPixles with probabilities of being similar to all super-pixels based on disparity using Gaussian distribution 114 | }; 115 | 116 | //! Class containing information for the graph-cut segmentation 117 | class GraphCutInfo { 118 | public: 119 | GraphCutInfo() { 120 | fgInfo = new TDInfo(); 121 | bgInfo = new TDInfo(); 122 | }; 123 | ~GraphCutInfo() { 124 | delete fgInfo; 125 | delete bgInfo; 126 | }; 127 | SuperPixels *superPixels; //!< Pointer to the super pixels 128 | TDInfo *fgInfo; //!< Pointer to information about the foreground 129 | TDInfo *bgInfo; //!< Pointer to information about the background 130 | float *nonPlaneProb; //!< Float array of size nrSPixels containing the probabilities of all super pixels to \em not be part of the dominant plane 131 | int selectedFG; //!< The selected foreground super pixel by the attention model 132 | }; 133 | 134 | //! Struct containing the position of a point in interger values 135 | struct Point { 136 | int x, y; 137 | }; 138 | 139 | //! Struct containing the position of a point in float values 140 | struct PointF{ 141 | float x, y; 142 | }; 143 | 144 | 145 | #endif 146 | -------------------------------------------------------------------------------- /myself_symmetry/myself_symmetry.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {9C2DE40C-59E8-4902-A48A-8263E2E3CE3D} 15 | Win32Proj 16 | myself_symmetry 17 | 18 | 19 | 20 | Application 21 | true 22 | Unicode 23 | 24 | 25 | Application 26 | false 27 | true 28 | Unicode 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | true 43 | 44 | 45 | false 46 | 47 | 48 | 49 | 50 | 51 | Level3 52 | Disabled 53 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 54 | 55 | 56 | Console 57 | true 58 | 59 | 60 | 61 | 62 | Level3 63 | 64 | 65 | MaxSpeed 66 | true 67 | true 68 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 69 | 70 | 71 | Console 72 | true 73 | true 74 | true 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | -------------------------------------------------------------------------------- /myself_symmetry/myself_symmetry.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Source Files 29 | 30 | 31 | Source Files 32 | 33 | 34 | Source Files 35 | 36 | 37 | Source Files 38 | 39 | 40 | 41 | 42 | Header Files 43 | 44 | 45 | Header Files 46 | 47 | 48 | Header Files 49 | 50 | 51 | Header Files 52 | 53 | 54 | Header Files 55 | 56 | 57 | Header Files 58 | 59 | 60 | Header Files 61 | 62 | 63 | Header Files 64 | 65 | 66 | Header Files 67 | 68 | 69 | Header Files 70 | 71 | 72 | -------------------------------------------------------------------------------- /myself_symmetry/myself_symmetry.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | -------------------------------------------------------------------------------- /myself_symmetry/unistd.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef _UNISTD_H 4 | #define _UNISTD_H 5 | 6 | #include 7 | #include 8 | 9 | #endif --------------------------------------------------------------------------------