├── .gitignore ├── .travis.yml ├── CMakeLists.txt ├── Dockerfile ├── LICENSE ├── README.md ├── data ├── opensr.gif ├── opensse.gif ├── view │ ├── 0.xf │ ├── 1.xf │ ├── 10.xf │ ├── 100.xf │ ├── 101.xf │ ├── 11.xf │ ├── 12.xf │ ├── 13.xf │ ├── 14.xf │ ├── 15.xf │ ├── 16.xf │ ├── 17.xf │ ├── 18.xf │ ├── 19.xf │ ├── 2.xf │ ├── 20.xf │ ├── 21.xf │ ├── 22.xf │ ├── 23.xf │ ├── 24.xf │ ├── 25.xf │ ├── 26.xf │ ├── 27.xf │ ├── 28.xf │ ├── 29.xf │ ├── 3.xf │ ├── 30.xf │ ├── 31.xf │ ├── 32.xf │ ├── 33.xf │ ├── 34.xf │ ├── 35.xf │ ├── 36.xf │ ├── 37.xf │ ├── 38.xf │ ├── 39.xf │ ├── 4.xf │ ├── 40.xf │ ├── 41.xf │ ├── 42.xf │ ├── 43.xf │ ├── 44.xf │ ├── 45.xf │ ├── 46.xf │ ├── 47.xf │ ├── 48.xf │ ├── 49.xf │ ├── 5.xf │ ├── 50.xf │ ├── 51.xf │ ├── 52.xf │ ├── 53.xf │ ├── 54.xf │ ├── 55.xf │ ├── 56.xf │ ├── 57.xf │ ├── 58.xf │ ├── 59.xf │ ├── 6.xf │ ├── 60.xf │ ├── 61.xf │ ├── 62.xf │ ├── 63.xf │ ├── 64.xf │ ├── 65.xf │ ├── 66.xf │ ├── 67.xf │ ├── 68.xf │ ├── 69.xf │ ├── 7.xf │ ├── 70.xf │ ├── 71.xf │ ├── 72.xf │ ├── 73.xf │ ├── 74.xf │ ├── 75.xf │ ├── 76.xf │ ├── 77.xf │ ├── 78.xf │ ├── 79.xf │ ├── 8.xf │ ├── 80.xf │ ├── 81.xf │ ├── 82.xf │ ├── 83.xf │ ├── 84.xf │ ├── 85.xf │ ├── 86.xf │ ├── 87.xf │ ├── 88.xf │ ├── 89.xf │ ├── 9.xf │ ├── 90.xf │ ├── 91.xf │ ├── 92.xf │ ├── 93.xf │ ├── 94.xf │ ├── 95.xf │ ├── 96.xf │ ├── 97.xf │ ├── 98.xf │ └── 99.xf ├── vocabulary └── zddhub.png ├── gui └── SketchSearchDemo │ ├── SketchSearchDemo.pro │ ├── config.json │ ├── main.cpp │ ├── mainwindow.cpp │ ├── mainwindow.h │ ├── resultphotowidget.cpp │ ├── resultphotowidget.h │ ├── searchengine.h │ ├── sketcharea.cpp │ ├── sketcharea.h │ ├── sketchsearcher.cpp │ ├── sketchsearcher.h │ ├── trimeshview │ ├── include │ │ ├── Color.h │ │ ├── GLCamera.h │ │ ├── KDtree.h │ │ ├── Vec.h │ │ ├── XForm.h │ │ ├── bsphere.h │ │ ├── lineqn.h │ │ ├── mempool.h │ │ ├── strutil.h │ │ ├── timestamp.h │ │ └── trianglemesh.h │ ├── trianglemesh │ │ ├── GLCamera.cpp │ │ ├── KDtree.cpp │ │ ├── trianglemesh_bounding.cpp │ │ ├── trianglemesh_connectivity.cpp │ │ ├── trianglemesh_curvature.cpp │ │ ├── trianglemesh_io.cpp │ │ ├── trianglemesh_normals.cpp │ │ ├── trianglemesh_pointareas.cpp │ │ ├── trianglemesh_stats.cpp │ │ └── trianglemesh_tstrips.cpp │ ├── trimeshview.cpp │ ├── trimeshview.h │ ├── trimeshview.pri │ ├── trimeshview_draw_apparent_ridges.cpp │ ├── trimeshview_draw_base.cpp │ ├── trimeshview_draw_lines.cpp │ └── trimeshview_draw_ridges_and_valleys.cpp │ └── view │ ├── 0.xf │ ├── 1.xf │ ├── 10.xf │ ├── 100.xf │ ├── 101.xf │ ├── 11.xf │ ├── 12.xf │ ├── 13.xf │ ├── 14.xf │ ├── 15.xf │ ├── 16.xf │ ├── 17.xf │ ├── 18.xf │ ├── 19.xf │ ├── 2.xf │ ├── 20.xf │ ├── 21.xf │ ├── 22.xf │ ├── 23.xf │ ├── 24.xf │ ├── 25.xf │ ├── 26.xf │ ├── 27.xf │ ├── 28.xf │ ├── 29.xf │ ├── 3.xf │ ├── 30.xf │ ├── 31.xf │ ├── 32.xf │ ├── 33.xf │ ├── 34.xf │ ├── 35.xf │ ├── 36.xf │ ├── 37.xf │ ├── 38.xf │ ├── 39.xf │ ├── 4.xf │ ├── 40.xf │ ├── 41.xf │ ├── 42.xf │ ├── 43.xf │ ├── 44.xf │ ├── 45.xf │ ├── 46.xf │ ├── 47.xf │ ├── 48.xf │ ├── 49.xf │ ├── 5.xf │ ├── 50.xf │ ├── 51.xf │ ├── 52.xf │ ├── 53.xf │ ├── 54.xf │ ├── 55.xf │ ├── 56.xf │ ├── 57.xf │ ├── 58.xf │ ├── 59.xf │ ├── 6.xf │ ├── 60.xf │ ├── 61.xf │ ├── 62.xf │ ├── 63.xf │ ├── 64.xf │ ├── 65.xf │ ├── 66.xf │ ├── 67.xf │ ├── 68.xf │ ├── 69.xf │ ├── 7.xf │ ├── 70.xf │ ├── 71.xf │ ├── 72.xf │ ├── 73.xf │ ├── 74.xf │ ├── 75.xf │ ├── 76.xf │ ├── 77.xf │ ├── 78.xf │ ├── 79.xf │ ├── 8.xf │ ├── 80.xf │ ├── 81.xf │ ├── 82.xf │ ├── 83.xf │ ├── 84.xf │ ├── 85.xf │ ├── 86.xf │ ├── 87.xf │ ├── 88.xf │ ├── 89.xf │ ├── 9.xf │ ├── 90.xf │ ├── 91.xf │ ├── 92.xf │ ├── 93.xf │ ├── 94.xf │ ├── 95.xf │ ├── 96.xf │ ├── 97.xf │ ├── 98.xf │ └── 99.xf ├── opensse.h ├── opensse.pri ├── opensse.pro ├── sse ├── CMakeLists.txt ├── common │ ├── distance.h │ └── types.h ├── features │ ├── detector.cpp │ ├── detector.h │ ├── feature.h │ ├── galif.cpp │ ├── galif.h │ ├── generator.cpp │ ├── generator.h │ ├── util.cpp │ └── util.h ├── index │ ├── invertedindex.cpp │ ├── invertedindex.h │ ├── tfidf.cpp │ └── tfidf.h ├── io │ ├── filelist.cpp │ ├── filelist.h │ ├── json_parser.cpp │ ├── json_parser.h │ ├── reader_writer.cpp │ └── reader_writer.h ├── opensse.h ├── quantize │ ├── quantizer.cpp │ └── quantizer.h └── vocabulary │ ├── kmeans.h │ └── kmeans_init.h └── tools ├── CMakeLists.txt ├── add_license.sh ├── extract.cpp ├── extract_and_quantize.cpp ├── filelist ├── generate_filelist.py ├── generate_filelist.rb ├── index.cpp ├── quantize.cpp ├── search.cpp ├── sse └── vocabulary.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | # C++ objects and libs 2 | *.slo 3 | *.lo 4 | *.o 5 | *.a 6 | *.la 7 | *.lai 8 | *.so 9 | *.dll 10 | *.dylib 11 | bin 12 | 13 | # Qt-es 14 | 15 | *.pro.user 16 | *.pro.user.* 17 | moc_*.cpp 18 | qrc_*.cpp 19 | Makefile 20 | *-build-* 21 | release 22 | bin 23 | 24 | # Mac osx 25 | *.DS_Store 26 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # https://travis-ci.org 2 | 3 | language: cpp 4 | 5 | install: 6 | - sudo add-apt-repository --yes ppa:ubuntu-sdk-team/ppa 7 | - sudo add-apt-repository --yes ppa:lttng/daily 8 | - sudo add-apt-repository ppa:lkoppel/opencv -y # opencv3 ppa 9 | - sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y 10 | - sudo apt-get update -qq 11 | - sudo apt-get install -qq libopencv-dev 12 | - sudo apt-get install g++-4.8 -y 13 | - export CXX="g++-4.8" 14 | script: 15 | - mkdir release && cd release 16 | - cmake .. 17 | - make 18 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(opensse) 2 | 3 | cmake_minimum_required(VERSION 2.8) 4 | 5 | if(POLICY CMP0042) 6 | cmake_policy(SET CMP0042 NEW) 7 | endif() 8 | 9 | set(HAVE_LIBPTHREAD YES) 10 | 11 | add_definitions(-std=c++11) 12 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread") 13 | 14 | include_directories(/usr/local/include) 15 | include_directories(..) 16 | include_directories(${PROJECT_SOURCE_DIR}/sse) 17 | 18 | link_directories(/usr/local/lib) 19 | set(REQUIRED_LIB opencv_core opencv_imgproc opencv_imgcodecs opencv_highgui opencv_features2d opencv_ml) 20 | 21 | add_subdirectory(sse) 22 | 23 | add_subdirectory(tools) -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # How to use 2 | # docker build -t opensse . 3 | # docker run -it opensse /bin/bash 4 | 5 | FROM zddhub/opencv:3.2.0 6 | MAINTAINER zdd 7 | 8 | RUN apt-get update \ 9 | && apt-get install g++ -y \ 10 | && apt-get install cmake -y 11 | 12 | RUN mkdir opensse 13 | COPY . opensse 14 | 15 | RUN cd opensse \ 16 | && mkdir dist && cd dist \ 17 | && cmake .. \ 18 | && make \ 19 | && make install \ 20 | && ldconfig 21 | 22 | CMD [ "sse" ] -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | OpenSSE: Open Sketch Search Engine [![Build Status](https://travis-ci.org/zddhub/opensse.svg?branch=master)](https://travis-ci.org/zddhub/opensse) 2 | ================================== 3 | 4 | [![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/zddhub/opensse?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 5 | 6 | Hello everybody! 7 | 8 | I'm very interested in [Mathias Eitz's works](http://cybertron.cg.tu-berlin.de/eitz/projects/sbsr/) on SIGGRAPH 2012, so I developed OpenSSE, Just for fun. 9 | 10 | This is an open source sketch search engine for 3D object retrieval based on sketch image as input. In fact, it can retrieve more, such as images, videos, point cloud models and volume models, you just need get their line drawing images than I know you can. 11 | 12 | In order to clearly show how to work, I used single thread and ascii encoding for file storage. 13 | 14 | Zhang Dongdong 15 | 16 | 17 | Demo powered by OpenSSE 18 | ======================= 19 | 20 | * [Open Sketch Search](https://www.opensse.com/) 21 | 22 | This demo deals with 3D mesh models. See more search results, click [demo videos](https://www.opensse.com/). 23 | 24 | [![Sketch search demo](data/opensse.gif "Sketch search demo")](https://www.opensse.com/) 25 | 26 | * [Open Sketch Recognize](https://sr.opensse.com/) 27 | 28 | Recognize input sketch image, you can try it via [web version](http://online.opensse.com/). See more search results, click [demo videos](https://sr.opensse.com/). 29 | 30 | [![Sketch recognize demo](data/opensr.gif "Sketch recognize demo")](https://sr.opensse.com/) 31 | 32 | 33 | Interesting demo 34 | ================ 35 | 36 | *Note:* The below demos are **NOT** powered by OpenSSE, but I think they share the same field. And also I am very interested in them, so list here: 37 | 38 | - [AutoDraw](https://www.autodraw.com/) 39 | - [QuickDraw](https://quickdraw.withgoogle.com/) 40 | 41 | 42 | How to install 43 | ============== 44 | 45 | After installed OpenSSE's dependency - [OpenCV 3.0.0+](http://opencv.org/), You can compile and install it like below: 46 | 47 | ```sh 48 | mkdir release && cd release 49 | cmake .. 50 | make 51 | make install 52 | ``` 53 | 54 | 55 | OpenSSE Wiki 56 | ============ 57 | More detail info, go to [OpenSSE Wiki](https://github.com/zddhub/opensse/wiki) 58 | 59 | 60 | Todo List 61 | ========= 62 | - [ ] Recognize sketch 63 | - [ ] Speed up train steps 64 | - [ ] Support big image set 65 | 66 | 67 | Thanks 68 | ====== 69 | - [Mathias Eitz](http://cybertron.cg.tu-berlin.de/eitz/) 70 | - [Szymon Rusinkiewicz](http://www.cs.princeton.edu/~smr/) 71 | - [SHREC 2012 - 2014](http://www.itl.nist.gov/iad/vug/sharp/contest/2014/Generic3D/index.html) 72 | - [Tilke Judd](http://people.csail.mit.edu/tjudd/) 73 | 74 | 75 | License 76 | ======= 77 | 78 | [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0) 79 | 80 | 81 | Contact me 82 | ========== 83 | 84 | If you have any question or idea, please [email to me](mailto:zddhub@gmail.com). 85 | -------------------------------------------------------------------------------- /data/opensr.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zddhub/opensse/9611503bd09009cd5319f15cac8511dfb7d7b388/data/opensr.gif -------------------------------------------------------------------------------- /data/opensse.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zddhub/opensse/9611503bd09009cd5319f15cac8511dfb7d7b388/data/opensse.gif -------------------------------------------------------------------------------- /data/view/0.xf: -------------------------------------------------------------------------------- 1 | 1 0 0 0 2 | 0 1 0 0 3 | -0 0 1 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/1.xf: -------------------------------------------------------------------------------- 1 | 0.95106 0 0.30902 0 2 | 0 1 0 0 3 | -0.30902 0 0.95106 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/10.xf: -------------------------------------------------------------------------------- 1 | -1 0 1.2246e-016 0 2 | 0 1 0 0 3 | -1.2246e-016 0 -1 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/100.xf: -------------------------------------------------------------------------------- 1 | 1 -2.4493e-016 -1.4998e-032 0 2 | 0 6.1232e-017 -1 0 3 | 2.4493e-016 1 6.1232e-017 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/101.xf: -------------------------------------------------------------------------------- 1 | 1 2.4493e-016 -1.4998e-032 0 2 | 0 6.1232e-017 1 0 3 | 2.4493e-016 -1 6.1232e-017 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/11.xf: -------------------------------------------------------------------------------- 1 | -0.95106 0 -0.30902 0 2 | 0 1 0 0 3 | 0.30902 0 -0.95106 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/12.xf: -------------------------------------------------------------------------------- 1 | -0.80902 0 -0.58779 0 2 | 0 1 0 0 3 | 0.58779 0 -0.80902 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/13.xf: -------------------------------------------------------------------------------- 1 | -0.58779 0 -0.80902 0 2 | 0 1 0 0 3 | 0.80902 0 -0.58779 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/14.xf: -------------------------------------------------------------------------------- 1 | -0.30902 0 -0.95106 0 2 | 0 1 0 0 3 | 0.95106 0 -0.30902 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/15.xf: -------------------------------------------------------------------------------- 1 | -1.837e-016 0 -1 0 2 | 0 1 0 0 3 | 1 0 -1.837e-016 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/16.xf: -------------------------------------------------------------------------------- 1 | 0.30902 0 -0.95106 0 2 | 0 1 0 0 3 | 0.95106 0 0.30902 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/17.xf: -------------------------------------------------------------------------------- 1 | 0.58779 0 -0.80902 0 2 | 0 1 0 0 3 | 0.80902 0 0.58779 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/18.xf: -------------------------------------------------------------------------------- 1 | 0.80902 0 -0.58779 0 2 | 0 1 0 0 3 | 0.58779 0 0.80902 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/19.xf: -------------------------------------------------------------------------------- 1 | 0.95106 0 -0.30902 0 2 | 0 1 0 0 3 | 0.30902 0 0.95106 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/2.xf: -------------------------------------------------------------------------------- 1 | 0.80902 0 0.58779 0 2 | 0 1 0 0 3 | -0.58779 0 0.80902 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/20.xf: -------------------------------------------------------------------------------- 1 | 1 0 0 0 2 | 0 0.86603 -0.5 0 3 | 0 0.5 0.86603 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/21.xf: -------------------------------------------------------------------------------- 1 | 0.95106 0.15451 0.26762 0 2 | 0 0.86603 -0.5 0 3 | -0.30902 0.47553 0.82364 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/22.xf: -------------------------------------------------------------------------------- 1 | 0.80902 0.29389 0.50904 0 2 | 0 0.86603 -0.5 0 3 | -0.58779 0.40451 0.70063 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/23.xf: -------------------------------------------------------------------------------- 1 | 0.58779 0.40451 0.70063 0 2 | 0 0.86603 -0.5 0 3 | -0.80902 0.29389 0.50904 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/24.xf: -------------------------------------------------------------------------------- 1 | 0.30902 0.47553 0.82364 0 2 | 0 0.86603 -0.5 0 3 | -0.95106 0.15451 0.26762 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/25.xf: -------------------------------------------------------------------------------- 1 | 6.1232e-017 0.5 0.86603 0 2 | 0 0.86603 -0.5 0 3 | -1 3.0616e-017 5.3029e-017 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/26.xf: -------------------------------------------------------------------------------- 1 | -0.30902 0.47553 0.82364 0 2 | 0 0.86603 -0.5 0 3 | -0.95106 -0.15451 -0.26762 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/27.xf: -------------------------------------------------------------------------------- 1 | -0.58779 0.40451 0.70063 0 2 | 0 0.86603 -0.5 0 3 | -0.80902 -0.29389 -0.50904 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/28.xf: -------------------------------------------------------------------------------- 1 | -0.80902 0.29389 0.50904 0 2 | 0 0.86603 -0.5 0 3 | -0.58779 -0.40451 -0.70063 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/29.xf: -------------------------------------------------------------------------------- 1 | -0.95106 0.15451 0.26762 0 2 | 0 0.86603 -0.5 0 3 | -0.30902 -0.47553 -0.82364 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/3.xf: -------------------------------------------------------------------------------- 1 | 0.58779 0 0.80902 0 2 | 0 1 0 0 3 | -0.80902 0 0.58779 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/30.xf: -------------------------------------------------------------------------------- 1 | -1 6.1232e-017 1.0606e-016 0 2 | 0 0.86603 -0.5 0 3 | -1.2246e-016 -0.5 -0.86603 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/31.xf: -------------------------------------------------------------------------------- 1 | -0.95106 -0.15451 -0.26762 0 2 | 0 0.86603 -0.5 0 3 | 0.30902 -0.47553 -0.82364 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/32.xf: -------------------------------------------------------------------------------- 1 | -0.80902 -0.29389 -0.50904 0 2 | 0 0.86603 -0.5 0 3 | 0.58779 -0.40451 -0.70063 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/33.xf: -------------------------------------------------------------------------------- 1 | -0.58779 -0.40451 -0.70063 0 2 | 0 0.86603 -0.5 0 3 | 0.80902 -0.29389 -0.50904 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/34.xf: -------------------------------------------------------------------------------- 1 | -0.30902 -0.47553 -0.82364 0 2 | 0 0.86603 -0.5 0 3 | 0.95106 -0.15451 -0.26762 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/35.xf: -------------------------------------------------------------------------------- 1 | -1.837e-016 -0.5 -0.86603 0 2 | 0 0.86603 -0.5 0 3 | 1 -9.1849e-017 -1.5909e-016 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/36.xf: -------------------------------------------------------------------------------- 1 | 0.30902 -0.47553 -0.82364 0 2 | 0 0.86603 -0.5 0 3 | 0.95106 0.15451 0.26762 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/37.xf: -------------------------------------------------------------------------------- 1 | 0.58779 -0.40451 -0.70063 0 2 | 0 0.86603 -0.5 0 3 | 0.80902 0.29389 0.50904 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/38.xf: -------------------------------------------------------------------------------- 1 | 0.80902 -0.29389 -0.50904 0 2 | 0 0.86603 -0.5 0 3 | 0.58779 0.40451 0.70063 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/39.xf: -------------------------------------------------------------------------------- 1 | 0.95106 -0.15451 -0.26762 0 2 | 0 0.86603 -0.5 0 3 | 0.30902 0.47553 0.82364 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/4.xf: -------------------------------------------------------------------------------- 1 | 0.30902 0 0.95106 0 2 | 0 1 0 0 3 | -0.95106 0 0.30902 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/40.xf: -------------------------------------------------------------------------------- 1 | 1 0 0 0 2 | 0 0.5 -0.86603 0 3 | 0 0.86603 0.5 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/41.xf: -------------------------------------------------------------------------------- 1 | 0.95106 0.26762 0.15451 0 2 | 0 0.5 -0.86603 0 3 | -0.30902 0.82364 0.47553 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/42.xf: -------------------------------------------------------------------------------- 1 | 0.80902 0.50904 0.29389 0 2 | 0 0.5 -0.86603 0 3 | -0.58779 0.70063 0.40451 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/43.xf: -------------------------------------------------------------------------------- 1 | 0.58779 0.70063 0.40451 0 2 | 0 0.5 -0.86603 0 3 | -0.80902 0.50904 0.29389 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/44.xf: -------------------------------------------------------------------------------- 1 | 0.30902 0.82364 0.47553 0 2 | 0 0.5 -0.86603 0 3 | -0.95106 0.26762 0.15451 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/45.xf: -------------------------------------------------------------------------------- 1 | 6.1232e-017 0.86603 0.5 0 2 | 0 0.5 -0.86603 0 3 | -1 5.3029e-017 3.0616e-017 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/46.xf: -------------------------------------------------------------------------------- 1 | -0.30902 0.82364 0.47553 0 2 | 0 0.5 -0.86603 0 3 | -0.95106 -0.26762 -0.15451 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/47.xf: -------------------------------------------------------------------------------- 1 | -0.58779 0.70063 0.40451 0 2 | 0 0.5 -0.86603 0 3 | -0.80902 -0.50904 -0.29389 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/48.xf: -------------------------------------------------------------------------------- 1 | -0.80902 0.50904 0.29389 0 2 | 0 0.5 -0.86603 0 3 | -0.58779 -0.70063 -0.40451 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/49.xf: -------------------------------------------------------------------------------- 1 | -0.95106 0.26762 0.15451 0 2 | 0 0.5 -0.86603 0 3 | -0.30902 -0.82364 -0.47553 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/5.xf: -------------------------------------------------------------------------------- 1 | 6.1232e-017 0 1 0 2 | 0 1 0 0 3 | -1 0 6.1232e-017 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/50.xf: -------------------------------------------------------------------------------- 1 | -1 1.0606e-016 6.1232e-017 0 2 | 0 0.5 -0.86603 0 3 | -1.2246e-016 -0.86603 -0.5 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/51.xf: -------------------------------------------------------------------------------- 1 | -0.95106 -0.26762 -0.15451 0 2 | 0 0.5 -0.86603 0 3 | 0.30902 -0.82364 -0.47553 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/52.xf: -------------------------------------------------------------------------------- 1 | -0.80902 -0.50904 -0.29389 0 2 | 0 0.5 -0.86603 0 3 | 0.58779 -0.70063 -0.40451 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/53.xf: -------------------------------------------------------------------------------- 1 | -0.58779 -0.70063 -0.40451 0 2 | 0 0.5 -0.86603 0 3 | 0.80902 -0.50904 -0.29389 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/54.xf: -------------------------------------------------------------------------------- 1 | -0.30902 -0.82364 -0.47553 0 2 | 0 0.5 -0.86603 0 3 | 0.95106 -0.26762 -0.15451 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/55.xf: -------------------------------------------------------------------------------- 1 | -1.837e-016 -0.86603 -0.5 0 2 | 0 0.5 -0.86603 0 3 | 1 -1.5909e-016 -9.1849e-017 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/56.xf: -------------------------------------------------------------------------------- 1 | 0.30902 -0.82364 -0.47553 0 2 | 0 0.5 -0.86603 0 3 | 0.95106 0.26762 0.15451 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/57.xf: -------------------------------------------------------------------------------- 1 | 0.58779 -0.70063 -0.40451 0 2 | 0 0.5 -0.86603 0 3 | 0.80902 0.50904 0.29389 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/58.xf: -------------------------------------------------------------------------------- 1 | 0.80902 -0.50904 -0.29389 0 2 | 0 0.5 -0.86603 0 3 | 0.58779 0.70063 0.40451 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/59.xf: -------------------------------------------------------------------------------- 1 | 0.95106 -0.26762 -0.15451 0 2 | 0 0.5 -0.86603 0 3 | 0.30902 0.82364 0.47553 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/6.xf: -------------------------------------------------------------------------------- 1 | -0.30902 0 0.95106 0 2 | 0 1 0 0 3 | -0.95106 0 -0.30902 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/60.xf: -------------------------------------------------------------------------------- 1 | 1 0 0 0 2 | 0 0.5 0.86603 0 3 | 0 -0.86603 0.5 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/61.xf: -------------------------------------------------------------------------------- 1 | 0.95106 -0.26762 0.15451 0 2 | 0 0.5 0.86603 0 3 | -0.30902 -0.82364 0.47553 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/62.xf: -------------------------------------------------------------------------------- 1 | 0.80902 -0.50904 0.29389 0 2 | 0 0.5 0.86603 0 3 | -0.58779 -0.70063 0.40451 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/63.xf: -------------------------------------------------------------------------------- 1 | 0.58779 -0.70063 0.40451 0 2 | 0 0.5 0.86603 0 3 | -0.80902 -0.50904 0.29389 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/64.xf: -------------------------------------------------------------------------------- 1 | 0.30902 -0.82364 0.47553 0 2 | 0 0.5 0.86603 0 3 | -0.95106 -0.26762 0.15451 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/65.xf: -------------------------------------------------------------------------------- 1 | 6.1232e-017 -0.86603 0.5 0 2 | 0 0.5 0.86603 0 3 | -1 -5.3029e-017 3.0616e-017 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/66.xf: -------------------------------------------------------------------------------- 1 | -0.30902 -0.82364 0.47553 0 2 | 0 0.5 0.86603 0 3 | -0.95106 0.26762 -0.15451 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/67.xf: -------------------------------------------------------------------------------- 1 | -0.58779 -0.70063 0.40451 0 2 | 0 0.5 0.86603 0 3 | -0.80902 0.50904 -0.29389 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/68.xf: -------------------------------------------------------------------------------- 1 | -0.80902 -0.50904 0.29389 0 2 | 0 0.5 0.86603 0 3 | -0.58779 0.70063 -0.40451 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/69.xf: -------------------------------------------------------------------------------- 1 | -0.95106 -0.26762 0.15451 0 2 | 0 0.5 0.86603 0 3 | -0.30902 0.82364 -0.47553 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/7.xf: -------------------------------------------------------------------------------- 1 | -0.58779 0 0.80902 0 2 | 0 1 0 0 3 | -0.80902 0 -0.58779 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/70.xf: -------------------------------------------------------------------------------- 1 | -1 -1.0606e-016 6.1232e-017 0 2 | 0 0.5 0.86603 0 3 | -1.2246e-016 0.86603 -0.5 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/71.xf: -------------------------------------------------------------------------------- 1 | -0.95106 0.26762 -0.15451 0 2 | 0 0.5 0.86603 0 3 | 0.30902 0.82364 -0.47553 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/72.xf: -------------------------------------------------------------------------------- 1 | -0.80902 0.50904 -0.29389 0 2 | 0 0.5 0.86603 0 3 | 0.58779 0.70063 -0.40451 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/73.xf: -------------------------------------------------------------------------------- 1 | -0.58779 0.70063 -0.40451 0 2 | 0 0.5 0.86603 0 3 | 0.80902 0.50904 -0.29389 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/74.xf: -------------------------------------------------------------------------------- 1 | -0.30902 0.82364 -0.47553 0 2 | 0 0.5 0.86603 0 3 | 0.95106 0.26762 -0.15451 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/75.xf: -------------------------------------------------------------------------------- 1 | -1.837e-016 0.86603 -0.5 0 2 | 0 0.5 0.86603 0 3 | 1 1.5909e-016 -9.1849e-017 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/76.xf: -------------------------------------------------------------------------------- 1 | 0.30902 0.82364 -0.47553 0 2 | 0 0.5 0.86603 0 3 | 0.95106 -0.26762 0.15451 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/77.xf: -------------------------------------------------------------------------------- 1 | 0.58779 0.70063 -0.40451 0 2 | 0 0.5 0.86603 0 3 | 0.80902 -0.50904 0.29389 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/78.xf: -------------------------------------------------------------------------------- 1 | 0.80902 0.50904 -0.29389 0 2 | 0 0.5 0.86603 0 3 | 0.58779 -0.70063 0.40451 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/79.xf: -------------------------------------------------------------------------------- 1 | 0.95106 0.26762 -0.15451 0 2 | 0 0.5 0.86603 0 3 | 0.30902 -0.82364 0.47553 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/8.xf: -------------------------------------------------------------------------------- 1 | -0.80902 0 0.58779 0 2 | 0 1 0 0 3 | -0.58779 0 -0.80902 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/80.xf: -------------------------------------------------------------------------------- 1 | 1 0 0 0 2 | 0 0.86603 0.5 0 3 | 0 -0.5 0.86603 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/81.xf: -------------------------------------------------------------------------------- 1 | 0.95106 -0.15451 0.26762 0 2 | 0 0.86603 0.5 0 3 | -0.30902 -0.47553 0.82364 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/82.xf: -------------------------------------------------------------------------------- 1 | 0.80902 -0.29389 0.50904 0 2 | 0 0.86603 0.5 0 3 | -0.58779 -0.40451 0.70063 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/83.xf: -------------------------------------------------------------------------------- 1 | 0.58779 -0.40451 0.70063 0 2 | 0 0.86603 0.5 0 3 | -0.80902 -0.29389 0.50904 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/84.xf: -------------------------------------------------------------------------------- 1 | 0.30902 -0.47553 0.82364 0 2 | 0 0.86603 0.5 0 3 | -0.95106 -0.15451 0.26762 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/85.xf: -------------------------------------------------------------------------------- 1 | 6.1232e-017 -0.5 0.86603 0 2 | 0 0.86603 0.5 0 3 | -1 -3.0616e-017 5.3029e-017 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/86.xf: -------------------------------------------------------------------------------- 1 | -0.30902 -0.47553 0.82364 0 2 | 0 0.86603 0.5 0 3 | -0.95106 0.15451 -0.26762 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/87.xf: -------------------------------------------------------------------------------- 1 | -0.58779 -0.40451 0.70063 0 2 | 0 0.86603 0.5 0 3 | -0.80902 0.29389 -0.50904 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/88.xf: -------------------------------------------------------------------------------- 1 | -0.80902 -0.29389 0.50904 0 2 | 0 0.86603 0.5 0 3 | -0.58779 0.40451 -0.70063 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/89.xf: -------------------------------------------------------------------------------- 1 | -0.95106 -0.15451 0.26762 0 2 | 0 0.86603 0.5 0 3 | -0.30902 0.47553 -0.82364 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/9.xf: -------------------------------------------------------------------------------- 1 | -0.95106 0 0.30902 0 2 | 0 1 0 0 3 | -0.30902 0 -0.95106 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/90.xf: -------------------------------------------------------------------------------- 1 | -1 -6.1232e-017 1.0606e-016 0 2 | 0 0.86603 0.5 0 3 | -1.2246e-016 0.5 -0.86603 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/91.xf: -------------------------------------------------------------------------------- 1 | -0.95106 0.15451 -0.26762 0 2 | 0 0.86603 0.5 0 3 | 0.30902 0.47553 -0.82364 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/92.xf: -------------------------------------------------------------------------------- 1 | -0.80902 0.29389 -0.50904 0 2 | 0 0.86603 0.5 0 3 | 0.58779 0.40451 -0.70063 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/93.xf: -------------------------------------------------------------------------------- 1 | -0.58779 0.40451 -0.70063 0 2 | 0 0.86603 0.5 0 3 | 0.80902 0.29389 -0.50904 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/94.xf: -------------------------------------------------------------------------------- 1 | -0.30902 0.47553 -0.82364 0 2 | 0 0.86603 0.5 0 3 | 0.95106 0.15451 -0.26762 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/95.xf: -------------------------------------------------------------------------------- 1 | -1.837e-016 0.5 -0.86603 0 2 | 0 0.86603 0.5 0 3 | 1 9.1849e-017 -1.5909e-016 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/96.xf: -------------------------------------------------------------------------------- 1 | 0.30902 0.47553 -0.82364 0 2 | 0 0.86603 0.5 0 3 | 0.95106 -0.15451 0.26762 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/97.xf: -------------------------------------------------------------------------------- 1 | 0.58779 0.40451 -0.70063 0 2 | 0 0.86603 0.5 0 3 | 0.80902 -0.29389 0.50904 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/98.xf: -------------------------------------------------------------------------------- 1 | 0.80902 0.29389 -0.50904 0 2 | 0 0.86603 0.5 0 3 | 0.58779 -0.40451 0.70063 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/view/99.xf: -------------------------------------------------------------------------------- 1 | 0.95106 0.15451 -0.26762 0 2 | 0 0.86603 0.5 0 3 | 0.30902 -0.47553 0.82364 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /data/zddhub.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zddhub/opensse/9611503bd09009cd5319f15cac8511dfb7d7b388/data/zddhub.png -------------------------------------------------------------------------------- /gui/SketchSearchDemo/SketchSearchDemo.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) 2014 Zhang Dongdong 3 | # All rights reserved. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | #------------------------------------------------------------------------- 17 | #------------------------------------------------- 18 | # 19 | # Project created by QtCreator 2014-03-12T08:55:19 20 | # 21 | #------------------------------------------------- 22 | 23 | QT += core gui \ 24 | opengl \ 25 | printsupport 26 | 27 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 28 | 29 | TARGET = SketchSearchDemo 30 | TEMPLATE = app 31 | 32 | DESTDIR = ../bin 33 | 34 | CONFIGDIR = /tmp/SketchSearchDemo 35 | 36 | QMAKE_POST_LINK = mkdir -p $$CONFIGDIR; cp $$PWD/config.json $$CONFIGDIR; \ 37 | mkdir -p $$CONFIGDIR/view; cp $$PWD/view/* $$CONFIGDIR/view 38 | 39 | unix { 40 | INCLUDEPATH += $$PWD \ 41 | /usr/local/include 42 | 43 | LIBS += -L/usr/local/lib/ \ 44 | -lopencv_core -lopencv_imgproc -lopencv_imgcodecs -lopencv_highgui -lopencv_features2d -lopencv_ml \ 45 | -lopensse 46 | } 47 | 48 | macx: CONFIG += app_bundle 49 | 50 | include(trimeshview/trimeshview.pri) 51 | 52 | SOURCES += main.cpp\ 53 | mainwindow.cpp \ 54 | sketcharea.cpp \ 55 | resultphotowidget.cpp \ 56 | sketchsearcher.cpp \ 57 | 58 | HEADERS += mainwindow.h \ 59 | sketcharea.h \ 60 | searchengine.h \ 61 | resultphotowidget.h \ 62 | sketchsearcher.h \ 63 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "searcher": 3 | { 4 | "indexfile": "/Users/ddzhang/Database/SHREC12/index_file", 5 | "filelist": "/Users/ddzhang/Database/SHREC12/filelist", 6 | "vocabulary": "/Users/ddzhang/Database/SHREC12/vocabulary", 7 | "results_num": "12", 8 | "views_num": "102" 9 | } 10 | } -------------------------------------------------------------------------------- /gui/SketchSearchDemo/main.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Copyright (c) 2014 Zhang Dongdong 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | **************************************************************************/ 17 | #include "mainwindow.h" 18 | #include 19 | 20 | int main(int argc, char *argv[]) 21 | { 22 | QApplication a(argc, argv); 23 | MainWindow w; 24 | w.showMaximized(); 25 | 26 | return a.exec(); 27 | } 28 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/mainwindow.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Copyright (c) 2014 Zhang Dongdong 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | **************************************************************************/ 17 | #include "mainwindow.h" 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include "sketchsearcher.h" 28 | 29 | MainWindow::MainWindow(QWidget *parent) 30 | : QMainWindow(parent) 31 | { 32 | Json config = Json("/tmp/SketchSearchDemo/config.json"); // 33 | searchEngine = new SketchSearcher(config); 34 | 35 | setupMenuBar(); 36 | 37 | sketchArea = new SketchArea; 38 | sketchArea->setAutoSaveSketch(true); 39 | triMeshView = new TriMeshView; 40 | //triMeshView->readMesh("./data/1_01.obj"); 41 | QSplitter *leftSplitter = new QSplitter(Qt::Vertical); 42 | leftSplitter->addWidget(sketchArea); 43 | leftSplitter->addWidget(triMeshView); 44 | //leftSplitter->setStretchFactor(1, 1); 45 | 46 | resultPhotoWidget = new ResultPhotoWidget; 47 | QSplitter *mainSplitter = new QSplitter(Qt::Horizontal); 48 | mainSplitter->addWidget(leftSplitter); 49 | mainSplitter->addWidget(resultPhotoWidget); 50 | //mainSplitter->setStretchFactor(1, 2); 51 | 52 | QSize size = this->size(); 53 | QList leftList; 54 | leftList.push_back(size.height()/2); 55 | leftList.push_back(size.height()/2); 56 | leftSplitter->setSizes(leftList); 57 | 58 | QList mainList; 59 | mainList.push_back(size.width()/7); 60 | mainList.push_back(size.width()/3); 61 | mainSplitter->setSizes(mainList); 62 | 63 | this->setCentralWidget(mainSplitter); 64 | 65 | this->setMinimumSize(800, 600); 66 | 67 | //auto search 68 | connect(sketchArea, SIGNAL(newSketchDone(QString)), this, SLOT(search(QString))); 69 | 70 | connect(sketchArea, SIGNAL(clearSketchDone()), this, SLOT(clearResults())); 71 | connect(resultPhotoWidget, SIGNAL(itemClicked(QTableWidgetItem*)), this, SLOT(showLineDrawing(QTableWidgetItem*))); 72 | 73 | } 74 | 75 | void MainWindow::setupMenuBar() 76 | { 77 | QMenu *fileMenu = menuBar()->addMenu(tr("&File")); 78 | 79 | QAction *openAction = fileMenu->addAction(tr("&Open")); 80 | connect(openAction, SIGNAL(triggered()), this, SLOT(openFile())); 81 | 82 | QAction *queryAction = menuBar()->addAction(tr("&Query")); 83 | connect(queryAction, SIGNAL(triggered()), this, SLOT(query())); 84 | } 85 | 86 | void MainWindow::openFile() 87 | { 88 | QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), QDir::currentPath(), 89 | tr("Images (*.png *.bmp *.jpg)")); 90 | 91 | if(!fileName.isEmpty()) 92 | { 93 | sketchArea->openImage(fileName); 94 | } 95 | } 96 | 97 | void MainWindow::query() 98 | { 99 | QueryResults results; 100 | searchEngine->query(sketchArea->sketchPath().toStdString(), results); 101 | resultPhotoWidget->updateResults(results); 102 | } 103 | 104 | void MainWindow::search(const QString &fileName) 105 | { 106 | QueryResults results; 107 | searchEngine->query(fileName.toStdString(), results); 108 | resultPhotoWidget->updateResults(results); 109 | } 110 | 111 | void MainWindow::clearResults() 112 | { 113 | QueryResults res; 114 | resultPhotoWidget->updateResults(res); 115 | triMeshView->clearMesh(); 116 | } 117 | 118 | void MainWindow::showLineDrawing(QTableWidgetItem *item) 119 | { 120 | QString fileName = item->whatsThis(); 121 | QString modelFileName = fileName.left(fileName.lastIndexOf("view")) + ".off"; 122 | 123 | // std::cout << "fileName:" << fileName.toStdString()<readMesh(modelFileName.toStdString().c_str(), 132 | xfFileName.replace(".jpg", ".xf").toStdString().c_str()); 133 | 134 | // qDebug(fileName.toStdString().c_str()); 135 | 136 | } 137 | 138 | MainWindow::~MainWindow() 139 | { 140 | 141 | } 142 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/mainwindow.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Copyright (c) 2014 Zhang Dongdong 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | **************************************************************************/ 17 | #ifndef MAINWINDOW_H 18 | #define MAINWINDOW_H 19 | 20 | #include 21 | 22 | #include "sketcharea.h" 23 | #include "searchengine.h" 24 | #include "resultphotowidget.h" 25 | #include "trimeshview.h" 26 | 27 | class MainWindow : public QMainWindow 28 | { 29 | Q_OBJECT 30 | 31 | public: 32 | MainWindow(QWidget *parent = 0); 33 | ~MainWindow(); 34 | private slots: 35 | void openFile(); 36 | void query(); 37 | void search(const QString &fileName); 38 | void showLineDrawing(QTableWidgetItem *item); 39 | void clearResults(); 40 | private: 41 | void setupMenuBar(); 42 | private: 43 | SketchArea *sketchArea; 44 | TriMeshView *triMeshView; 45 | ResultPhotoWidget *resultPhotoWidget; 46 | SearchEngine *searchEngine; 47 | }; 48 | 49 | #endif // MAINWINDOW_H 50 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/resultphotowidget.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Copyright (c) 2014 Zhang Dongdong 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | **************************************************************************/ 17 | #include "resultphotowidget.h" 18 | 19 | 20 | #include 21 | #include 22 | 23 | ResultPhotoWidget::ResultPhotoWidget(QWidget *parent) : 24 | QTableWidget(parent) 25 | { 26 | resize(300, 800); 27 | //setMaximumWidth(300); 28 | setIconSize(QSize(200,200)); 29 | 30 | 31 | //setColumnWidth(0, 108); 32 | 33 | // setRowCount(1); 34 | // setRowHeight(0,200); 35 | 36 | // 37 | this->horizontalHeader()->hide(); 38 | this->verticalHeader()->hide(); 39 | 40 | this->setStyleSheet("QTableView{selection-background-color: transparent;selection-color: transparent}"); 41 | // 42 | this->setShowGrid(false); 43 | 44 | // 45 | this->setEditTriggers(QAbstractItemView::NoEditTriggers); 46 | 47 | QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); 48 | this->setSizePolicy(sizePolicy); 49 | 50 | // 51 | this->setSelectionMode(QAbstractItemView::SingleSelection); 52 | 53 | // 54 | this->setFocusPolicy(Qt::NoFocus); 55 | } 56 | 57 | 58 | void ResultPhotoWidget::updateResults(QueryResults &res) 59 | { 60 | results.clear(); 61 | results = res; 62 | 63 | int columnCount = 4; 64 | this->clear(); 65 | // this->setColumnCount(results.size()); 66 | this->setRowCount(results.size()/columnCount +1); 67 | this->setColumnCount(columnCount); 68 | 69 | for(int i = 0; i < results.size();i++) 70 | { 71 | if(results[i].ratio <=0.0) 72 | break; 73 | 74 | QTableWidgetItem *item = new QTableWidgetItem(); 75 | item->setWhatsThis(QString(results[i].imageName.c_str())); 76 | item->setIcon(QIcon(QString(results[i].imageName.c_str()))); 77 | QString rank = tr("%1 %2").arg(results[i].ratio).arg(QString(results[i].imageName.c_str())); 78 | item->setToolTip(rank); 79 | item->setText(rank); 80 | item->setTextAlignment(Qt::AlignBottom); 81 | item->setTextColor(Qt::black); 82 | 83 | setItem(i/columnCount, i%columnCount, item); 84 | // setColumnWidth(i, 200); 85 | // setItem(i, 0, item); 86 | 87 | item->setTextAlignment(Qt::AlignCenter); 88 | 89 | setRowHeight(i/columnCount, 212); 90 | setColumnWidth(i%columnCount, 207); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/resultphotowidget.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Copyright (c) 2014 Zhang Dongdong 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | **************************************************************************/ 17 | #ifndef RESULTPHOTOWIDGET_H 18 | #define RESULTPHOTOWIDGET_H 19 | 20 | #include 21 | 22 | #include "searchengine.h" 23 | 24 | class ResultPhotoWidget : public QTableWidget 25 | { 26 | Q_OBJECT 27 | public: 28 | explicit ResultPhotoWidget(QWidget *parent = 0); 29 | signals: 30 | 31 | public slots: 32 | void updateResults(QueryResults &res); 33 | private: 34 | QueryResults results; 35 | }; 36 | 37 | #endif // RESULTPHOTOWIDGET_H 38 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/searchengine.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Copyright (c) 2014 Zhang Dongdong 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | **************************************************************************/ 17 | #ifndef SEARCHENGINE_H 18 | #define SEARCHENGINE_H 19 | 20 | #include 21 | #include 22 | 23 | typedef unsigned int uint; 24 | 25 | struct QueryResult 26 | { 27 | std::string imageName; 28 | uint imageIndex; 29 | float ratio; 30 | 31 | bool operator< (const QueryResult& r) const 32 | { 33 | return ratio > r.ratio; 34 | } 35 | }; 36 | 37 | typedef std::vector QueryResults; 38 | 39 | /** 40 | * @brief The SearchEngine class 41 | * Search engine interface 42 | */ 43 | class SearchEngine 44 | { 45 | public: 46 | virtual void query(const std::string &fileName, QueryResults& results) = 0; 47 | }; 48 | 49 | #endif // SEARCHENGINE_H 50 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/sketcharea.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Copyright (c) 2014 Zhang Dongdong 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | **************************************************************************/ 17 | #include "sketcharea.h" 18 | 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | 26 | SketchArea::SketchArea(QWidget *parent) : 27 | QWidget(parent) 28 | { 29 | setAttribute(Qt::WA_StaticContents); 30 | QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); 31 | this->setSizePolicy(sizePolicy); 32 | 33 | this->setFocusPolicy(Qt::StrongFocus); 34 | 35 | modified = false; 36 | 37 | scribbling = false; 38 | myPenWidth = 3; 39 | myPenColor = Qt::black; 40 | 41 | erasing = false; 42 | myEraserWidth = 25; 43 | myEraserColor = Qt::white; 44 | 45 | autoSaveSketch = false; 46 | saveSketchFileName = "/tmp/temp.jpg"; 47 | } 48 | 49 | bool SketchArea::openImage(const QString &fileName) 50 | { 51 | QImage loadedImage; 52 | if (!loadedImage.load(fileName)) 53 | return false; 54 | 55 | clearImage(); 56 | 57 | loadedImage.save(saveSketchFileName, "JPG"); 58 | 59 | QSize newSize; 60 | if(loadedImage.size().width() > size().width() || loadedImage.size().height() > size().height()) 61 | { 62 | newSize = size(); 63 | loadedImage = loadedImage.scaled(size().width(), size().height()); 64 | } 65 | else 66 | newSize = loadedImage.size().expandedTo(size()); 67 | resizeImage(&loadedImage, newSize); 68 | 69 | //Form Indexed8 to Format_RGB32 70 | image = loadedImage.convertToFormat(QImage::Format_ARGB32); 71 | 72 | modified = false; 73 | 74 | emit newSketchDone(fileName); 75 | update(); 76 | return true; 77 | } 78 | 79 | bool SketchArea::saveImage(const QString &fileName, const char *fileFormat) 80 | { 81 | QImage visibleImage = image; 82 | resizeImage(&visibleImage, size()); 83 | 84 | if (visibleImage.save(fileName, fileFormat)) { 85 | modified = false; 86 | return true; 87 | } else { 88 | return false; 89 | } 90 | } 91 | 92 | void SketchArea::setPenColor(const QColor &newColor) 93 | { 94 | myPenColor = newColor; 95 | } 96 | 97 | void SketchArea::setPenWidth(int newWidth) 98 | { 99 | myPenWidth = newWidth; 100 | } 101 | 102 | void SketchArea::setEraserColor(const QColor &newColor) 103 | { 104 | myEraserColor = newColor; 105 | } 106 | 107 | void SketchArea::setEraserWidth(int newWidth) 108 | { 109 | myEraserWidth = newWidth; 110 | } 111 | 112 | void SketchArea::setAutoSaveSketch(bool save, const QString &fileName) 113 | { 114 | autoSaveSketch = save; 115 | saveSketchFileName = fileName; 116 | } 117 | 118 | void SketchArea::clearImage() 119 | { 120 | image.fill(qRgb(255, 255, 255)); 121 | modified = true; 122 | update(); 123 | emit clearSketchDone(); 124 | } 125 | 126 | void SketchArea::keyPressEvent(QKeyEvent *event) 127 | { 128 | switch(event->key()) { 129 | case Qt::Key_C: 130 | clearImage(); 131 | break; 132 | case Qt::Key_E: 133 | erasing = true; 134 | break; 135 | default: 136 | QWidget::keyPressEvent(event); 137 | } 138 | } 139 | 140 | void SketchArea::keyReleaseEvent(QKeyEvent *event) 141 | { 142 | switch (event->key()) { 143 | case Qt::Key_E: 144 | erasing = false; 145 | break; 146 | default: 147 | QWidget::keyPressEvent(event); 148 | break; 149 | } 150 | } 151 | 152 | void SketchArea::mousePressEvent(QMouseEvent *event) 153 | { 154 | if (event->button() == Qt::LeftButton) { 155 | lastPoint = event->pos(); 156 | scribbling = true; 157 | } 158 | else if(event->button() == Qt::RightButton) { 159 | lastPoint = event->pos(); 160 | erasing = true; 161 | } 162 | } 163 | 164 | void SketchArea::mouseMoveEvent(QMouseEvent *event) 165 | { 166 | if ((event->buttons() & Qt::LeftButton) && scribbling) 167 | drawLineTo(event->pos()); 168 | if ((event->buttons() & Qt::RightButton) && erasing) 169 | drawLineTo(event->pos()); 170 | } 171 | 172 | void SketchArea::mouseReleaseEvent(QMouseEvent *event) 173 | { 174 | if (event->button() == Qt::LeftButton && scribbling) { 175 | drawLineTo(event->pos()); 176 | scribbling = false; 177 | } 178 | 179 | if (event->button() == Qt::RightButton && erasing) { 180 | drawLineTo(event->pos()); 181 | erasing = false; 182 | } 183 | 184 | if(event->button() == Qt::MidButton) 185 | { 186 | clearImage(); 187 | } 188 | 189 | if(autoSaveSketch) 190 | saveImage(saveSketchFileName, "JPG"); 191 | 192 | if(event->button() == Qt::LeftButton || event->button() == Qt::RightButton) 193 | emit newSketchDone(saveSketchFileName); 194 | } 195 | 196 | void SketchArea::paintEvent(QPaintEvent *event) 197 | { 198 | QPainter painter(this); 199 | QRect dirtyRect = event->rect(); 200 | 201 | painter.drawImage(dirtyRect, image, dirtyRect); 202 | } 203 | 204 | void SketchArea::resizeEvent(QResizeEvent *event) 205 | { 206 | // if (width() > image.width() || height() > image.height()) { 207 | // int newWidth = qMax(width() + 128, image.width()); 208 | // int newHeight = qMax(height() + 128, image.height()); 209 | // resizeImage(&image, QSize(newWidth, newHeight)); 210 | // update(); 211 | // } 212 | 213 | QSize newSize(width(), height()); 214 | QImage newImage(newSize, QImage::Format_RGB32); 215 | newImage.fill(qRgb(255, 255, 255)); 216 | QPainter painter(&newImage); 217 | QRect rect; 218 | rect.setWidth(qMin(width(), image.width())); 219 | rect.setHeight(qMin(height(), image.height())); 220 | painter.drawImage(rect, image.copy(rect)); 221 | image = newImage; 222 | update(); 223 | 224 | QWidget::resizeEvent(event); 225 | } 226 | 227 | void SketchArea::drawLineTo(const QPoint &endPoint) 228 | { 229 | QPainter painter(&image); 230 | painter.setRenderHint(QPainter::Antialiasing);//ƽ��ֱ�� 231 | 232 | if(erasing) 233 | painter.setPen(QPen(myEraserColor, myEraserWidth, Qt::SolidLine, Qt::RoundCap, 234 | Qt::RoundJoin)); 235 | else 236 | painter.setPen(QPen(myPenColor, myPenWidth, Qt::SolidLine, Qt::RoundCap, 237 | Qt::RoundJoin)); 238 | 239 | if(endPoint.x() < rect().width() && endPoint.y() < rect().height()) 240 | painter.drawLine(lastPoint, endPoint); 241 | 242 | modified = true; 243 | 244 | int rad = ((erasing == true ? myEraserWidth : myPenWidth) / 2) + 2; 245 | update(QRect(lastPoint, endPoint).normalized() 246 | .adjusted(-rad, -rad, +rad, +rad)); 247 | lastPoint = endPoint; 248 | } 249 | 250 | void SketchArea::resizeImage(QImage *image, const QSize &newSize) 251 | { 252 | if (image->size() == newSize) 253 | return; 254 | 255 | QImage newImage(newSize, QImage::Format_RGB32); 256 | newImage.fill(qRgb(255, 255, 255)); 257 | QPainter painter(&newImage); 258 | painter.drawImage(QPoint(0, 0), *image); 259 | *image = newImage; 260 | painter.end(); 261 | } 262 | 263 | void SketchArea::print() 264 | { 265 | #ifndef QT_NO_PRINTER 266 | QPrinter printer(QPrinter::HighResolution); 267 | 268 | QPrintDialog *printDialog = new QPrintDialog(&printer, this); 269 | if (printDialog->exec() == QDialog::Accepted) { 270 | QPainter painter(&printer); 271 | QRect rect = painter.viewport(); 272 | QSize size = image.size(); 273 | size.scale(rect.size(), Qt::KeepAspectRatio); 274 | painter.setViewport(rect.x(), rect.y(), size.width(), size.height()); 275 | painter.setWindow(image.rect()); 276 | painter.drawImage(0, 0, image); 277 | } 278 | #endif // QT_NO_PRINTER 279 | } 280 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/sketcharea.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Copyright (c) 2014 Zhang Dongdong 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | **************************************************************************/ 17 | #ifndef SKETCHAREA_H 18 | #define SKETCHAREA_H 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | /** 30 | * @brief The SketchArea class 31 | * draw sketch panel 32 | * when mouse release, emit newSketchDone signal 33 | * using setAutoSaveSketch save sketch image. 34 | */ 35 | class SketchArea : public QWidget 36 | { 37 | Q_OBJECT 38 | public: 39 | explicit SketchArea(QWidget *parent = 0); 40 | bool openImage(const QString &fileName); 41 | bool saveImage(const QString &fileName, const char *fileFormat); 42 | void setPenColor(const QColor &newColor); 43 | void setPenWidth(int newWidth); 44 | void setEraserColor(const QColor &newColor); 45 | void setEraserWidth(int newWidth); 46 | 47 | /** 48 | * @brief setAutoSaveSketch 49 | * @param save is true, when you want to save sketch,else false; 50 | * @param fileName 51 | */ 52 | void setAutoSaveSketch(bool save, const QString &fileName = "/tmp/temp.jpg"); 53 | 54 | QString sketchPath() const { return saveSketchFileName; } 55 | bool isModified() const { return modified; } 56 | QColor penColor() const { return myPenColor; } 57 | int penWidth() const { return myPenWidth; } 58 | QColor eraserColor() const { return myEraserColor; } 59 | int eraserWidth() const { return myEraserWidth; } 60 | signals: 61 | void newSketchDone(const QString &fileName); 62 | void clearSketchDone(); 63 | public slots: 64 | void clearImage(); 65 | void print(); 66 | 67 | protected: 68 | void keyPressEvent(QKeyEvent *event); 69 | void keyReleaseEvent(QKeyEvent *event); 70 | void mousePressEvent(QMouseEvent *event); 71 | void mouseMoveEvent(QMouseEvent *event); 72 | void mouseReleaseEvent(QMouseEvent *event); 73 | void paintEvent(QPaintEvent *event); 74 | void resizeEvent(QResizeEvent *event); 75 | 76 | private: 77 | void drawLineTo(const QPoint &endPoint); 78 | void resizeImage(QImage *image, const QSize &newSize); 79 | 80 | bool autoSaveSketch; 81 | QString saveSketchFileName; 82 | 83 | bool modified; 84 | bool scribbling; 85 | int myPenWidth; 86 | QColor myPenColor; 87 | 88 | bool erasing; 89 | int myEraserWidth; 90 | QColor myEraserColor; 91 | 92 | QImage image; 93 | QPoint lastPoint; 94 | }; 95 | 96 | #endif // SKETCHAREA_H 97 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/sketchsearcher.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Copyright (c) 2014 Zhang Dongdong 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | **************************************************************************/ 17 | #include "sketchsearcher.h" 18 | using namespace sse; 19 | 20 | SketchSearcher::SketchSearcher(Json &config) 21 | : _indexFile(config.getValue("searcher$indexfile", "/tmp/SketchSearchDemo/data/model_indexfile")) 22 | , _vocabularyFile(config.getValue("searcher$vocabulary", "/tmp/SketchSearchDemo/data/vocabulary")) 23 | , _fileList(config.getValue("searcher$filelist", "/tmp/SketchSearchDemo/data/model_filelist")) 24 | , _numOfResults(convert(config.getValue("searcher$results_num", "25"), UINT)) 25 | , _numOfViews(convert(config.getValue("searcher$views_num", "1"), UINT)) 26 | { 27 | index = new InvertedIndex(); 28 | index->load(_indexFile); 29 | 30 | read(_vocabularyFile, vocabulary); 31 | 32 | galif = new Galif(); 33 | 34 | quantizer = QuantizerHard >(); 35 | 36 | files = new FileList; 37 | files->load(_fileList); 38 | } 39 | 40 | SketchSearcher::~SketchSearcher() 41 | { 42 | delete index; 43 | delete galif; 44 | delete files; 45 | } 46 | 47 | void SketchSearcher::query(const std::string &fileName, QueryResults &results) 48 | { 49 | //extract features 50 | KeyPoints_t keypoints; 51 | Features_t features; 52 | cv::Mat image = cv::imread(fileName.c_str()); 53 | 54 | galif->compute(image, keypoints, features); 55 | 56 | //quantize 57 | Vec_f32_t query; 58 | quantize(features, vocabulary, query, quantizer); 59 | 60 | TF_simple tf; 61 | IDF_simple idf; 62 | 63 | std::vector _results; 64 | //std::cout<< "query: " <<_results.size()<query(query, tf, idf, _numOfResults, _results); 69 | } 70 | else { 71 | index->query(query, tf, idf, _numOfResults, _numOfViews, _results); 72 | } 73 | 74 | results.resize(_results.size()); 75 | 76 | for(uint i = 0; i < _results.size(); i++) { 77 | 78 | results[i].ratio = _results[i].first; 79 | results[i].imageIndex = _results[i].second; 80 | results[i].imageName = files->getFilename(_results[i].second); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/sketchsearcher.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Copyright (c) 2014 Zhang Dongdong 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | **************************************************************************/ 17 | #ifndef SKETCHSEARCHER_H 18 | #define SKETCHSEARCHER_H 19 | 20 | #include "searchengine.h" 21 | 22 | #include "opensse/opensse.h" 23 | 24 | class SketchSearcher : public SearchEngine 25 | { 26 | public: 27 | SketchSearcher(Json &config); 28 | virtual ~SketchSearcher(); 29 | 30 | void query(const std::string &fileName, QueryResults &results); 31 | 32 | private: 33 | sse::InvertedIndex *index; 34 | sse::Galif *galif; 35 | sse::FileList *files; 36 | 37 | sse::Vocabularys_t vocabulary; 38 | sse::QuantizerHard > quantizer; 39 | 40 | const std::string _indexFile; 41 | const std::string _vocabularyFile; 42 | const std::string _rootdir; 43 | const std::string _fileList; 44 | const unsigned int _numOfResults; 45 | const unsigned int _numOfViews; 46 | }; 47 | 48 | #endif // SKETCHSEARCHER_H 49 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/trimeshview/include/GLCamera.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Copyright (c) 2014 Zhang Dongdong 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | **************************************************************************/ 17 | #ifndef GLCAMERA_H 18 | #define GLCAMERA_H 19 | /* 20 | Szymon Rusinkiewicz 21 | Princeton University 22 | 23 | GLCamera.h 24 | Manages OpenGL camera and trackball/arcball interaction 25 | */ 26 | 27 | #include "Vec.h" 28 | #include "XForm.h" 29 | #include "timestamp.h" 30 | 31 | 32 | namespace Mouse { 33 | enum button { NONE, ROTATE, MOVEXY, MOVEZ, WHEELUP, WHEELDOWN, LIGHT }; 34 | }; 35 | 36 | class GLCamera { 37 | public: 38 | enum Constraint { UNCONSTRAINED, 39 | XCONSTRAINED, YCONSTRAINED, ZCONSTRAINED }; 40 | 41 | private: 42 | int lastmousex, lastmousey; 43 | Mouse::button lastb; 44 | timestamp last_time; 45 | 46 | vec lightdir; 47 | 48 | bool dospin; 49 | point spincenter; 50 | vec spinaxis; 51 | float spinspeed; 52 | 53 | Constraint constraint_; 54 | float field_of_view, pixscale; 55 | mutable float surface_depth; 56 | float click_depth; 57 | float tb_screen_x, tb_screen_y, tb_screen_size; 58 | bool read_depth(int x, int y, point &p) const; 59 | 60 | void startspin(); 61 | vec mouse2tb(float x, float y); 62 | void rotate(int mousex, int mousey, xform &xf); 63 | void movexy(int mousex, int mousey, xform &xf); 64 | void movez(int mousex, int mousey, xform &xf); 65 | void wheel(Mouse::button updown, xform &xf); 66 | void relight(int mousex, int mousey); 67 | void mouse_click(int mousex, int mousey, 68 | const point &scene_center, float scene_size); 69 | 70 | public: 71 | GLCamera() : lastb(Mouse::NONE), lightdir(vec(0,0,1)), 72 | dospin(false), spinspeed(0), 73 | constraint_(UNCONSTRAINED), field_of_view(0.7f), 74 | surface_depth(0.0f), click_depth(0.0f) 75 | { 76 | lightdir[0] = lightdir[1] = 0; lightdir[2] = 1; 77 | last_time = now(); 78 | } 79 | 80 | void setupGL(const point &scene_center, float scene_size) const; 81 | 82 | void mouse(int mousex, int mousey, Mouse::button b, 83 | const point &scene_center, float scene_size, 84 | xform &xf); 85 | 86 | bool autospin(xform &xf); 87 | void stopspin() { dospin = false; } 88 | 89 | vec light() const { return lightdir; } 90 | void set_light(const vec &lightdir_) { lightdir = lightdir_; } 91 | 92 | float fov() const { return field_of_view; } 93 | void set_fov(float fov_) { field_of_view = fov_; } 94 | 95 | Constraint constraint() { return constraint_; } 96 | void set_constraint(Constraint c) { constraint_ = c; } 97 | }; 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/trimeshview/include/KDtree.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Copyright (c) 2014 Zhang Dongdong 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | **************************************************************************/ 17 | #ifndef KDTREE_H 18 | #define KDTREE_H 19 | /* 20 | Szymon Rusinkiewicz 21 | Princeton University 22 | 23 | KDtree.h 24 | A K-D tree for points, with limited capabilities (find nearest point to 25 | a given point, or to a ray). 26 | 27 | Note that in order to be generic, this *doesn't* use Vecs and the like... 28 | */ 29 | 30 | #include 31 | 32 | class KDtree { 33 | private: 34 | class Node; 35 | Node *root; 36 | void build(const float *ptlist, size_t n); 37 | 38 | public: 39 | // Compatibility function for closest-compatible-point searches 40 | struct CompatFunc 41 | { 42 | virtual bool operator () (const float *p) const = 0; 43 | virtual ~CompatFunc() {} // To make the compiler shut up 44 | }; 45 | 46 | // Constructor from an array of points 47 | KDtree(const float *ptlist, size_t n) 48 | { build(ptlist, n); } 49 | 50 | // Constructor from a vector of points 51 | template KDtree(const std::vector &v) 52 | { build((const float *) &v[0], v.size()); } 53 | 54 | // Destructor - recursively frees the tree 55 | ~KDtree(); 56 | 57 | // The queries: returns closest point to a point or a ray, 58 | // provided it's within sqrt(maxdist2) and is compatible 59 | const float *closest_to_pt(const float *p, 60 | float maxdist2 = 0.0f, 61 | const CompatFunc *iscompat = NULL) const; 62 | const float *closest_to_ray(const float *p, const float *dir, 63 | float maxdist2 = 0.0f, 64 | const CompatFunc *iscompat = NULL) const; 65 | 66 | // Find the k nearest neighbors 67 | void find_k_closest_to_pt(std::vector &knn, 68 | int k, 69 | const float *p, 70 | float maxdist2 = 0.0f, 71 | const CompatFunc *iscompat = NULL) const; 72 | }; 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/trimeshview/include/bsphere.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Copyright (c) 2014 Zhang Dongdong 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | **************************************************************************/ 17 | #ifndef BSPHERE_H 18 | #define BSPHERE_H 19 | // Copright (C) 1999 20 | // 21 | // This program is free software; you can redistribute it and/or modify 22 | // it under the terms of the GNU General Public License as published by 23 | // the Free Software Foundation; either version 2 of the License, or 24 | // (at your option) any later version. 25 | // 26 | // This program is distributed in the hope that it will be useful, 27 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | // GNU General Public License for more details. 30 | // 31 | // You should have received a copy of the GNU General Public License 32 | // along with this program; if not, write to the Free Software 33 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA, 34 | // or download the License terms from prep.ai.mit.edu/pub/gnu/COPYING-2.0. 35 | // 36 | // Contact: 37 | // -------- 38 | // Bernd Gaertner 39 | // Institut f. Informatik 40 | // ETH Zuerich 41 | // ETH-Zentrum 42 | // CH-8092 Zuerich, Switzerland 43 | // http://www.inf.ethz.ch/personal/gaertner 44 | // 45 | 46 | 47 | #include "Vec.h" 48 | #include 49 | 50 | 51 | // Class for a basis of points supporting a bounding sphere 52 | template 53 | class Basis { 54 | private: 55 | int m, s; // size and number of support points 56 | T q0[D]; 57 | 58 | T z[D+1]; 59 | T f[D+1]; 60 | T v[D+1][D]; 61 | T a[D+1][D]; 62 | 63 | T c[D+1][D]; 64 | T sqr_r[D+1]; 65 | 66 | T *current_c; // points to some c[j] 67 | T current_sqr_r; 68 | 69 | public: 70 | const T *center() const { return current_c; } 71 | T squared_radius() const { return current_sqr_r; } 72 | int size() const { return m; } 73 | T excess(const Vec &p) const; 74 | void reset(); // generates empty sphere with m=s=0 75 | bool push(const Vec &p); 76 | void pop(); 77 | }; 78 | 79 | 80 | // Class for hoding and computing the bounding sphere 81 | template 82 | class Miniball { 83 | public: 84 | typedef typename std::list< Vec >::iterator It; 85 | 86 | private: 87 | std::list< Vec > L;// STL list keeping the points 88 | Basis B; // basis keeping the current ball 89 | It support_end; // past-the-end iterator of support set 90 | 91 | void move_to_front(It j); 92 | T max_excess(It t, It i, It &pivot) const; 93 | void mtf_mb(It k); 94 | void pivot_mb(It k); 95 | 96 | public: 97 | void check_in(const Vec &p) { L.push_back(p); } 98 | template 99 | void check_in(I first, I last) { L.insert(L.end(), first, last); } 100 | void build(bool pivoting = true); 101 | Vec center() const { return Vec(B.center()); } 102 | T squared_radius() const { return B.squared_radius(); } 103 | }; 104 | 105 | 106 | template 107 | T Basis::excess(const Vec &p) const 108 | { 109 | T e = -current_sqr_r; 110 | for (int k = 0; k < D; k++) 111 | e += sqr(p[k] - current_c[k]); 112 | return e; 113 | } 114 | 115 | 116 | template 117 | void Basis::reset() 118 | { 119 | m = s = 0; 120 | // we misuse c[0] for the center of the empty sphere 121 | for (int j = 0; j < D; j++) 122 | c[0][j] = 0; 123 | current_c = c[0]; 124 | current_sqr_r = -1; 125 | } 126 | 127 | 128 | template 129 | bool Basis::push(const Vec &p) 130 | { 131 | int i, j; 132 | const T eps = T(1.0e-13); 133 | if (m == 0) { 134 | for (i = 0; i < D; i++) 135 | q0[i] = p[i]; 136 | for (i = 0; i < D; i++) 137 | c[0][i] = q0[i]; 138 | sqr_r[0] = 0; 139 | } else { 140 | // set v_m to Q_m 141 | for (i = 0; i < D; i++) 142 | v[m][i] = p[i] - q0[i]; 143 | 144 | // compute the a_{m,i}, i < m 145 | for (i = 1; i < m; i++) { 146 | a[m][i] = 0; 147 | for (j = 0; j < D; j++) 148 | a[m][i] += v[i][j] * v[m][j]; 149 | a[m][i] *= (T(2) / z[i]); 150 | } 151 | 152 | // update v_m to Q_m-\bar{Q}_m 153 | for (i = 1; i < m; i++) { 154 | for (j = 0; j < D; j++) 155 | v[m][j] -= a[m][i] * v[i][j]; 156 | } 157 | 158 | // compute z_m 159 | z[m] = 0; 160 | for (j = 0; j < D; j++) 161 | z[m] += sqr(v[m][j]); 162 | z[m] *= T(2); 163 | 164 | // reject push if z_m too small 165 | if (z[m] < eps*current_sqr_r) 166 | return false; 167 | 168 | // update c, sqr_r 169 | T e = -sqr_r[m-1]; 170 | for (i = 0; i < D; i++) 171 | e += sqr(p[i] - c[m-1][i]); 172 | f[m] = e / z[m]; 173 | 174 | for (i = 0; i < D; i++) 175 | c[m][i] = c[m-1][i] + f[m]*v[m][i]; 176 | sqr_r[m] = sqr_r[m-1] + e*f[m]*T(0.5); 177 | } 178 | current_c = c[m]; 179 | current_sqr_r = sqr_r[m]; 180 | s = ++m; 181 | return true; 182 | } 183 | 184 | 185 | template 186 | void Basis::pop() 187 | { 188 | m--; 189 | } 190 | 191 | 192 | template 193 | void Miniball::move_to_front(It j) 194 | { 195 | if (support_end == j) 196 | support_end++; 197 | L.splice(L.begin(), L, j); 198 | } 199 | 200 | 201 | template 202 | T Miniball::max_excess(It t, It i, It &pivot) const 203 | { 204 | const T *c = B.center(), sqr_r = B.squared_radius(); 205 | T e, max_e = 0; 206 | for (It k = t; k != i; k++) { 207 | const Vec &p = *k; 208 | e = -sqr_r; 209 | for (int j = 0; j < D; j++) 210 | e += sqr(p[j] - c[j]); 211 | if (e > max_e) { 212 | max_e = e; 213 | pivot = k; 214 | } 215 | } 216 | return max_e; 217 | } 218 | 219 | 220 | template 221 | void Miniball::mtf_mb(It i) 222 | { 223 | support_end = L.begin(); 224 | if (B.size() == D+1) 225 | return; 226 | for (It k = L.begin(); k != i; ) { 227 | It j = k++; 228 | if (B.excess(*j) > 0) { 229 | if (B.push(*j)) { 230 | mtf_mb(j); 231 | B.pop(); 232 | move_to_front(j); 233 | } 234 | } 235 | } 236 | } 237 | 238 | 239 | template 240 | void Miniball::pivot_mb(It i) 241 | { 242 | It t = ++L.begin(); 243 | mtf_mb(t); 244 | T max_e, old_sqr_r = T(0); 245 | do { 246 | It pivot; 247 | max_e = max_excess(t, i, pivot); 248 | if (max_e > 0) { 249 | t = support_end; 250 | if (t == pivot) 251 | t++; 252 | old_sqr_r = B.squared_radius(); 253 | B.push(*pivot); 254 | mtf_mb(support_end); 255 | B.pop(); 256 | move_to_front(pivot); 257 | } 258 | } while (max_e > 0 && B.squared_radius() > old_sqr_r); 259 | } 260 | 261 | template 262 | void Miniball::build(bool pivoting /* = true */) 263 | { 264 | B.reset(); 265 | support_end = L.begin(); 266 | if (pivoting) 267 | pivot_mb(L.end()); 268 | else 269 | mtf_mb(L.end()); 270 | } 271 | 272 | #endif 273 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/trimeshview/include/mempool.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Copyright (c) 2014 Zhang Dongdong 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | **************************************************************************/ 17 | #ifndef MEMPOOL_H 18 | #define MEMPOOL_H 19 | /* 20 | Szymon Rusinkiewicz 21 | Princeton University 22 | 23 | mempool.h 24 | Replacement memory management for a class using a memory pool. 25 | 26 | Sample usage: 27 | class MyClass { 28 | private: 29 | static PoolAlloc memPool; 30 | public: 31 | void *operator new(size_t n) { return memPool.alloc(n); } 32 | void operator delete(void *p, size_t n) { memPool.free(p,n); } 33 | // ... 34 | }; 35 | 36 | PoolAlloc MyClass::memPool(sizeof(MyClass)); 37 | 38 | Does *no* error checking. 39 | Make sure sizeof(MyClass) is larger than sizeof(void *). 40 | Based on the description of the Pool class in _Effective C++_ by Scott Meyers. 41 | */ 42 | 43 | #include 44 | #include 45 | 46 | #define POOL_MEMBLOCK 4088 47 | 48 | 49 | class PoolAlloc { 50 | private: 51 | size_t itemsize; 52 | void *freelist; 53 | void grow_freelist() 54 | { 55 | size_t n = POOL_MEMBLOCK / itemsize; 56 | freelist = ::operator new(n * itemsize); 57 | for (size_t i = 0; i < n-1; i++) 58 | *(void **)((char *)freelist + itemsize*i) = 59 | (char *)freelist + itemsize*(i+1); 60 | *(void **)((char *)freelist + itemsize*(n-1)) = 0; 61 | } 62 | 63 | public: 64 | PoolAlloc(size_t size) : itemsize(size), freelist(0) {} 65 | void *alloc(size_t n) 66 | { 67 | if (n != itemsize) 68 | return ::operator new(n); 69 | if (!freelist) 70 | grow_freelist(); 71 | void *next = freelist; 72 | freelist = *(void **)next; 73 | return next; 74 | } 75 | void free(void *p, size_t n) 76 | { 77 | if (!p) 78 | return; 79 | else if (n != itemsize) 80 | ::operator delete(p); 81 | else { 82 | *(void **)p = freelist; 83 | freelist = p; 84 | } 85 | } 86 | void sort_freelist() 87 | { 88 | if (!freelist) 89 | return; 90 | std::vector v; 91 | void *p; 92 | for (p = freelist; *(void **)p; p = *(void **)p) 93 | v.push_back(p); 94 | std::sort(v.begin(), v.end()); 95 | p = freelist = v[0]; 96 | for (size_t i = 1; i < v.size(); i++) { 97 | *(void **)p = v[i]; 98 | p = *(void **)p; 99 | } 100 | *(void **)p = NULL; 101 | } 102 | }; 103 | 104 | #endif 105 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/trimeshview/include/strutil.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Copyright (c) 2014 Zhang Dongdong 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | **************************************************************************/ 17 | #ifndef STRUTIL_H 18 | #define STRUTIL_H 19 | /* 20 | Szymon Rusinkiewicz 21 | Princeton University 22 | 23 | strutil.h 24 | Miscellaneous string-manipulation utilities 25 | 26 | Usage: 27 | std::string s("foo.bar"); 28 | std::string s2 = replace_ext(s, "baz"); // "foo.baz" 29 | begins_with("Foobar", "foo") // true 30 | ends_with("foobar", "baz") // false 31 | */ 32 | 33 | 34 | #include 35 | #include 36 | 37 | #ifdef _WIN32 38 | # ifndef strncasecmp 39 | # define strncasecmp _strnicmp 40 | # endif 41 | #endif 42 | 43 | 44 | // Replace the extension of a filename, else add one if none present 45 | static inline std::string replace_ext(const std::string &filename, 46 | const std::string &ext) 47 | { 48 | std::string x = filename; 49 | std::string::size_type dot = x.rfind(".", x.length()); 50 | if (dot != std::string::npos) 51 | x.erase(dot); 52 | return x + std::string(".") + ext; 53 | } 54 | 55 | 56 | // Does string s1 begin/end with s2? (Case-insensitive) 57 | static inline bool begins_with(const char *s1, const char *s2) 58 | { 59 | using namespace std; 60 | return !strncasecmp(s1, s2, strlen(s2)); 61 | } 62 | 63 | static inline bool begins_with(const std::string &s1, const std::string &s2) 64 | { 65 | return begins_with(s1.c_str(), s2.c_str()); 66 | } 67 | 68 | static inline bool ends_with(const char *s1, const char *s2) 69 | { 70 | using namespace std; 71 | size_t l1 = strlen(s1), l2 = strlen(s2); 72 | return (l1 >= l2) && !strncasecmp(s1 + l1 - l2, s2, l2); 73 | } 74 | 75 | static inline bool ends_with(const std::string &s1, const std::string &s2) 76 | { 77 | return ends_with(s1.c_str(), s2.c_str()); 78 | } 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/trimeshview/include/timestamp.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Copyright (c) 2014 Zhang Dongdong 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | **************************************************************************/ 17 | #ifndef TIMESTAMP_H 18 | #define TIMESTAMP_H 19 | /* 20 | Szymon Rusinkiewicz 21 | Princeton University 22 | 23 | timestamp.h 24 | Wrapper around system-specific timestamps. 25 | */ 26 | 27 | 28 | #ifdef _WIN32 29 | 30 | # define WIN32_LEAN_AND_MEAN 31 | # include 32 | # include 33 | # define usleep(x) Sleep((x)/1000) 34 | 35 | struct timestamp { LARGE_INTEGER t; }; 36 | 37 | static inline double LI2d(const LARGE_INTEGER &li) 38 | { 39 | // Work around random compiler bugs... 40 | double d = li.HighPart; 41 | d *= 65536.0 * 65536.0; 42 | d += *(unsigned long *)(&(li.LowPart)); 43 | return d; 44 | } 45 | 46 | static inline float operator - (const timestamp &t1, const timestamp &t2) 47 | { 48 | static LARGE_INTEGER PerformanceFrequency; 49 | static int status = QueryPerformanceFrequency(&PerformanceFrequency); 50 | if (status == 0) return 1.0f; 51 | 52 | return float((LI2d(t1.t) - LI2d(t2.t)) / LI2d(PerformanceFrequency)); 53 | } 54 | 55 | static inline timestamp now() 56 | { 57 | timestamp t; 58 | QueryPerformanceCounter(&t.t); 59 | return t; 60 | } 61 | 62 | #else 63 | 64 | # include 65 | # include 66 | 67 | typedef struct timeval timestamp; 68 | 69 | static inline float operator - (const timestamp &t1, const timestamp &t2) 70 | { 71 | return (float)(t1.tv_sec - t2.tv_sec) + 72 | 1.0e-6f*(t1.tv_usec - t2.tv_usec); 73 | } 74 | 75 | static inline timestamp now() 76 | { 77 | timestamp t; 78 | gettimeofday(&t, 0); 79 | return t; 80 | } 81 | 82 | #endif 83 | 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/trimeshview/include/trianglemesh.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zddhub/opensse/9611503bd09009cd5319f15cac8511dfb7d7b388/gui/SketchSearchDemo/trimeshview/include/trianglemesh.h -------------------------------------------------------------------------------- /gui/SketchSearchDemo/trimeshview/trianglemesh/trianglemesh_bounding.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Copyright (c) 2014 Zhang Dongdong 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | **************************************************************************/ 17 | 18 | #include "trianglemesh.h" 19 | #include "bsphere.h" 20 | using namespace std; 21 | 22 | 23 | 24 | //use the Miniball code 25 | 26 | 27 | // Compute bounding sphere of the vertices. 28 | void TriangleMesh::need_bsphere() 29 | { 30 | if (vertices.empty() || bsphere.valid) 31 | return; 32 | 33 | dprintf("Computing bounding sphere... "); 34 | 35 | Miniball<3,float> mb; 36 | mb.check_in(vertices.begin(), vertices.end()); 37 | mb.build(); 38 | bsphere.center = mb.center(); 39 | bsphere.r = sqrt(mb.squared_radius()); 40 | bsphere.valid = true; 41 | 42 | dprintf("Done.\n center = (%g, %g, %g), radius = %g\n", 43 | bsphere.center[0], bsphere.center[1], 44 | bsphere.center[2], bsphere.r); 45 | } 46 | 47 | 48 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/trimeshview/trianglemesh/trianglemesh_connectivity.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zddhub/opensse/9611503bd09009cd5319f15cac8511dfb7d7b388/gui/SketchSearchDemo/trimeshview/trianglemesh/trianglemesh_connectivity.cpp -------------------------------------------------------------------------------- /gui/SketchSearchDemo/trimeshview/trianglemesh/trianglemesh_curvature.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zddhub/opensse/9611503bd09009cd5319f15cac8511dfb7d7b388/gui/SketchSearchDemo/trimeshview/trianglemesh/trianglemesh_curvature.cpp -------------------------------------------------------------------------------- /gui/SketchSearchDemo/trimeshview/trianglemesh/trianglemesh_io.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zddhub/opensse/9611503bd09009cd5319f15cac8511dfb7d7b388/gui/SketchSearchDemo/trimeshview/trianglemesh/trianglemesh_io.cpp -------------------------------------------------------------------------------- /gui/SketchSearchDemo/trimeshview/trianglemesh/trianglemesh_normals.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Copyright (c) 2014 Zhang Dongdong 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | **************************************************************************/ 17 | /* 18 | Szymon Rusinkiewicz 19 | Princeton University 20 | 21 | TriMesh_normals.cc 22 | Compute per-vertex normals for TriMeshes 23 | 24 | For meshes, uses average of per-face normals, weighted according to: 25 | Max, N. 26 | "Weights for Computing Vertex Normals from Facet Normals," 27 | Journal of Graphics Tools, Vol. 4, No. 2, 1999. 28 | 29 | For raw point clouds, fits plane to k nearest neighbors. 30 | */ 31 | 32 | 33 | #include "trianglemesh.h" 34 | #include "KDtree.h" 35 | #include "lineqn.h" 36 | using namespace std; 37 | 38 | 39 | void TriangleMesh::need_normals() 40 | { 41 | // Nothing to do if we already have normals 42 | int nv = vertices.size(); 43 | if (int(normals.size()) == nv) 44 | return; 45 | 46 | dprintf("Computing normals... "); 47 | normals.clear(); 48 | normals.resize(nv); 49 | 50 | // TODO: direct handling of grids 51 | if (!tstrips.empty()) { 52 | // Compute from tstrips 53 | const int *t = &tstrips[0], *end = t + tstrips.size(); 54 | while (likely(t < end)) { 55 | int striplen = *t - 2; 56 | t += 3; 57 | bool flip = false; 58 | for (int i = 0; i < striplen; i++, t++, flip = !flip) { 59 | const point &p0 = vertices[*(t-2)]; 60 | const point &p1 = vertices[*(t-1)]; 61 | const point &p2 = vertices[* t ]; 62 | vec a = p0-p1, b = p1-p2, c = p2-p0; 63 | float l2a = len2(a), l2b = len2(b), l2c = len2(c); 64 | vec facenormal = flip ? (b CROSS a) : (a CROSS b); 65 | normals[*(t-2)] += facenormal * (1.0f / (l2a * l2c)); 66 | normals[*(t-1)] += facenormal * (1.0f / (l2b * l2a)); 67 | normals[* t ] += facenormal * (1.0f / (l2c * l2b)); 68 | } 69 | } 70 | } else if (need_faces(), !faces.empty()) { 71 | // Compute from faces 72 | int nf = faces.size(); 73 | #pragma omp parallel for 74 | for (int i = 0; i < nf; i++) { 75 | const point &p0 = vertices[faces[i][0]]; 76 | const point &p1 = vertices[faces[i][1]]; 77 | const point &p2 = vertices[faces[i][2]]; 78 | vec a = p0-p1, b = p1-p2, c = p2-p0; 79 | float l2a = len2(a), l2b = len2(b), l2c = len2(c); 80 | vec facenormal = a CROSS b; 81 | normals[faces[i][0]] += facenormal * (1.0f / (l2a * l2c)); 82 | normals[faces[i][1]] += facenormal * (1.0f / (l2b * l2a)); 83 | normals[faces[i][2]] += facenormal * (1.0f / (l2c * l2b)); 84 | } 85 | } else { 86 | // Find normals of a point cloud 87 | const int k = 6; 88 | const vec ref(0, 0, 1); 89 | KDtree kd(vertices); 90 | #pragma omp parallel for 91 | for (int i = 0; i < nv; i++) { 92 | vector knn; 93 | kd.find_k_closest_to_pt(knn, k, vertices[i]); 94 | int actual_k = knn.size(); 95 | if (actual_k < 3) { 96 | dprintf("Warning: not enough points for vertex %d\n", i); 97 | normals[i] = ref; 98 | continue; 99 | } 100 | // Compute covariance 101 | float C[3][3] = { {0,0,0}, {0,0,0}, {0,0,0} }; 102 | // The below loop starts at 1, since element 0 103 | // is just vertices[i] itself 104 | for (int j = 1; j < actual_k; j++) { 105 | vec d = point(knn[j]) - vertices[i]; 106 | for (int l = 0; l < 3; l++) 107 | for (int m = 0; m < 3; m++) 108 | C[l][m] += d[l] * d[m]; 109 | } 110 | float e[3]; 111 | eigdc(C, e); 112 | normals[i] = vec(C[0][0], C[1][0], C[2][0]); 113 | if ((normals[i] DOT ref) < 0.0f) 114 | normals[i] = -normals[i]; 115 | } 116 | } 117 | 118 | // Make them all unit-length 119 | #pragma omp parallel for 120 | for (int i = 0; i < nv; i++) 121 | normalize(normals[i]); 122 | 123 | dprintf("Done.\n"); 124 | } 125 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/trimeshview/trianglemesh/trianglemesh_pointareas.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Copyright (c) 2014 Zhang Dongdong 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | **************************************************************************/ 17 | /* 18 | Szymon Rusinkiewicz 19 | Princeton University 20 | 21 | TriMesh_pointareas.cc 22 | Compute the area "belonging" to each vertex or each corner 23 | of a triangle (defined as Voronoi area restricted to the 1-ring of 24 | a vertex, or to the triangle). 25 | 26 | for more voronoi area, see 27 | Meyer M., Discrete differential geometry operators for triangulated 2-manifolds 28 | */ 29 | 30 | 31 | #include "trianglemesh.h" 32 | 33 | // Compute per-vertex point areas 34 | void TriangleMesh::need_pointareas() 35 | { 36 | if (pointareas.size() == vertices.size()) 37 | return; 38 | need_faces(); 39 | 40 | dprintf("Computing point areas... "); 41 | 42 | int nf = faces.size(), nv = vertices.size(); 43 | pointareas.clear(); 44 | pointareas.resize(nv); 45 | cornerareas.clear(); 46 | cornerareas.resize(nf); 47 | 48 | #pragma omp parallel for 49 | for (int i = 0; i < nf; i++) { 50 | // Edges 51 | vec e[3] = { vertices[faces[i][2]] - vertices[faces[i][1]], 52 | vertices[faces[i][0]] - vertices[faces[i][2]], 53 | vertices[faces[i][1]] - vertices[faces[i][0]] }; 54 | 55 | // Compute corner weights 56 | float area = 0.5f * len(e[0] CROSS e[1]); 57 | float l2[3] = { len2(e[0]), len2(e[1]), len2(e[2]) }; 58 | float ew[3] = { l2[0] * (l2[1] + l2[2] - l2[0]), 59 | l2[1] * (l2[2] + l2[0] - l2[1]), 60 | l2[2] * (l2[0] + l2[1] - l2[2]) }; 61 | if (ew[0] <= 0.0f) { 62 | cornerareas[i][1] = -0.25f * l2[2] * area / 63 | (e[0] DOT e[2]); 64 | cornerareas[i][2] = -0.25f * l2[1] * area / 65 | (e[0] DOT e[1]); 66 | cornerareas[i][0] = area - cornerareas[i][1] - 67 | cornerareas[i][2]; 68 | } else if (ew[1] <= 0.0f) { 69 | cornerareas[i][2] = -0.25f * l2[0] * area / 70 | (e[1] DOT e[0]); 71 | cornerareas[i][0] = -0.25f * l2[2] * area / 72 | (e[1] DOT e[2]); 73 | cornerareas[i][1] = area - cornerareas[i][2] - 74 | cornerareas[i][0]; 75 | } else if (ew[2] <= 0.0f) { 76 | cornerareas[i][0] = -0.25f * l2[1] * area / 77 | (e[2] DOT e[1]); 78 | cornerareas[i][1] = -0.25f * l2[0] * area / 79 | (e[2] DOT e[0]); 80 | cornerareas[i][2] = area - cornerareas[i][0] - 81 | cornerareas[i][1]; 82 | } else { 83 | float ewscale = 0.5f * area / (ew[0] + ew[1] + ew[2]); 84 | for (int j = 0; j < 3; j++) 85 | cornerareas[i][j] = ewscale * (ew[(j+1)%3] + 86 | ew[(j+2)%3]); 87 | } 88 | #pragma omp atomic 89 | pointareas[faces[i][0]] += cornerareas[i][0]; 90 | #pragma omp atomic 91 | pointareas[faces[i][1]] += cornerareas[i][1]; 92 | #pragma omp atomic 93 | pointareas[faces[i][2]] += cornerareas[i][2]; 94 | } 95 | 96 | dprintf("Done.\n"); 97 | } 98 | 99 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/trimeshview/trianglemesh/trianglemesh_stats.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Copyright (c) 2014 Zhang Dongdong 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | **************************************************************************/ 17 | 18 | #include "trianglemesh.h" 19 | #include 20 | #include 21 | using namespace std; 22 | 23 | // A characteristic "feature size" for the mesh. Computed as an approximation 24 | // to the median edge length 25 | float TriangleMesh::feature_size() 26 | { 27 | need_faces(); 28 | if (faces.empty()) 29 | return 0.0f; 30 | 31 | int nf = faces.size(); 32 | int nsamp = min(nf / 2, 333); 33 | 34 | vector samples; 35 | samples.reserve(nsamp * 3); 36 | 37 | for (int i = 0; i < nsamp; i++) { 38 | // Quick 'n dirty portable random number generator 39 | static unsigned randq = 0; 40 | randq = unsigned(1664525) * randq + unsigned(1013904223); 41 | 42 | int ind = randq % nf; 43 | const point &p0 = vertices[faces[ind][0]]; 44 | const point &p1 = vertices[faces[ind][1]]; 45 | const point &p2 = vertices[faces[ind][2]]; 46 | samples.push_back(dist2(p0,p1)); 47 | samples.push_back(dist2(p1,p2)); 48 | samples.push_back(dist2(p2,p0)); 49 | } 50 | nth_element(samples.begin(), 51 | samples.begin() + samples.size()/2, 52 | samples.end()); 53 | return sqrt(samples[samples.size()/2]); 54 | } 55 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/trimeshview/trianglemesh/trianglemesh_tstrips.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zddhub/opensse/9611503bd09009cd5319f15cac8511dfb7d7b388/gui/SketchSearchDemo/trimeshview/trianglemesh/trianglemesh_tstrips.cpp -------------------------------------------------------------------------------- /gui/SketchSearchDemo/trimeshview/trimeshview.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zddhub/opensse/9611503bd09009cd5319f15cac8511dfb7d7b388/gui/SketchSearchDemo/trimeshview/trimeshview.cpp -------------------------------------------------------------------------------- /gui/SketchSearchDemo/trimeshview/trimeshview.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zddhub/opensse/9611503bd09009cd5319f15cac8511dfb7d7b388/gui/SketchSearchDemo/trimeshview/trimeshview.h -------------------------------------------------------------------------------- /gui/SketchSearchDemo/trimeshview/trimeshview.pri: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) 2014 Zhang Dongdong 3 | # All rights reserved. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | #------------------------------------------------------------------------- 17 | 18 | INCLUDEPATH += $$PWD \ 19 | $$PWD/include 20 | 21 | HEADERS += \ 22 | trimeshview/trimeshview.h 23 | 24 | SOURCES += \ 25 | trimeshview/trimeshview.cpp \ 26 | trimeshview/trimeshview_draw_ridges_and_valleys.cpp \ 27 | trimeshview/trimeshview_draw_lines.cpp \ 28 | trimeshview/trimeshview_draw_base.cpp \ 29 | trimeshview/trimeshview_draw_apparent_ridges.cpp \ 30 | trimeshview/trianglemesh/trianglemesh_tstrips.cpp \ 31 | trimeshview/trianglemesh/trianglemesh_stats.cpp \ 32 | trimeshview/trianglemesh/trianglemesh_pointareas.cpp \ 33 | trimeshview/trianglemesh/trianglemesh_normals.cpp \ 34 | trimeshview/trianglemesh/trianglemesh_io.cpp \ 35 | trimeshview/trianglemesh/trianglemesh_curvature.cpp \ 36 | trimeshview/trianglemesh/trianglemesh_connectivity.cpp \ 37 | trimeshview/trianglemesh/trianglemesh_bounding.cpp \ 38 | trimeshview/trianglemesh/KDtree.cpp \ 39 | trimeshview/trianglemesh/GLCamera.cpp 40 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/trimeshview/trimeshview_draw_base.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zddhub/opensse/9611503bd09009cd5319f15cac8511dfb7d7b388/gui/SketchSearchDemo/trimeshview/trimeshview_draw_base.cpp -------------------------------------------------------------------------------- /gui/SketchSearchDemo/trimeshview/trimeshview_draw_lines.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zddhub/opensse/9611503bd09009cd5319f15cac8511dfb7d7b388/gui/SketchSearchDemo/trimeshview/trimeshview_draw_lines.cpp -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/0.xf: -------------------------------------------------------------------------------- 1 | 1 0 0 0 2 | 0 1 0 0 3 | -0 0 1 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/1.xf: -------------------------------------------------------------------------------- 1 | 0.95106 0 0.30902 0 2 | 0 1 0 0 3 | -0.30902 0 0.95106 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/10.xf: -------------------------------------------------------------------------------- 1 | -1 0 1.2246e-016 0 2 | 0 1 0 0 3 | -1.2246e-016 0 -1 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/100.xf: -------------------------------------------------------------------------------- 1 | 1 -2.4493e-016 -1.4998e-032 0 2 | 0 6.1232e-017 -1 0 3 | 2.4493e-016 1 6.1232e-017 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/101.xf: -------------------------------------------------------------------------------- 1 | 1 2.4493e-016 -1.4998e-032 0 2 | 0 6.1232e-017 1 0 3 | 2.4493e-016 -1 6.1232e-017 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/11.xf: -------------------------------------------------------------------------------- 1 | -0.95106 0 -0.30902 0 2 | 0 1 0 0 3 | 0.30902 0 -0.95106 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/12.xf: -------------------------------------------------------------------------------- 1 | -0.80902 0 -0.58779 0 2 | 0 1 0 0 3 | 0.58779 0 -0.80902 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/13.xf: -------------------------------------------------------------------------------- 1 | -0.58779 0 -0.80902 0 2 | 0 1 0 0 3 | 0.80902 0 -0.58779 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/14.xf: -------------------------------------------------------------------------------- 1 | -0.30902 0 -0.95106 0 2 | 0 1 0 0 3 | 0.95106 0 -0.30902 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/15.xf: -------------------------------------------------------------------------------- 1 | -1.837e-016 0 -1 0 2 | 0 1 0 0 3 | 1 0 -1.837e-016 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/16.xf: -------------------------------------------------------------------------------- 1 | 0.30902 0 -0.95106 0 2 | 0 1 0 0 3 | 0.95106 0 0.30902 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/17.xf: -------------------------------------------------------------------------------- 1 | 0.58779 0 -0.80902 0 2 | 0 1 0 0 3 | 0.80902 0 0.58779 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/18.xf: -------------------------------------------------------------------------------- 1 | 0.80902 0 -0.58779 0 2 | 0 1 0 0 3 | 0.58779 0 0.80902 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/19.xf: -------------------------------------------------------------------------------- 1 | 0.95106 0 -0.30902 0 2 | 0 1 0 0 3 | 0.30902 0 0.95106 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/2.xf: -------------------------------------------------------------------------------- 1 | 0.80902 0 0.58779 0 2 | 0 1 0 0 3 | -0.58779 0 0.80902 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/20.xf: -------------------------------------------------------------------------------- 1 | 1 0 0 0 2 | 0 0.86603 -0.5 0 3 | 0 0.5 0.86603 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/21.xf: -------------------------------------------------------------------------------- 1 | 0.95106 0.15451 0.26762 0 2 | 0 0.86603 -0.5 0 3 | -0.30902 0.47553 0.82364 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/22.xf: -------------------------------------------------------------------------------- 1 | 0.80902 0.29389 0.50904 0 2 | 0 0.86603 -0.5 0 3 | -0.58779 0.40451 0.70063 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/23.xf: -------------------------------------------------------------------------------- 1 | 0.58779 0.40451 0.70063 0 2 | 0 0.86603 -0.5 0 3 | -0.80902 0.29389 0.50904 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/24.xf: -------------------------------------------------------------------------------- 1 | 0.30902 0.47553 0.82364 0 2 | 0 0.86603 -0.5 0 3 | -0.95106 0.15451 0.26762 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/25.xf: -------------------------------------------------------------------------------- 1 | 6.1232e-017 0.5 0.86603 0 2 | 0 0.86603 -0.5 0 3 | -1 3.0616e-017 5.3029e-017 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/26.xf: -------------------------------------------------------------------------------- 1 | -0.30902 0.47553 0.82364 0 2 | 0 0.86603 -0.5 0 3 | -0.95106 -0.15451 -0.26762 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/27.xf: -------------------------------------------------------------------------------- 1 | -0.58779 0.40451 0.70063 0 2 | 0 0.86603 -0.5 0 3 | -0.80902 -0.29389 -0.50904 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/28.xf: -------------------------------------------------------------------------------- 1 | -0.80902 0.29389 0.50904 0 2 | 0 0.86603 -0.5 0 3 | -0.58779 -0.40451 -0.70063 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/29.xf: -------------------------------------------------------------------------------- 1 | -0.95106 0.15451 0.26762 0 2 | 0 0.86603 -0.5 0 3 | -0.30902 -0.47553 -0.82364 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/3.xf: -------------------------------------------------------------------------------- 1 | 0.58779 0 0.80902 0 2 | 0 1 0 0 3 | -0.80902 0 0.58779 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/30.xf: -------------------------------------------------------------------------------- 1 | -1 6.1232e-017 1.0606e-016 0 2 | 0 0.86603 -0.5 0 3 | -1.2246e-016 -0.5 -0.86603 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/31.xf: -------------------------------------------------------------------------------- 1 | -0.95106 -0.15451 -0.26762 0 2 | 0 0.86603 -0.5 0 3 | 0.30902 -0.47553 -0.82364 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/32.xf: -------------------------------------------------------------------------------- 1 | -0.80902 -0.29389 -0.50904 0 2 | 0 0.86603 -0.5 0 3 | 0.58779 -0.40451 -0.70063 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/33.xf: -------------------------------------------------------------------------------- 1 | -0.58779 -0.40451 -0.70063 0 2 | 0 0.86603 -0.5 0 3 | 0.80902 -0.29389 -0.50904 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/34.xf: -------------------------------------------------------------------------------- 1 | -0.30902 -0.47553 -0.82364 0 2 | 0 0.86603 -0.5 0 3 | 0.95106 -0.15451 -0.26762 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/35.xf: -------------------------------------------------------------------------------- 1 | -1.837e-016 -0.5 -0.86603 0 2 | 0 0.86603 -0.5 0 3 | 1 -9.1849e-017 -1.5909e-016 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/36.xf: -------------------------------------------------------------------------------- 1 | 0.30902 -0.47553 -0.82364 0 2 | 0 0.86603 -0.5 0 3 | 0.95106 0.15451 0.26762 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/37.xf: -------------------------------------------------------------------------------- 1 | 0.58779 -0.40451 -0.70063 0 2 | 0 0.86603 -0.5 0 3 | 0.80902 0.29389 0.50904 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/38.xf: -------------------------------------------------------------------------------- 1 | 0.80902 -0.29389 -0.50904 0 2 | 0 0.86603 -0.5 0 3 | 0.58779 0.40451 0.70063 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/39.xf: -------------------------------------------------------------------------------- 1 | 0.95106 -0.15451 -0.26762 0 2 | 0 0.86603 -0.5 0 3 | 0.30902 0.47553 0.82364 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/4.xf: -------------------------------------------------------------------------------- 1 | 0.30902 0 0.95106 0 2 | 0 1 0 0 3 | -0.95106 0 0.30902 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/40.xf: -------------------------------------------------------------------------------- 1 | 1 0 0 0 2 | 0 0.5 -0.86603 0 3 | 0 0.86603 0.5 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/41.xf: -------------------------------------------------------------------------------- 1 | 0.95106 0.26762 0.15451 0 2 | 0 0.5 -0.86603 0 3 | -0.30902 0.82364 0.47553 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/42.xf: -------------------------------------------------------------------------------- 1 | 0.80902 0.50904 0.29389 0 2 | 0 0.5 -0.86603 0 3 | -0.58779 0.70063 0.40451 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/43.xf: -------------------------------------------------------------------------------- 1 | 0.58779 0.70063 0.40451 0 2 | 0 0.5 -0.86603 0 3 | -0.80902 0.50904 0.29389 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/44.xf: -------------------------------------------------------------------------------- 1 | 0.30902 0.82364 0.47553 0 2 | 0 0.5 -0.86603 0 3 | -0.95106 0.26762 0.15451 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/45.xf: -------------------------------------------------------------------------------- 1 | 6.1232e-017 0.86603 0.5 0 2 | 0 0.5 -0.86603 0 3 | -1 5.3029e-017 3.0616e-017 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/46.xf: -------------------------------------------------------------------------------- 1 | -0.30902 0.82364 0.47553 0 2 | 0 0.5 -0.86603 0 3 | -0.95106 -0.26762 -0.15451 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/47.xf: -------------------------------------------------------------------------------- 1 | -0.58779 0.70063 0.40451 0 2 | 0 0.5 -0.86603 0 3 | -0.80902 -0.50904 -0.29389 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/48.xf: -------------------------------------------------------------------------------- 1 | -0.80902 0.50904 0.29389 0 2 | 0 0.5 -0.86603 0 3 | -0.58779 -0.70063 -0.40451 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/49.xf: -------------------------------------------------------------------------------- 1 | -0.95106 0.26762 0.15451 0 2 | 0 0.5 -0.86603 0 3 | -0.30902 -0.82364 -0.47553 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/5.xf: -------------------------------------------------------------------------------- 1 | 6.1232e-017 0 1 0 2 | 0 1 0 0 3 | -1 0 6.1232e-017 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/50.xf: -------------------------------------------------------------------------------- 1 | -1 1.0606e-016 6.1232e-017 0 2 | 0 0.5 -0.86603 0 3 | -1.2246e-016 -0.86603 -0.5 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/51.xf: -------------------------------------------------------------------------------- 1 | -0.95106 -0.26762 -0.15451 0 2 | 0 0.5 -0.86603 0 3 | 0.30902 -0.82364 -0.47553 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/52.xf: -------------------------------------------------------------------------------- 1 | -0.80902 -0.50904 -0.29389 0 2 | 0 0.5 -0.86603 0 3 | 0.58779 -0.70063 -0.40451 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/53.xf: -------------------------------------------------------------------------------- 1 | -0.58779 -0.70063 -0.40451 0 2 | 0 0.5 -0.86603 0 3 | 0.80902 -0.50904 -0.29389 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/54.xf: -------------------------------------------------------------------------------- 1 | -0.30902 -0.82364 -0.47553 0 2 | 0 0.5 -0.86603 0 3 | 0.95106 -0.26762 -0.15451 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/55.xf: -------------------------------------------------------------------------------- 1 | -1.837e-016 -0.86603 -0.5 0 2 | 0 0.5 -0.86603 0 3 | 1 -1.5909e-016 -9.1849e-017 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/56.xf: -------------------------------------------------------------------------------- 1 | 0.30902 -0.82364 -0.47553 0 2 | 0 0.5 -0.86603 0 3 | 0.95106 0.26762 0.15451 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/57.xf: -------------------------------------------------------------------------------- 1 | 0.58779 -0.70063 -0.40451 0 2 | 0 0.5 -0.86603 0 3 | 0.80902 0.50904 0.29389 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/58.xf: -------------------------------------------------------------------------------- 1 | 0.80902 -0.50904 -0.29389 0 2 | 0 0.5 -0.86603 0 3 | 0.58779 0.70063 0.40451 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/59.xf: -------------------------------------------------------------------------------- 1 | 0.95106 -0.26762 -0.15451 0 2 | 0 0.5 -0.86603 0 3 | 0.30902 0.82364 0.47553 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/6.xf: -------------------------------------------------------------------------------- 1 | -0.30902 0 0.95106 0 2 | 0 1 0 0 3 | -0.95106 0 -0.30902 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/60.xf: -------------------------------------------------------------------------------- 1 | 1 0 0 0 2 | 0 0.5 0.86603 0 3 | 0 -0.86603 0.5 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/61.xf: -------------------------------------------------------------------------------- 1 | 0.95106 -0.26762 0.15451 0 2 | 0 0.5 0.86603 0 3 | -0.30902 -0.82364 0.47553 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/62.xf: -------------------------------------------------------------------------------- 1 | 0.80902 -0.50904 0.29389 0 2 | 0 0.5 0.86603 0 3 | -0.58779 -0.70063 0.40451 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/63.xf: -------------------------------------------------------------------------------- 1 | 0.58779 -0.70063 0.40451 0 2 | 0 0.5 0.86603 0 3 | -0.80902 -0.50904 0.29389 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/64.xf: -------------------------------------------------------------------------------- 1 | 0.30902 -0.82364 0.47553 0 2 | 0 0.5 0.86603 0 3 | -0.95106 -0.26762 0.15451 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/65.xf: -------------------------------------------------------------------------------- 1 | 6.1232e-017 -0.86603 0.5 0 2 | 0 0.5 0.86603 0 3 | -1 -5.3029e-017 3.0616e-017 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/66.xf: -------------------------------------------------------------------------------- 1 | -0.30902 -0.82364 0.47553 0 2 | 0 0.5 0.86603 0 3 | -0.95106 0.26762 -0.15451 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/67.xf: -------------------------------------------------------------------------------- 1 | -0.58779 -0.70063 0.40451 0 2 | 0 0.5 0.86603 0 3 | -0.80902 0.50904 -0.29389 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/68.xf: -------------------------------------------------------------------------------- 1 | -0.80902 -0.50904 0.29389 0 2 | 0 0.5 0.86603 0 3 | -0.58779 0.70063 -0.40451 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/69.xf: -------------------------------------------------------------------------------- 1 | -0.95106 -0.26762 0.15451 0 2 | 0 0.5 0.86603 0 3 | -0.30902 0.82364 -0.47553 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/7.xf: -------------------------------------------------------------------------------- 1 | -0.58779 0 0.80902 0 2 | 0 1 0 0 3 | -0.80902 0 -0.58779 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/70.xf: -------------------------------------------------------------------------------- 1 | -1 -1.0606e-016 6.1232e-017 0 2 | 0 0.5 0.86603 0 3 | -1.2246e-016 0.86603 -0.5 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/71.xf: -------------------------------------------------------------------------------- 1 | -0.95106 0.26762 -0.15451 0 2 | 0 0.5 0.86603 0 3 | 0.30902 0.82364 -0.47553 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/72.xf: -------------------------------------------------------------------------------- 1 | -0.80902 0.50904 -0.29389 0 2 | 0 0.5 0.86603 0 3 | 0.58779 0.70063 -0.40451 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/73.xf: -------------------------------------------------------------------------------- 1 | -0.58779 0.70063 -0.40451 0 2 | 0 0.5 0.86603 0 3 | 0.80902 0.50904 -0.29389 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/74.xf: -------------------------------------------------------------------------------- 1 | -0.30902 0.82364 -0.47553 0 2 | 0 0.5 0.86603 0 3 | 0.95106 0.26762 -0.15451 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/75.xf: -------------------------------------------------------------------------------- 1 | -1.837e-016 0.86603 -0.5 0 2 | 0 0.5 0.86603 0 3 | 1 1.5909e-016 -9.1849e-017 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/76.xf: -------------------------------------------------------------------------------- 1 | 0.30902 0.82364 -0.47553 0 2 | 0 0.5 0.86603 0 3 | 0.95106 -0.26762 0.15451 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/77.xf: -------------------------------------------------------------------------------- 1 | 0.58779 0.70063 -0.40451 0 2 | 0 0.5 0.86603 0 3 | 0.80902 -0.50904 0.29389 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/78.xf: -------------------------------------------------------------------------------- 1 | 0.80902 0.50904 -0.29389 0 2 | 0 0.5 0.86603 0 3 | 0.58779 -0.70063 0.40451 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/79.xf: -------------------------------------------------------------------------------- 1 | 0.95106 0.26762 -0.15451 0 2 | 0 0.5 0.86603 0 3 | 0.30902 -0.82364 0.47553 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/8.xf: -------------------------------------------------------------------------------- 1 | -0.80902 0 0.58779 0 2 | 0 1 0 0 3 | -0.58779 0 -0.80902 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/80.xf: -------------------------------------------------------------------------------- 1 | 1 0 0 0 2 | 0 0.86603 0.5 0 3 | 0 -0.5 0.86603 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/81.xf: -------------------------------------------------------------------------------- 1 | 0.95106 -0.15451 0.26762 0 2 | 0 0.86603 0.5 0 3 | -0.30902 -0.47553 0.82364 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/82.xf: -------------------------------------------------------------------------------- 1 | 0.80902 -0.29389 0.50904 0 2 | 0 0.86603 0.5 0 3 | -0.58779 -0.40451 0.70063 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/83.xf: -------------------------------------------------------------------------------- 1 | 0.58779 -0.40451 0.70063 0 2 | 0 0.86603 0.5 0 3 | -0.80902 -0.29389 0.50904 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/84.xf: -------------------------------------------------------------------------------- 1 | 0.30902 -0.47553 0.82364 0 2 | 0 0.86603 0.5 0 3 | -0.95106 -0.15451 0.26762 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/85.xf: -------------------------------------------------------------------------------- 1 | 6.1232e-017 -0.5 0.86603 0 2 | 0 0.86603 0.5 0 3 | -1 -3.0616e-017 5.3029e-017 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/86.xf: -------------------------------------------------------------------------------- 1 | -0.30902 -0.47553 0.82364 0 2 | 0 0.86603 0.5 0 3 | -0.95106 0.15451 -0.26762 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/87.xf: -------------------------------------------------------------------------------- 1 | -0.58779 -0.40451 0.70063 0 2 | 0 0.86603 0.5 0 3 | -0.80902 0.29389 -0.50904 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/88.xf: -------------------------------------------------------------------------------- 1 | -0.80902 -0.29389 0.50904 0 2 | 0 0.86603 0.5 0 3 | -0.58779 0.40451 -0.70063 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/89.xf: -------------------------------------------------------------------------------- 1 | -0.95106 -0.15451 0.26762 0 2 | 0 0.86603 0.5 0 3 | -0.30902 0.47553 -0.82364 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/9.xf: -------------------------------------------------------------------------------- 1 | -0.95106 0 0.30902 0 2 | 0 1 0 0 3 | -0.30902 0 -0.95106 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/90.xf: -------------------------------------------------------------------------------- 1 | -1 -6.1232e-017 1.0606e-016 0 2 | 0 0.86603 0.5 0 3 | -1.2246e-016 0.5 -0.86603 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/91.xf: -------------------------------------------------------------------------------- 1 | -0.95106 0.15451 -0.26762 0 2 | 0 0.86603 0.5 0 3 | 0.30902 0.47553 -0.82364 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/92.xf: -------------------------------------------------------------------------------- 1 | -0.80902 0.29389 -0.50904 0 2 | 0 0.86603 0.5 0 3 | 0.58779 0.40451 -0.70063 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/93.xf: -------------------------------------------------------------------------------- 1 | -0.58779 0.40451 -0.70063 0 2 | 0 0.86603 0.5 0 3 | 0.80902 0.29389 -0.50904 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/94.xf: -------------------------------------------------------------------------------- 1 | -0.30902 0.47553 -0.82364 0 2 | 0 0.86603 0.5 0 3 | 0.95106 0.15451 -0.26762 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/95.xf: -------------------------------------------------------------------------------- 1 | -1.837e-016 0.5 -0.86603 0 2 | 0 0.86603 0.5 0 3 | 1 9.1849e-017 -1.5909e-016 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/96.xf: -------------------------------------------------------------------------------- 1 | 0.30902 0.47553 -0.82364 0 2 | 0 0.86603 0.5 0 3 | 0.95106 -0.15451 0.26762 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/97.xf: -------------------------------------------------------------------------------- 1 | 0.58779 0.40451 -0.70063 0 2 | 0 0.86603 0.5 0 3 | 0.80902 -0.29389 0.50904 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/98.xf: -------------------------------------------------------------------------------- 1 | 0.80902 0.29389 -0.50904 0 2 | 0 0.86603 0.5 0 3 | 0.58779 -0.40451 0.70063 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /gui/SketchSearchDemo/view/99.xf: -------------------------------------------------------------------------------- 1 | 0.95106 0.15451 -0.26762 0 2 | 0 0.86603 0.5 0 3 | 0.30902 -0.47553 0.82364 0 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /opensse.h: -------------------------------------------------------------------------------- 1 | #ifndef OPENSSE_H 2 | #define OPENSSE_H 3 | 4 | #include "sse/common/distance.h" 5 | #include "sse/common/types.h" 6 | #include "sse/features/galif.h" 7 | #include "sse/index/invertedindex.h" 8 | #include "sse/io/filelist.h" 9 | #include "sse/io/reader_writer.h" 10 | #include "sse/io/json_parser.h" 11 | #include "sse/quantize/quantizer.h" 12 | #include "sse/vocabulary/kmeans_init.h" 13 | #include "sse/vocabulary/kmeans.h" 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /opensse.pri: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) 2014 Zhang Dongdong 3 | # All rights reserved. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | #------------------------------------------------------------------------- 17 | 18 | unix { 19 | 20 | INCLUDEPATH += $$PWD \ 21 | /usr/local/include 22 | 23 | LIBS += -L/usr/local/lib/ \ 24 | -lopencv_core -lopencv_imgproc -lopencv_imgcodecs -lopencv_highgui -lopencv_features2d -lopencv_ml 25 | } 26 | 27 | macx: { 28 | #for commind line 29 | CONFIG -= app_bundle 30 | } 31 | 32 | 33 | #start with $$PWD, so that they will appear in included project 34 | HEADERS += \ 35 | $$PWD/sse/common/types.h \ 36 | $$PWD/sse/features/feature.h \ 37 | $$PWD/sse/features/galif.h \ 38 | $$PWD/sse/features/detector.h \ 39 | $$PWD/sse/features/generator.h \ 40 | $$PWD/sse/features/util.h \ 41 | $$PWD/sse/io/filelist.h \ 42 | $$PWD/sse/io/reader_writer.h \ 43 | $$PWD/sse/common/distance.h \ 44 | $$PWD/sse/vocabulary/kmeans.h \ 45 | $$PWD/sse/vocabulary/kmeans_init.h \ 46 | $$PWD/sse/quantize/quantizer.h \ 47 | $$PWD/sse/index/invertedindex.h \ 48 | $$PWD/sse/index/tfidf.h 49 | 50 | SOURCES += \ 51 | $$PWD/sse/features/galif.cpp \ 52 | $$PWD/sse/features/detector.cpp \ 53 | $$PWD/sse/features/generator.cpp \ 54 | $$PWD/sse/features/util.cpp \ 55 | $$PWD/sse/io/filelist.cpp \ 56 | $$PWD/sse/io/reader_writer.cpp \ 57 | $$PWD/sse/quantize/quantizer.cpp \ 58 | $$PWD/sse/index/invertedindex.cpp \ 59 | $$PWD/sse/index/tfidf.cpp 60 | -------------------------------------------------------------------------------- /opensse.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) 2014 Zhang Dongdong 3 | # All rights reserved. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | #------------------------------------------------------------------------- 17 | TEMPLATE = subdirs 18 | 19 | SUBDIRS += \ 20 | #opensse.pri \ 21 | gui/SketchSearchDemo 22 | 23 | -------------------------------------------------------------------------------- /sse/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set( 2 | SOURCES 3 | io/filelist.cpp 4 | io/reader_writer.cpp 5 | io/json_parser.cpp 6 | features/util.cpp 7 | features/generator.cpp 8 | features/detector.cpp 9 | features/galif.cpp 10 | quantize/quantizer.cpp 11 | index/tfidf.cpp 12 | index/invertedindex.cpp 13 | ) 14 | 15 | add_library(opensse SHARED ${SOURCES}) 16 | target_link_libraries(opensse ${REQUIRED_LIB}) 17 | set(LIBRARY_OUTPUT_PATH ${opensse_BINARY_DIR}/lib) 18 | 19 | install (TARGETS opensse LIBRARY DESTINATION /usr/local/lib) 20 | 21 | # install include 22 | macro (install_head arg) 23 | file(GLOB HEADS ${arg}/*.h) 24 | install(FILES ${HEADS} DESTINATION /usr/local/include/opensse/${arg}) 25 | endmacro (install_head) 26 | 27 | install_head(common) 28 | install_head(io) 29 | install_head(features) 30 | install_head(quantize) 31 | install_head(index) 32 | install_head(search) 33 | install_head(vocabulary) 34 | install_head(.) -------------------------------------------------------------------------------- /sse/common/types.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Copyright (c) 2014 Zhang Dongdong 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | **************************************************************************/ 17 | #ifndef TYPES_H 18 | #define TYPES_H 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | namespace sse { 31 | 32 | using std::vector; 33 | using std::string; 34 | using std::set; 35 | 36 | using cv::Mat; 37 | 38 | typedef unsigned int uint; 39 | 40 | typedef int64_t Index_t; 41 | typedef std::vector Vec_Index_t; 42 | 43 | typedef std::vector Vec_f32_t; 44 | typedef std::vector KeyPoints_t; 45 | typedef std::vector Features_t; 46 | typedef std::vector Vocabularys_t; 47 | typedef std::vector Samples_t; //files has been quantized. 48 | 49 | typedef std::pair ResultItem_t; 50 | 51 | } //namespace sse 52 | 53 | #endif // TYPES_H 54 | -------------------------------------------------------------------------------- /sse/features/detector.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Copyright (c) 2014 Zhang Dongdong 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | **************************************************************************/ 17 | #include "detector.h" 18 | 19 | namespace sse { 20 | 21 | GridDetector::GridDetector(uint numSamples) : 22 | _numSamples(numSamples) 23 | { 24 | 25 | } 26 | 27 | /** 28 | * @brief GridDetector::detect 29 | * Keypoints are cross points, when we divide image to square grid. 30 | * 31 | * _numSamples, default value is 625 32 | */ 33 | void GridDetector::detect(const cv::Mat &image, KeyPoints_t &keypoints) const 34 | { 35 | cv::Rect samplingArea(0, 0, image.size().width, image.size().height); 36 | 37 | uint numSample1D = std::ceil(std::sqrt(static_cast(_numSamples))); 38 | float stepX = samplingArea.width / static_cast(numSample1D+1); 39 | float stepY = samplingArea.height / static_cast(numSample1D+1); 40 | 41 | for(uint x = 1; x < numSample1D; x++) { 42 | uint posX = x*stepX; 43 | for(uint y = 1; y <= numSample1D; y++) { 44 | uint posY = y*stepY; 45 | Vec_f32_t p(2); 46 | p[0] = posX; 47 | p[1] = posY; 48 | keypoints.push_back(p); 49 | } 50 | } 51 | } 52 | 53 | } //namespace sse 54 | -------------------------------------------------------------------------------- /sse/features/detector.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Copyright (c) 2014 Zhang Dongdong 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | **************************************************************************/ 17 | #ifndef DETECTOR_H 18 | #define DETECTOR_H 19 | 20 | #include "../common/types.h" 21 | 22 | namespace sse { 23 | 24 | /** 25 | * @brief The Detector class 26 | * Detect key points from input image 27 | */ 28 | class Detector 29 | { 30 | public: 31 | virtual void detect(const cv::Mat &image, KeyPoints_t &keypoints) const = 0; 32 | }; 33 | 34 | class GridDetector : public Detector { 35 | public: 36 | GridDetector(uint numSamples = 625); 37 | void detect(const cv::Mat &image, KeyPoints_t &keypoints) const; 38 | private: 39 | uint _numSamples; 40 | }; 41 | 42 | } //namespace sse 43 | 44 | 45 | #endif // DETECTOR_H 46 | -------------------------------------------------------------------------------- /sse/features/feature.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Copyright (c) 2014 Zhang Dongdong 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | **************************************************************************/ 17 | #ifndef FEATURE_H 18 | #define FEATURE_H 19 | 20 | #include "../common/types.h" 21 | 22 | namespace sse { 23 | 24 | /** 25 | * @brief The Feature class 26 | * The base class of all features 27 | */ 28 | class Feature 29 | { 30 | public: 31 | virtual void compute(const cv::Mat &image, 32 | sse::KeyPoints_t &keypoints, 33 | sse::Features_t &features) const = 0; 34 | /** 35 | * @brief scale: scale image as a suitable size 36 | * 37 | * @param image 38 | * @param scaled 39 | */ 40 | virtual double scale(const cv::Mat &image, cv::Mat &scaled) const = 0; 41 | /** 42 | * @brief detect keypoints 43 | * 44 | * @param image 45 | * @param keypoints 46 | */ 47 | virtual void detect(const cv::Mat &image, sse::KeyPoints_t &keypoints) const = 0; 48 | /** 49 | * @brief extract features from image 50 | * 51 | * @param image 52 | * @param keypoints 53 | * @param features 54 | * @param emptyFeatures 55 | */ 56 | virtual void extract(const cv::Mat &image, const sse::KeyPoints_t &keypoints, 57 | sse::Features_t &features, sse::Vec_Index_t &emptyFeatures) const = 0; 58 | }; 59 | 60 | } //namspace sse 61 | 62 | #endif // FEATURE_H 63 | -------------------------------------------------------------------------------- /sse/features/galif.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Copyright (c) 2014 Zhang Dongdong 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | **************************************************************************/ 17 | #ifndef GALIF_H 18 | #define GALIF_H 19 | 20 | #include "feature.h" 21 | #include "detector.h" 22 | 23 | namespace sse { 24 | 25 | class Galif : public Feature 26 | { 27 | public: 28 | // Galif(const PropertyTree_t ¶meters); 29 | Galif(uint width = 256, uint numOrients = 4, uint tiles = 4, 30 | double peakFrequency = 0.1, double lineWidth = 0.02, 31 | double lambda = 0.3, 32 | double featureSize = 0.1, 33 | bool isSmoothHist = true, 34 | const std::string& normalizeHist = "l2", 35 | const std::string& detectorName = "grid", 36 | uint numOfSamples = 625); 37 | void compute(const cv::Mat &image, KeyPoints_t &keypoints, Features_t &features) const; 38 | double scale(const cv::Mat &image, cv::Mat &scaled) const; 39 | void detect(const cv::Mat &image, KeyPoints_t &keypoints) const; 40 | void extract(const cv::Mat &image, const KeyPoints_t &keypoints, Features_t &features, Vec_Index_t &emptyFeatures) const; 41 | private: 42 | void assertImageSize(const cv::Mat &image) const; 43 | 44 | const uint _width; 45 | const uint _numOrients; 46 | const uint _tiles; 47 | const double _peakFrequency; 48 | const double _lineWidth; 49 | const double _lambda; 50 | const double _featureSize; 51 | const bool _isSmoothHist; 52 | const std::string _normalizeHist; 53 | const std::string _detectorName; 54 | 55 | cv::Size _filterSize; 56 | std::vector > > _gaborFilter; 57 | Detector *_detector; 58 | }; 59 | 60 | } //namespace sse 61 | 62 | #endif // GALIF_H 63 | -------------------------------------------------------------------------------- /sse/features/generator.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Copyright (c) 2014 Zhang Dongdong 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | **************************************************************************/ 17 | #include "generator.h" 18 | 19 | namespace sse { 20 | 21 | Generator::Generator() 22 | { 23 | } 24 | 25 | } 26 | 27 | 28 | -------------------------------------------------------------------------------- /sse/features/generator.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Copyright (c) 2014 Zhang Dongdong 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | **************************************************************************/ 17 | #ifndef GENERATOR_H 18 | #define GENERATOR_H 19 | 20 | namespace sse { 21 | 22 | class Generator 23 | { 24 | public: 25 | Generator(); 26 | }; 27 | 28 | } //namespace sse 29 | 30 | 31 | 32 | #endif // GENERATOR_H 33 | -------------------------------------------------------------------------------- /sse/features/util.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Copyright (c) 2014 Zhang Dongdong 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | **************************************************************************/ 17 | 18 | #include "util.h" 19 | 20 | namespace sse { 21 | 22 | void normalizeKeypoints(const KeyPoints_t &keypoints, const cv::Size &imageSize, KeyPoints_t &keypointsNormalized) 23 | { 24 | Vec_f32_t p(2); 25 | for (size_t i = 0; i < keypoints.size(); i++) { 26 | p[0] = keypoints[i][0] / imageSize.width; 27 | p[1] = keypoints[i][1] / imageSize.height; 28 | keypointsNormalized.push_back(p); 29 | } 30 | } 31 | 32 | void filterEmptyFeatures(const Features_t &features, const KeyPoints_t &keypoints, const vector &emptyFeatures, 33 | Features_t &featuresFiltered, KeyPoints_t &keypointsFiltered) 34 | { 35 | assert(features.size() == keypoints.size()); 36 | assert(features.size() == emptyFeatures.size()); 37 | 38 | for (size_t i = 0; i < emptyFeatures.size(); i++) { 39 | 40 | if (!emptyFeatures[i]) { 41 | featuresFiltered.push_back(features[i]); 42 | keypointsFiltered.push_back(keypoints[i]); 43 | } 44 | } 45 | } 46 | 47 | } //namespace sse 48 | -------------------------------------------------------------------------------- /sse/features/util.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Copyright (c) 2014 Zhang Dongdong 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | **************************************************************************/ 17 | #ifndef UTIL_H 18 | #define UTIL_H 19 | 20 | #include "../common/types.h" 21 | 22 | namespace sse { 23 | 24 | // Normalizes keypoint coordinates into range [0, 1] x [0, 1] to have them stored independently of image size 25 | void normalizeKeypoints(const KeyPoints_t &keypoints, const cv::Size &imageSize, KeyPoints_t &keypointsNormalized); 26 | 27 | // Removes all empty features, i.e. those that only contains zeros 28 | void filterEmptyFeatures(const Features_t &features, const KeyPoints_t &keypoints, const vector &emptyFeatures, 29 | Features_t &featuresFiltered, KeyPoints_t &keypointsFiltered); 30 | 31 | } //namespace sse 32 | 33 | #endif // UTIL_H 34 | -------------------------------------------------------------------------------- /sse/index/invertedindex.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Copyright (c) 2014 Zhang Dongdong 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | **************************************************************************/ 17 | #include "invertedindex.h" 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | namespace sse { 24 | 25 | InvertedIndex::InvertedIndex(uint vocabularySize) 26 | :_numOfWords(vocabularySize) 27 | { 28 | init(_numOfWords); 29 | } 30 | 31 | void InvertedIndex::init(uint numOfWords) 32 | { 33 | _ft.clear(); 34 | _invertedList.clear(); 35 | _weightList.clear(); 36 | _uniqueTerms.clear(); 37 | 38 | _ft.resize(numOfWords, 0); 39 | _invertedList.resize(numOfWords); 40 | _weightList.resize(numOfWords); 41 | 42 | _numOfDocuments = 0; 43 | } 44 | 45 | void InvertedIndex::addSample(const Vec_f32_t &sample) 46 | { 47 | assert(sample.size() == _numOfWords); 48 | 49 | for(uint t= 0; t < sample.size(); t++) { 50 | //sample[t] > 0.0 51 | float f_dt = sample[t]; 52 | if(f_dt > 0) { 53 | _ft[t]++; 54 | _invertedList[t].push_back(std::make_pair(_numOfDocuments, f_dt)); 55 | 56 | _uniqueTerms.insert(t); 57 | } 58 | } 59 | 60 | _numOfDocuments ++; 61 | } 62 | 63 | void InvertedIndex::createIndex(const TF_interface &tf, const IDF_interface &idf) 64 | { 65 | assert(_weightList.size() == _invertedList.size()); 66 | 67 | // prepare for l2 normalization 68 | vector documentLengths(_numOfDocuments, 0); 69 | 70 | for(uint termId = 0; termId < _numOfWords; termId++) { 71 | uint listSizeOfTerm = _invertedList[termId].size(); 72 | _weightList[termId].resize(listSizeOfTerm); 73 | 74 | for(uint listId = 0; listId < listSizeOfTerm; listId ++) { 75 | uint docId = _invertedList[termId][listId].first; 76 | 77 | float _tf = tf(*this, termId); 78 | float _idf = idf(*this, termId, listId, docId); 79 | 80 | float weight = _tf*_idf; 81 | _weightList[termId][listId] = weight; 82 | 83 | // prepare for l2 normalization 84 | documentLengths[docId] += weight * weight; 85 | } 86 | } 87 | 88 | //l2 normalization 89 | for(uint i = 0; i < _numOfDocuments; i++) { 90 | documentLengths[i] = std::sqrt(documentLengths[i]); 91 | } 92 | 93 | for(uint termId = 0; termId < _numOfWords; termId++) { 94 | uint listSizeOfTerm = _invertedList[termId].size(); 95 | _weightList[termId].resize(listSizeOfTerm); 96 | 97 | for(uint listId = 0; listId < listSizeOfTerm; listId ++) { 98 | uint docId = _invertedList[termId][listId].first; 99 | _weightList[termId][listId] /= documentLengths[docId]; 100 | } 101 | } 102 | } 103 | 104 | void InvertedIndex::query(const Vec_f32_t &sample, const TF_interface &tf, const IDF_interface &idf, 105 | uint numOfResults, std::vector &results) 106 | { 107 | numOfResults = std::min(numOfResults, _numOfDocuments); 108 | 109 | results.clear(); 110 | results.reserve(numOfResults); 111 | 112 | // get query tf-idf weight 113 | InvertedIndex indexSample(_numOfWords); 114 | indexSample.addSample(sample); 115 | indexSample.createIndex(tf, idf); 116 | 117 | // accumulators A 118 | std::vector A(_numOfDocuments, 0); 119 | const std::set& uniqueTerms = indexSample.uniqueTerms(); 120 | std::set::const_iterator it = uniqueTerms.begin(); 121 | for(; it != uniqueTerms.end(); ++it) { 122 | uint termId = *it; 123 | float wqt = indexSample.weightList()[termId][0]; 124 | 125 | const std::vector > &term_list = _invertedList[termId]; 126 | const std::vector &weight_list = _weightList[termId]; 127 | 128 | for(uint listId = 0; listId < term_list.size(); listId++) { 129 | uint docId = term_list[listId].first; 130 | float wdt = weight_list[listId]; 131 | A[docId] += wdt * wqt; 132 | } 133 | } 134 | 135 | std::priority_queue, std::greater > queue; 136 | 137 | for(uint i = 0; i < _numOfDocuments; i++) { 138 | queue.push(ResultItem_t(A[i], i)); 139 | if(queue.size() > numOfResults) { 140 | queue.pop(); 141 | } 142 | } 143 | 144 | assert(queue.size() <= numOfResults); 145 | 146 | for(uint i = 0; i < numOfResults; i++) { 147 | results.push_back(queue.top()); 148 | queue.pop(); 149 | } 150 | 151 | std::reverse(results.begin(), results.end()); 152 | } 153 | 154 | //many views 155 | void InvertedIndex::query(const Vec_f32_t &sample, const TF_interface &tf, const IDF_interface &idf, 156 | uint numOfResults, uint numOfViews, std::vector &results) 157 | { 158 | uint _numOfResults = std::min(numOfResults*numOfViews, _numOfDocuments); 159 | 160 | results.clear(); 161 | results.reserve(numOfResults); 162 | 163 | // get query tf-idf weight 164 | InvertedIndex indexSample(_numOfWords); 165 | indexSample.addSample(sample); 166 | indexSample.createIndex(tf, idf); 167 | 168 | // accumulators A 169 | std::vector A(_numOfDocuments, 0); 170 | const std::set& uniqueTerms = indexSample.uniqueTerms(); 171 | std::set::const_iterator it = uniqueTerms.begin(); 172 | for(; it != uniqueTerms.end(); ++it) { 173 | uint termId = *it; 174 | float wqt = indexSample.weightList()[termId][0]; 175 | 176 | const std::vector > &term_list = _invertedList[termId]; 177 | const std::vector &weight_list = _weightList[termId]; 178 | 179 | for(uint listId = 0; listId < term_list.size(); listId++) { 180 | uint docId = term_list[listId].first; 181 | float wdt = weight_list[listId]; 182 | A[docId] += wdt * wqt; 183 | } 184 | } 185 | 186 | std::priority_queue, std::greater > queue; 187 | 188 | for(uint i = 0; i < _numOfDocuments; i++) { 189 | queue.push(ResultItem_t(A[i], i)); 190 | if(queue.size() > _numOfResults) { 191 | queue.pop(); 192 | } 193 | } 194 | 195 | assert(queue.size() <= _numOfResults); 196 | assert(numOfViews > 0); 197 | 198 | std::vector flags(_numOfDocuments); 199 | uint index = 0; 200 | 201 | std::stack stack; 202 | for(uint i = 0; i < _numOfResults; i++) { 203 | stack.push(queue.top()); 204 | queue.pop(); 205 | } 206 | 207 | for(uint i = 0; i < _numOfResults; i++) { 208 | if(!flags[stack.top().second / numOfViews]) { 209 | results.push_back(stack.top()); 210 | flags[stack.top().second / numOfViews] = 1; 211 | index ++; 212 | if(index == numOfResults) 213 | break; 214 | } 215 | stack.pop(); 216 | } 217 | } 218 | 219 | void InvertedIndex::load(const std::string &filename) 220 | { 221 | std::ifstream in(filename.c_str()); 222 | in >> _numOfWords; 223 | init(_numOfWords); 224 | 225 | in >> _numOfDocuments; 226 | 227 | for(uint i = 0; i < _ft.size(); i++) { 228 | in >> _ft[i]; 229 | } 230 | 231 | for(uint i = 0; i < _numOfWords; i++) { 232 | uint sizeOfLists; 233 | in >> sizeOfLists; 234 | _invertedList[i].resize(sizeOfLists); 235 | _weightList[i].resize(sizeOfLists); 236 | for(uint j = 0; j < _invertedList[i].size(); j++) { 237 | uint docId = 0; 238 | float f_dt = 0.0; 239 | in >> docId; in >> f_dt; 240 | _invertedList[i][j] = std::make_pair(docId, f_dt); 241 | in >> _weightList[i][j]; 242 | } 243 | } 244 | in.close(); 245 | } 246 | 247 | void InvertedIndex::save(const std::string &filename) 248 | { 249 | std::ofstream out(filename.c_str()); 250 | 251 | out << _numOfWords < &results); 33 | void query(const Vec_f32_t &sample, const TF_interface &tf, const IDF_interface &idf, 34 | uint numOfResults, uint numOfViews, std::vector &results); 35 | void save(const std::string& filename); 36 | void load(const std::string& filename); 37 | 38 | inline const std::vector& ft() const { return _ft; } 39 | inline const std::vector > >& invertedList() const { return _invertedList; } 40 | inline const std::vector >& weightList() const { return _weightList; } 41 | inline const std::set& uniqueTerms() const { return _uniqueTerms; } 42 | inline uint numOfDocuments() const { return _numOfDocuments; } 43 | private: 44 | void init(uint numOfWords = 0); 45 | 46 | uint _numOfWords; 47 | 48 | //Document-level inverted index 49 | //term t : [0, vocabularySize) 50 | //_ft: a count ft of the documents containing t 51 | std::vector _ft; 52 | //_invertedList: Inverted list for terms: 53 | // the entry for each term t is composed of a document identifier d and a document frequency f_dt 54 | std::vector > > _invertedList; 55 | // tf-idf weights 56 | //_weightList[term_id][list_id] = tf-idf(_invertedList[term_id][list_id]) 57 | std::vector > _weightList; 58 | 59 | //record index when 60 | std::set _uniqueTerms; 61 | 62 | uint _numOfDocuments; 63 | }; 64 | 65 | } 66 | 67 | 68 | #endif // INVERTEDINDEX_H 69 | -------------------------------------------------------------------------------- /sse/index/tfidf.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Copyright (c) 2014 Zhang Dongdong 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | **************************************************************************/ 17 | #include "tfidf.h" 18 | 19 | #include "invertedindex.h" 20 | 21 | namespace sse { 22 | 23 | float TF_simple::operator() (const InvertedIndex &index, uint termId) const 24 | { 25 | uint ft = index.ft()[termId]; 26 | return std::log(1 + index.numOfDocuments() / static_cast(ft)); 27 | } 28 | 29 | float IDF_simple::operator() (const InvertedIndex &index, uint termId, uint listId, uint /*docId*/) const 30 | { 31 | float f_dt = index.invertedList()[termId][listId].second; 32 | return 1 + std::log(f_dt); 33 | } 34 | 35 | } //namespace sse 36 | -------------------------------------------------------------------------------- /sse/index/tfidf.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Copyright (c) 2014 Zhang Dongdong 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | **************************************************************************/ 17 | #ifndef TFIDF_H 18 | #define TFIDF_H 19 | 20 | #include "../common/types.h" 21 | 22 | namespace sse { 23 | 24 | class InvertedIndex; 25 | 26 | class TF_interface { 27 | public: 28 | virtual float operator() (const InvertedIndex &index, uint termId) const = 0; 29 | }; 30 | 31 | class IDF_interface { 32 | public: 33 | virtual float operator() (const InvertedIndex &index, uint termId, uint listId, uint docId) const = 0; 34 | }; 35 | 36 | class TF_simple : public TF_interface { 37 | public: 38 | float operator() (const InvertedIndex &index, uint termId) const; 39 | }; 40 | 41 | class IDF_simple : public IDF_interface { 42 | public: 43 | float operator() (const InvertedIndex &index, uint termId, uint listId, uint docId) const; 44 | }; 45 | 46 | } //namespace sse 47 | 48 | #endif // TFIDF_H 49 | -------------------------------------------------------------------------------- /sse/io/filelist.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Copyright (c) 2014 Zhang Dongdong 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | **************************************************************************/ 17 | #include "filelist.h" 18 | 19 | #include 20 | #include 21 | 22 | namespace sse { 23 | 24 | void FileList::randomSample(uint numOfSamples, uint seed) 25 | { 26 | if(numOfSamples >= _files.size()) 27 | return; 28 | 29 | std::vector indices(_files.size()); 30 | for (size_t i = 0; i < indices.size(); i++) indices[i] = i; 31 | 32 | std::random_shuffle(indices.begin(), indices.end()); 33 | indices.resize(numOfSamples); 34 | std::sort(indices.begin(), indices.end()); 35 | 36 | std::vector new_files(numOfSamples); 37 | for (size_t i = 0; i < new_files.size(); i++) new_files[i] = _files[indices[i]]; 38 | _files = new_files; 39 | } 40 | 41 | const std::vector& FileList::filenames() const 42 | { 43 | return _files; 44 | } 45 | 46 | uint FileList::size() const 47 | { 48 | return _files.size(); 49 | } 50 | 51 | const std::string& FileList::getRelativeFilename(uint index) const 52 | { 53 | assert(index < _files.size()); 54 | return _files[index]; 55 | } 56 | 57 | std::string FileList::getFilename(uint index) const 58 | { 59 | return getRelativeFilename(index); 60 | } 61 | 62 | void FileList::load(const std::string &filename) 63 | { 64 | std::ifstream in(filename.c_str()); 65 | 66 | std::vector files; 67 | std::string line; 68 | while(getline(in, line)) { 69 | files.push_back(line); 70 | } 71 | in.close(); 72 | _files = files; 73 | } 74 | 75 | void FileList::store(const std::string &filename) const 76 | { 77 | std::ofstream out(filename.c_str()); 78 | for(int i = 0; i < _files.size(); i++) { 79 | out << _files[i] << std::endl; 80 | } 81 | out.close(); 82 | } 83 | 84 | } 85 | 86 | -------------------------------------------------------------------------------- /sse/io/filelist.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Copyright (c) 2014 Zhang Dongdong 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | **************************************************************************/ 17 | #ifndef FILELIST_H 18 | #define FILELIST_H 19 | 20 | #include "../common/types.h" 21 | 22 | namespace sse { 23 | 24 | class FileList 25 | { 26 | public: 27 | // Subsample given filelist randomly 28 | void randomSample(uint numOfSamples, uint seed); 29 | 30 | // Vector of all filenames 31 | const std::vector& filenames() const; 32 | uint size() const; 33 | 34 | //Access relative filename of file i 35 | //index: [0, size()-1] 36 | const std::string& getRelativeFilename(uint index) const; 37 | //Access 'absolute' filename of file i 38 | //index: [0, size()-1] 39 | std::string getFilename(uint index) const; 40 | 41 | //Load a FileList 42 | //Note that you Must setRootDir 43 | void load(const std::string &filename); 44 | //Store a FileList 45 | //Note that the root directory is not stored, only 46 | //the list of filenames relative to the root directory. 47 | void store(const std::string &filename)const; 48 | 49 | private: 50 | std::vector _files; 51 | std::string _rootDir; 52 | }; 53 | 54 | } //namespace sse 55 | 56 | #endif // FILELIST_H 57 | -------------------------------------------------------------------------------- /sse/io/json_parser.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "json_parser.h" 3 | 4 | void parse(const string &jsonContent, map &json) 5 | { 6 | string keys_stack; 7 | string stack; 8 | stack.push_back('#'); 9 | 10 | int i = 0; 11 | while(i < jsonContent.size()) 12 | { 13 | char curChar = jsonContent[i]; 14 | string value; 15 | switch (curChar) { 16 | case '"': 17 | while(jsonContent[++i] != '"' && i < jsonContent.size()) 18 | keys_stack.push_back(jsonContent[i]); 19 | break; 20 | case ':': 21 | keys_stack.push_back('$'); 22 | stack.push_back(curChar); 23 | break; 24 | case '}': 25 | while(stack.back() != '{') 26 | stack.pop_back(); 27 | stack.pop_back(); 28 | if (stack.back() == '#') 29 | break; 30 | case ',': 31 | if (keys_stack.back() != '$') { 32 | while(keys_stack.back() != '$') { 33 | value.insert(0, 1, keys_stack.back()); 34 | keys_stack.pop_back(); 35 | } 36 | keys_stack.pop_back(); 37 | stack.pop_back(); 38 | 39 | json.insert(make_pair(keys_stack, value)); 40 | 41 | while(!keys_stack.empty() && keys_stack.back() != '$') { 42 | keys_stack.pop_back(); 43 | } 44 | } else { 45 | keys_stack.pop_back(); 46 | while(!keys_stack.empty() && keys_stack.back() != '$') 47 | keys_stack.pop_back(); 48 | } 49 | break; 50 | default: 51 | stack.push_back(curChar); 52 | } 53 | i++; 54 | } 55 | } 56 | 57 | Json::Json(const string &filename) 58 | { 59 | ifstream in(filename.c_str()); 60 | 61 | string jsonContent; 62 | char c; 63 | while(in.get(c)) 64 | if(c != ' ' && c != '\r' && c != '\n' && c != '\t') 65 | jsonContent.push_back(c); 66 | in.close(); 67 | 68 | parse(jsonContent, values); 69 | } 70 | 71 | const string& Json::getValue(const string &key, const string &defaultValue) 72 | { 73 | return values[key].empty() ? defaultValue : values[key]; 74 | } -------------------------------------------------------------------------------- /sse/io/json_parser.h: -------------------------------------------------------------------------------- 1 | #ifndef JSON_PARSER_H 2 | #define JSON_PARSER_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | enum VALUE_TYPE { 11 | UINT 12 | }; 13 | 14 | template 15 | T convert(const string &value, VALUE_TYPE type) 16 | { 17 | if (type == UINT) { 18 | char *end; 19 | return static_cast(strtol(value.c_str(), &end, 10)); 20 | } 21 | return T(0); 22 | }; 23 | 24 | class Json { 25 | public: 26 | Json(const string &filename); 27 | const string& getValue(const string &key, const string &defaultValue); 28 | private: 29 | map values; 30 | }; 31 | 32 | #endif // JSON_PARSER_H -------------------------------------------------------------------------------- /sse/io/reader_writer.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Copyright (c) 2014 Zhang Dongdong 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | **************************************************************************/ 17 | #include "reader_writer.h" 18 | 19 | #include 20 | 21 | namespace sse { 22 | 23 | void print(int index, int total, const std::string& info) 24 | { 25 | if(index +1 != total) 26 | std::cout << info.c_str() << " " << index+1 << "/" << total <<"\r"< > &data, const std::string &filename, 32 | Callback_fn callback, const std::string &info) 33 | { 34 | std::ofstream out(filename.c_str()); 35 | out << data.size() < > &data, 54 | Callback_fn callback, const std::string &info) 55 | { 56 | std::ifstream in(filename.c_str()); 57 | 58 | uint size = 0; 59 | in >> size; 60 | for(uint n = 0; n < size; n++) { 61 | uint row = 0; 62 | in >> row; 63 | uint col = 0; 64 | in >> col; 65 | 66 | std::vector vv; 67 | 68 | for(uint i = 0; i < row; i++) { 69 | Vec_f32_t vf; 70 | float temp; 71 | for(uint j = 0; j < col; j++) { 72 | in >> temp; 73 | vf.push_back(temp); 74 | } 75 | vv.push_back(vf); 76 | } 77 | data.push_back(vv); 78 | 79 | if(callback) 80 | callback(n, size, info); 81 | } 82 | 83 | in.close(); 84 | } 85 | 86 | void readSamplesForCluster(const std::string &filename, Features_t &samples, 87 | Callback_fn callback, const std::string &info) 88 | { 89 | std::ifstream in(filename.c_str()); 90 | 91 | //See: read below function in reader_writer.cpp 92 | //void write(const std::vector &vv, std::ofstream &out, 93 | //Callback_fn callback = Callback_fn()); 94 | // 95 | //uint filesize = 0; 96 | //in >> filesize; 97 | 98 | uint size = 0; 99 | in >> size; 100 | 101 | for(uint n = 0; n < size; n++) { 102 | uint row = 0; 103 | in >> row; 104 | uint col = 0; 105 | in >> col; 106 | 107 | for(uint i = 0; i < row; i++) { 108 | Vec_f32_t vf; 109 | float temp; 110 | for(uint j = 0; j < col; j++) { 111 | in >> temp; 112 | vf.push_back(temp); 113 | } 114 | samples.push_back(vf); 115 | } 116 | 117 | if(callback) 118 | callback(n, size, info); 119 | } 120 | 121 | in.close(); 122 | } 123 | 124 | void write(const std::vector &vv, const std::string &filename, 125 | Callback_fn callback, const std::string &info) 126 | { 127 | std::ofstream out(filename.c_str()); 128 | out << vv.size() < 0); 130 | out << vv[0].size() < &vv, 146 | Callback_fn callback, const std::string &info) 147 | { 148 | std::ifstream in(filename.c_str()); 149 | uint row = 0; 150 | uint col = 0; 151 | in >> row; 152 | in >> col; 153 | 154 | for(uint i = 0; i < row; i++) { 155 | Vec_f32_t vf; 156 | for(uint j = 0; j < col; j++) { 157 | float temp; 158 | in >> temp; 159 | vf.push_back(temp); 160 | } 161 | vv.push_back(vf); 162 | 163 | if(callback) 164 | callback(i, row, info); 165 | } 166 | 167 | in.close(); 168 | } 169 | 170 | void write(const std::vector &vv, std::ofstream &out, 171 | Callback_fn callback, const std::string &info) 172 | { 173 | out << vv.size() < 0); 175 | out << vv[0].size() < &vv, 190 | Callback_fn callback, const std::string &info) 191 | { 192 | uint row = 0; 193 | uint col = 0; 194 | in >> row; 195 | in >> col; 196 | 197 | for(uint i = 0; i < row; i++) { 198 | Vec_f32_t vf; 199 | for(uint j = 0; j < col; j++) { 200 | float temp; 201 | in >> temp; 202 | vf.push_back(temp); 203 | } 204 | vv.push_back(vf); 205 | 206 | if(callback) 207 | callback(i, row, info); 208 | } 209 | } 210 | 211 | } //namespace sse 212 | -------------------------------------------------------------------------------- /sse/io/reader_writer.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Copyright (c) 2014 Zhang Dongdong 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | **************************************************************************/ 17 | #ifndef READER_WRITER_H 18 | #define READER_WRITER_H 19 | 20 | #include "../common/types.h" 21 | 22 | #include 23 | 24 | namespace sse { 25 | 26 | typedef void(*Callback_fn)(int, int, const std::string&); 27 | 28 | //Callback function, show read or write progress 29 | void print(int index, int total, const std::string& info); 30 | 31 | void write(const std::vector > &data, const std::string &filename, 32 | Callback_fn callback = Callback_fn(), const std::string &info = ""); 33 | 34 | void read(const std::string &filename, std::vector > &data, 35 | Callback_fn callback = Callback_fn(), const std::string &info = ""); 36 | 37 | //Read Features_t in one dimensional ready for cluster 38 | //Note that: firt read filesize 39 | void readSamplesForCluster(const std::string &filename, Features_t &samples, 40 | Callback_fn callback = Callback_fn(), const std::string &info = ""); 41 | 42 | //Read and read 43 | void write(const std::vector &vv, const std::string &filename, 44 | Callback_fn callback = Callback_fn(), const std::string &info = ""); 45 | 46 | void read(const std::string &filename, std::vector &vv, 47 | Callback_fn callback = Callback_fn(), const std::string &info = ""); 48 | 49 | //Read and read features vector: std::vector 50 | //append method can save memory 51 | void read(std::ifstream &in, std::vector &vv, 52 | Callback_fn callback = Callback_fn(), const std::string &info = ""); 53 | 54 | void write(const std::vector &vv, std::ofstream &out, 55 | Callback_fn callback = Callback_fn(), const std::string &info = ""); 56 | 57 | 58 | } //namespace sse 59 | 60 | #endif // READER_WRITER_H 61 | -------------------------------------------------------------------------------- /sse/opensse.h: -------------------------------------------------------------------------------- 1 | #ifndef OPENSSE_H 2 | #define OPENSSE_H 3 | 4 | #include "opensse/common/distance.h" 5 | #include "opensse/common/types.h" 6 | #include "opensse/features/galif.h" 7 | #include "opensse/index/invertedindex.h" 8 | #include "opensse/io/filelist.h" 9 | #include "opensse/io/reader_writer.h" 10 | #include "opensse/io/json_parser.h" 11 | #include "opensse/quantize/quantizer.h" 12 | #include "opensse/vocabulary/kmeans_init.h" 13 | #include "opensse/vocabulary/kmeans.h" 14 | 15 | #endif -------------------------------------------------------------------------------- /sse/quantize/quantizer.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Copyright (c) 2014 Zhang Dongdong 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | **************************************************************************/ 17 | #include "quantizer.h" 18 | 19 | namespace sse { 20 | 21 | //Quantize one image 22 | void quantize(const Features_t &features, const Vocabularys_t &vocabulary, 23 | Vec_f32_t &vf, QuantizerHard > &quantizer) 24 | { 25 | Vocabularys_t quantized_samples; 26 | quantize_samples_parallel(features, vocabulary, quantized_samples, quantizer); 27 | 28 | build_histvw(quantized_samples, vocabulary.size(), vf, false); 29 | } 30 | 31 | void quantize_samples_parallel(const Features_t &samples, const Vocabularys_t &vocabulary, 32 | Vocabularys_t &quantized_samples, QuantizerHard > &quantizer) 33 | { 34 | quantized_samples.resize(samples.size()); 35 | 36 | //for each word compute distances to each entry in the vocabulary ... 37 | #pragma omp parallel for 38 | for(uint i = 0; i < samples.size(); i++) { 39 | quantizer.quantize(samples[i], vocabulary, quantized_samples[i]); 40 | } 41 | } 42 | 43 | void build_histvw(const Vocabularys_t &quantized_samples, uint vocabulary_size, Vec_f32_t &histvw, 44 | bool normalize, const KeyPoints_t &keypoints, int res) 45 | { 46 | assert(res > 0); 47 | assert(vocabulary_size > 0); 48 | 49 | if(res > 1) { 50 | assert(keypoints.size() == quantized_samples.size()); 51 | } 52 | 53 | //size_t vocabularySize = quantized_features[0].size(); 54 | 55 | // length of the vector is number of cells x histogram length 56 | // i.e. it actually stores one histogram per cell 57 | 58 | histvw.resize(res*res*vocabulary_size, 0); 59 | 60 | for(uint i = 0; i < quantized_samples.size(); i++) { 61 | assert(quantized_samples[i].size() == vocabulary_size); 62 | 63 | // in the case of res = 1, offset will be zero and 64 | // we only have a single histogram (no pyramid) and 65 | // thus the offset into this overall histogram will be zero 66 | int offset = 0; 67 | 68 | // ---------------------------------------------------------------- 69 | // Special path for building a spatial pyramid 70 | // 71 | // If the user has chosen res = 1 we do not care about the content 72 | // of the positions vector as they are only accessed for res > 1 73 | if(res > 1) { 74 | int x = static_cast(keypoints[i][0] * res); 75 | int y = static_cast(keypoints[i][1] * res); 76 | 77 | if(x == res) x--; 78 | if(y == res) y--; 79 | 80 | // generate a linear index from 2D (x,y) index 81 | int idx = y*res + x; 82 | assert (idx >= 0 && idx < res*res); 83 | 84 | // identify the spatial histogram we want to add to 85 | offset = vocabulary_size*idx; 86 | } 87 | // ----------------------------------------------------------------- 88 | 89 | // Build up histogram by adding the quantized feature to the 90 | // intermediate histogram. Offset defines the spatial bin we add into 91 | for(uint j = 0; j < vocabulary_size; j++) { 92 | histvw[offset+j] += quantized_samples[i][j]; 93 | } 94 | } 95 | 96 | 97 | // for the soft features we should normalize by the number of samples 98 | // but we do not really want that for the hard quantized features... 99 | // follow the approach by Chatterfield et al. 100 | // The second check is to avoid division by zero. In case an empty quantized_features 101 | // vector is passed in, the result will be an all zero histogram 102 | if(normalize && quantized_samples.size() > 0) { 103 | uint numSamples = quantized_samples.size(); 104 | for(uint i = 0; i < histvw.size(); i++) { 105 | histvw[i] /= numSamples; 106 | } 107 | } 108 | } 109 | 110 | } 111 | 112 | -------------------------------------------------------------------------------- /sse/quantize/quantizer.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Copyright (c) 2014 Zhang Dongdong 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | **************************************************************************/ 17 | #ifndef QUANTIZER_H 18 | #define QUANTIZER_H 19 | 20 | #include "../common/types.h" 21 | #include "../common/distance.h" 22 | 23 | namespace sse { 24 | 25 | /** 26 | * @brief Based class for a quantization function. 27 | * 28 | * TODO: not used now 29 | */ 30 | template 31 | class Quantizer_fn { 32 | public: 33 | void quantize(const Sample_t& sample, const std::vector& vocabulary, Vec_f32_t& quantized_sample); 34 | }; 35 | 36 | /** 37 | * @brief Functor performing hard quantization of a sample against a given codebook of samples 38 | */ 39 | template 40 | class QuantizerHard : public Quantizer_fn 41 | { 42 | public: 43 | /** 44 | * @brief Performs hard quantization of \p sample against the passed \p vocabulary. 45 | * 46 | * Computes the index of the sample in the vocabulary that has the smallest 47 | * distance (under the distance functor passed in via the second template parameter) to 48 | * the sample to be quantized. Note that we actually return a vector that contains a single 1 49 | * at the corresponding index. This is not really optimal performance-wise, but makes 50 | * the 'interface' similar to that of quantize_fuzzy such that both functors can be easily 51 | * exchanged for each other. 52 | * 53 | * @param sample Sample to be quantized 54 | * @param vocabulary Vocabulary 55 | * @param quantized_sample 56 | */ 57 | void quantize(const Sample_t& sample, const std::vector& vocabulary, Vec_f32_t& quantized_sample) 58 | { 59 | //quantized_sample.size() == vocabulary.size() 60 | quantized_sample.resize(vocabulary.size()); 61 | 62 | uint closest = 0; 63 | float minDistance = std::numeric_limits::max(); 64 | 65 | Dist_fn dist; 66 | 67 | for(uint i = 0; i < vocabulary.size(); i++) { 68 | float distance = dist(sample, vocabulary[i]); 69 | if(distance <= minDistance) { 70 | closest = i; 71 | minDistance = distance; 72 | } 73 | } 74 | 75 | quantized_sample[closest] = 1; 76 | } 77 | }; 78 | 79 | /** 80 | * @brief Functor performing soft quantization of a sample against a given codebook of samples 81 | */ 82 | template 83 | class QuantizeFuzzy 84 | { 85 | public: 86 | QuantizeFuzzy(float sigma) :_sigma(sigma) 87 | { 88 | assert(_sigma > 0); 89 | } 90 | 91 | void operator () (const Sample_t& sample, const std::vector& vocabulary, Vec_f32_t& quantized_sample) 92 | { 93 | //quantized_sample.size() == vocabulary.size() 94 | quantized_sample.resize(vocabulary.size()); 95 | 96 | float sigma2 = 2*_sigma*_sigma; 97 | float sum = 0; 98 | 99 | for(uint i = 0; i < vocabulary.size(); i++) { 100 | float d = dist(sample, vocabulary[i]); 101 | float e = exp(-d*d / sigma2); 102 | sum += e; 103 | quantized_sample[i] = e; 104 | } 105 | 106 | // Normalize such that sum(result) = 1 (L1 norm) 107 | // The reason is that each local feature contributes the same amount of energy (=1) to the 108 | // resulting histogram, If we wouldn't normalize, some features (that are close to several 109 | // entries in the vocabulary) would contribute more energy than others. 110 | // This is exactly the approach taken by Chatterfield et al. -- The devil is in the details 111 | for(uint i = 0; i < quantized_sample.size(); i++) { 112 | quantized_sample[i] /= sum; 113 | } 114 | } 115 | 116 | private: 117 | float _sigma; 118 | }; 119 | 120 | /** 121 | * @brief Convenience function that quantizes a vector of samples in parallel 122 | * @param samples Vector of samples to be quantized, each sample is of vector 123 | * @param vocabulary Vocabulary to quantize the samples against 124 | * @param quantized_samples A vector of the same size as the \p samples vector with each 125 | * entry being a vector the size of the \p vocabulary. 126 | * @param quantizer quantization function to be used 127 | */ 128 | void quantize_samples_parallel(const Features_t &samples, const Vocabularys_t &vocabulary, 129 | Vocabularys_t &quantized_samples, QuantizerHard > &quantizer); 130 | 131 | // Given a list of quantized samples and corresponding coordinates 132 | // compute the (spatialized) histogram of visual words out of that. 133 | // normalize=true normalizes the resulting histogram by the number 134 | // of samples, this is typically only used in case of a fuzzy histogram! 135 | // 136 | // Note a): 137 | // If you don't want to add any spatial information only pass in the 138 | // first three parameters, this gives a standard BoF histogram 139 | // 140 | // Note b): 141 | // we assume that the keypoints lie in [0,1]x[0,1] 142 | void build_histvw(const Vocabularys_t &quantized_samples, uint vocabulary_size, Vec_f32_t &histvw, 143 | bool normalize, const KeyPoints_t &kepoints = KeyPoints_t(), int res = 1); 144 | 145 | //Quantize one image with some default parameters 146 | void quantize(const Features_t &features, const Vocabularys_t &vocabulary, 147 | Vec_f32_t &vf, QuantizerHard > &quantizer); 148 | } //namespace sse 149 | 150 | 151 | 152 | #endif // QUANTIZER_H 153 | -------------------------------------------------------------------------------- /sse/vocabulary/kmeans_init.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Copyright (c) 2014 Zhang Dongdong 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | **************************************************************************/ 17 | #ifndef KMEANS_INIT_H 18 | #define KMEANS_INIT_H 19 | 20 | #include "../common/types.h" 21 | #include "../common/distance.h" 22 | 23 | #include 24 | #include 25 | 26 | namespace sse { 27 | 28 | template 29 | void kmeans_init_random(std::vector& centers, const collection_t& collection, std::size_t numclusters) 30 | { 31 | assert(collection.size() >= numclusters); 32 | 33 | centers.resize(collection.size()); 34 | for (std::size_t i = 0; i < centers.size(); i++) centers[i] = i; 35 | std::random_shuffle(centers.begin(), centers.end()); 36 | centers.resize(numclusters); 37 | } 38 | 39 | template 40 | void kmeans_init_plusplus(std::vector& result, const collection_t& collection, std::size_t numclusters, const dist_fn& distfn) 41 | { 42 | assert(numclusters > 0); 43 | assert(collection.size() >= numclusters); 44 | 45 | std::random_device rd; // will be used to obtain a seed for the random number engine 46 | std::mt19937 generator(rd()); // standard mersenne_twister_engine seeded with rd() 47 | std::uniform_real_distribution<> unirand(0.0, 1.0); 48 | 49 | std::size_t numtrials = 2 + std::log(numclusters); 50 | 51 | // add first cluster, randomly chosen 52 | std::set centers; 53 | index_t first = unirand(generator) * collection.size(); 54 | centers.insert(first); 55 | 56 | // compute distance between first cluster center and all others 57 | // and accumulate the distances that gives the current potential 58 | std::vector dists(collection.size()); 59 | double potential = 0.0; 60 | for (std::size_t i = 0; i < collection.size(); i++) 61 | { 62 | double d = distfn(collection[first], collection[i]); 63 | dists[i] = d*d; 64 | potential += dists[i]; 65 | } 66 | std::cout << "kmeans++ init: numclusters=" << numclusters << " numtrials=" << numtrials << " collection.size=" << collection.size() << " init pot=" << potential << std::endl; 67 | 68 | // iteratively add centers 69 | for (std::size_t c = 1; c < numclusters; c++) 70 | { 71 | double min_potential = std::numeric_limits::max(); 72 | std::size_t best_index = 0; 73 | 74 | for (std::size_t i = 0; i < numtrials; i++) 75 | { 76 | std::size_t index; 77 | 78 | // get new center 79 | double r = unirand(generator) * potential; 80 | for (index = 0; index < collection.size()-1 && r > dists[index]; index++) 81 | { 82 | r -= dists[index]; 83 | } 84 | 85 | while (centers.count(index) > 0) index = (index + 1) % collection.size(); 86 | 87 | // recompute potential 88 | double p = 0.0; 89 | for (std::size_t k = 0; k < collection.size(); k++) 90 | { 91 | double d = distfn(collection[index], collection[k]); 92 | p += std::min(dists[k], d*d); 93 | } 94 | 95 | if (p < min_potential) 96 | { 97 | min_potential = p; 98 | best_index = index; 99 | } 100 | } 101 | 102 | for (std::size_t i = 0; i < collection.size(); i++) 103 | { 104 | double d = distfn(collection[best_index], collection[i]); 105 | dists[i] = d*d; 106 | } 107 | 108 | potential = min_potential; 109 | 110 | centers.insert(best_index); 111 | 112 | std::cout << "new center " << c << ": potential=" << potential << " index=" << best_index << std::endl; 113 | } 114 | 115 | std::copy(centers.begin(), centers.end(), std::back_inserter(result)); 116 | } 117 | 118 | enum KmeansInitAlgorithm 119 | { 120 | KmeansInitRandom, 121 | KmeansInitPlusPlus 122 | }; 123 | 124 | } //namespace sse 125 | 126 | #endif // KMEANS_INIT_H 127 | -------------------------------------------------------------------------------- /tools/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin) 2 | 3 | set(TOOLS index extract vocabulary quantize search extract_and_quantize) 4 | set(SCRIPT_TOOLS sse filelist) 5 | 6 | macro (make_exec arg) 7 | add_executable(${arg} ${arg}.cpp) 8 | target_link_libraries(${arg} ${REQUIRED_LIB} opensse) 9 | endmacro (make_exec) 10 | 11 | foreach(tool ${TOOLS}) 12 | make_exec(${tool}) 13 | endforeach() 14 | 15 | file(COPY ${PROJECT_SOURCE_DIR}/tools/filelist DESTINATION ${CMAKE_BINARY_DIR}/bin) 16 | file(COPY ${PROJECT_SOURCE_DIR}/tools/sse DESTINATION ${CMAKE_BINARY_DIR}/bin/) 17 | 18 | install (TARGETS ${TOOLS} RUNTIME DESTINATION /usr/local/bin) 19 | 20 | install (FILES ${SCRIPT_TOOLS} PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ DESTINATION /usr/local/bin) -------------------------------------------------------------------------------- /tools/add_license.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # zdd / zddhub@gmail.com 3 | if [ $# != 2 ] 4 | then 5 | echo "Usage: add_license project_dir license_file" 6 | exit 7 | fi 8 | 9 | for file in `find $1 -name "*.[h|c]*"` 10 | do 11 | echo "/*************************************************************************" > temp 12 | while read line 13 | do 14 | echo " * $line" >> temp 15 | done < $2 16 | echo "**************************************************************************/" >> temp 17 | cat $file >> temp 18 | mv -f temp $file 19 | done 20 | 21 | for file in `find $1 -name "*.pr[o|i]"` 22 | do 23 | echo "#-------------------------------------------------------------------------" > temp 24 | while read line 25 | do 26 | echo "# $line" >> temp 27 | done < $2 28 | echo "#-------------------------------------------------------------------------" >> temp 29 | cat $file >> temp 30 | mv -f temp $file 31 | done 32 | -------------------------------------------------------------------------------- /tools/extract.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Copyright (c) 2014 Zhang Dongdong 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | **************************************************************************/ 17 | #include 18 | #include 19 | 20 | using namespace std; 21 | 22 | #include "opensse/opensse.h" 23 | 24 | using namespace sse; 25 | 26 | void usages() { 27 | cout << "Usages: sse extract -f filelist -o output" < vecKeypoints; 47 | std::vector vecFeatures; 48 | 49 | // Don't keep keypoints save memory. 50 | // std::string kp_file = std::string(argv[4]) + "keypoints"; 51 | // ofstream kp_out(kp_file.c_str()); 52 | std::string ft_file = std::string(argv[4]); 53 | ofstream ft_out(ft_file.c_str()); 54 | 55 | // kp_out << files.size() << endl; 56 | ft_out << files.size() << endl; 57 | for(uint i = 0; i < files.size(); i++) { 58 | KeyPoints_t keypoints; 59 | Features_t features; 60 | cv::Mat image = cv::imread(files.getFilename(i)); 61 | galif->compute(image, keypoints, features); 62 | // write(keypoints, kp_out); 63 | write(features, ft_out); 64 | cout << "Extract descriptors " << i+1 << "/" << files.size() <<"\r" << flush; 65 | } 66 | cout << "Extract descriptors "<< files.size() << "/" << files.size() << "." < 18 | #include 19 | using namespace std; 20 | 21 | #include "opensse/opensse.h" 22 | 23 | using namespace sse; 24 | 25 | void usages() { 26 | cout << "Usages: sse extract_and_quantize -f filelist -v vocabulary -o output" < > quantizer = QuantizerHard >(); 50 | 51 | Galif *galif = new Galif(); 52 | 53 | ofstream fout(argv[6]); 54 | fout << files.size() <compute(image, keypoints, features); 62 | quantize(features, vocabulary, sample, quantizer); 63 | for(Index_t j = 0; j < sample.size(); j++) { 64 | fout << sample[j] << " "; 65 | } 66 | fout << endl; 67 | cout << "quantize " << i+1 << "/" << files.size() <<"\r"< $filelist 44 | -------------------------------------------------------------------------------- /tools/generate_filelist.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import sys, os, getopt 4 | import random 5 | 6 | def usage(): 7 | print "Usage: generate_filelist -d rootdir -f filter -o filelist [-n sample_num]" 8 | print " rootdir:\t file root directory" 9 | print " filter:\t file name filter, eg: \"*.png\" " 10 | print " filelist:\t output file name" 11 | print " sample_num:\t sample num (>0)" 12 | 13 | def generate_filelist(argv): 14 | if len(argv) != 6 and len(argv) != 8: 15 | usage() 16 | sys.exit(1) 17 | 18 | rootdir = '' 19 | filter = '' 20 | filelist = '' 21 | sample_num = 0 22 | try: 23 | opts, args = getopt.getopt(argv, "d:f:o:n:", ["rootdir=", "filter=", "filelist=", "sample_num="]) 24 | except getopt.GetoptError: 25 | usage() 26 | sys.exit(1) 27 | 28 | for opt, arg in opts: 29 | if opt in ("-d", "--rootdir"): 30 | rootdir = arg 31 | elif opt in ("-f", "--filter"): 32 | filter = arg 33 | elif opt in ("-o", "--output"): 34 | filelist = arg 35 | elif opt in ("-n", "--sample_num"): 36 | sample_num = int(arg) 37 | if sample_num < 0: 38 | usage() 39 | sys.exit(1) 40 | else: 41 | usage() 42 | sys.exit(1) 43 | 44 | lists = [] 45 | os.chdir(rootdir) 46 | 47 | for root, dirs, files in os.walk('.'): 48 | for file in files: 49 | if file.endswith(filter[1:]): 50 | lists.append(os.path.join(root, file)) 51 | 52 | list = range(0, len(lists)) 53 | indexes = [] 54 | if sample_num == 0: 55 | indexes = list 56 | else: 57 | indexes = random.sample(list, sample_num) 58 | 59 | with open(filelist, 'w') as f: 60 | for index in indexes: 61 | f.write(lists[index][2:] + '\n') 62 | 63 | 64 | if __name__ == "__main__": 65 | generate_filelist(sys.argv[1:]) 66 | 67 | -------------------------------------------------------------------------------- /tools/generate_filelist.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | 3 | require 'optparse' 4 | 5 | argv_size = ARGV.size 6 | options = {} 7 | 8 | optparse = OptionParser.new do |opts| 9 | opts.banner = "Usage: generate_filelist -d rootdir -f filter -o filelist [-n sample_num]" 10 | opts.on('-d', '--rootdir rootdir', 'file root directory') { |v| options[:rootdir] = v } 11 | opts.on('-f', '--filter filter', 'file name filter') { |v| options[:filter] = v } 12 | opts.on('-o', '--filelist filelist', 'output file name') { |v| options[:filelist] = v } 13 | opts.on('-n', '--sample_num sample_num', 'sample num') { |v| options[:sample_num] = v } 14 | end 15 | 16 | begin 17 | optparse.parse! 18 | rescue OptionParser::InvalidArgument, OptionParser::InvalidOption, OptionParser::MissingArgument 19 | puts $!.to_s 20 | puts optparse 21 | exit 22 | end 23 | 24 | if argv_size != 6 && argv_size != 8 25 | puts optparse 26 | end 27 | 28 | Dir.chdir(options[:rootdir]) 29 | lists = Dir.glob("**/"+options[:filter]) 30 | 31 | file = File.new(options[:filelist], "w") 32 | lists.each do |image| 33 | file.puts image 34 | end 35 | 36 | file.close 37 | 38 | -------------------------------------------------------------------------------- /tools/index.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Copyright (c) 2014 Zhang Dongdong 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | **************************************************************************/ 17 | #include 18 | using namespace std; 19 | 20 | #include "opensse/opensse.h" 21 | using namespace sse; 22 | 23 | void usages() { 24 | cout << "Usages: sse index -s samples -o output" <> samplesize; 41 | uint vocabularySize = 0; 42 | samples_in >> vocabularySize; 43 | 44 | InvertedIndex index(vocabularySize); 45 | 46 | assert(samplesize > 0 && vocabularySize > 0); 47 | 48 | cout << "add sample " << "\r" <> sample[j]; 54 | } 55 | index.addSample(sample); 56 | cout << "add sample " << i <<"/" << samplesize << "\r" < 18 | #include 19 | using namespace std; 20 | 21 | #include "opensse/opensse.h" 22 | 23 | using namespace sse; 24 | 25 | void usages() { 26 | cout << "Usages: sse quantize -v vocabulary -f features -o output" < vecFeatures; 42 | 43 | ifstream ft_in(argv[4]); 44 | uint filesize = 0; 45 | ft_in >> filesize; 46 | 47 | Vocabularys_t vocabulary; 48 | read(argv[2], vocabulary, print, "read vocabulary"); 49 | 50 | //QuantizerHard 51 | QuantizerHard > quantizer = QuantizerHard >(); 52 | 53 | ofstream fout(argv[6]); 54 | fout << filesize < 18 | using namespace std; 19 | 20 | #include 21 | 22 | #include "opensse/opensse.h" 23 | using namespace sse; 24 | 25 | void usages() 26 | { 27 | cout << "Usages: sse search -i indexfile -v vocabulary -f filelist -n resultsnum" < > quantizer = QuantizerHard >(); 51 | 52 | TF_simple tf; 53 | IDF_simple idf; 54 | 55 | FileList files; 56 | files.load(argv[6]); 57 | 58 | uint numOfResults = atoi(argv[8]); 59 | 60 | cout << ">> sketch search :"<> input absolute path, like \"/Users/zdd/zddhub.png\""<> type q exit"<> good luck!"<> "; 67 | cin >> filename; 68 | 69 | if(filename[0] == 'q' || filename[0] != '/') 70 | break; 71 | 72 | //extract features 73 | KeyPoints_t keypoints; 74 | Features_t features; 75 | cv::Mat image = cv::imread(filename); 76 | 77 | galif->compute(image, keypoints, features); 78 | 79 | //quantize 80 | Vec_f32_t query; 81 | quantize(features, vocabulary, query, quantizer); 82 | 83 | std::vector results; 84 | index.query(query, tf, idf, numOfResults, results); 85 | 86 | for(uint i = 0; i < results.size(); i++) { 87 | cout << results[i].first << " " << files.getFilename(results[i].second).c_str()< []" 5 | } 6 | 7 | help() { 8 | cat << HELP 9 | usage: sse [--help] [] 10 | 11 | These are common sse commands used in various situations: 12 | 13 | filelist Collect image filelist 14 | extract Extract feature descriptors 15 | vocabulary Generate vocabulary 16 | quantize Quantize feature 17 | index Create inverted index file 18 | search Sketch Search 19 | 20 | Run 'sse --help' for more information on a command. 21 | HELP 22 | } 23 | 24 | if [ $# -lt 1 ]; then 25 | help 26 | exit 1 27 | fi 28 | 29 | SUB_COMMANDS="filelist extract vocabulary quantize index search extract_and_quantize" 30 | 31 | if [ "${SUB_COMMANDS/"$1"}" != "${SUB_COMMANDS}" ]; then 32 | $* 33 | elif [ "$1" == "-h" ]; then 34 | usage 35 | elif [ "$1" == "--help" ]; then 36 | help 37 | else 38 | echo "Unknown option: $1" 39 | usage 40 | fi 41 | 42 | 43 | -------------------------------------------------------------------------------- /tools/vocabulary.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Copyright (c) 2014 Zhang Dongdong 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | **************************************************************************/ 17 | #include 18 | 19 | using namespace std; 20 | 21 | #include "opensse/opensse.h" 22 | 23 | using namespace sse; 24 | 25 | void usages() 26 | { 27 | cout << "Usages: sse vocabulary -f features -n numclusters -o output" < > Cluster; 52 | 53 | cout << "cluster ..." <