Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve cmake (portable on all OSes), add appveyor and travis CI #148

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 32 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
# Build files
/CMakeCache.txt
/CMakeFiles/
/Makefile
/cmake_install.cmake
/yolo_mark
*.o
*.a
*.dSYM
*.csv
*.out
*.png
*.so
*.exe
*.dll
*.lib
build_*/
*.weights

# OS Generated #
.DS_Store*
ehthumbs.db
Icon?
Thumbs.db
*.swp

# IDE generated #
.vs/
.vscode/

#Build artifacts
yolo_mark

#Examples
data/*
data
examples/

70 changes: 70 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
language: cpp
cache:
timeout: 1000
directories:
- $HOME/vcpkg

matrix:
include:

- os: osx
compiler: clang
name: macOS - native clang - opencv@3
env:
- OpenCV_DIR="/usr/local/opt/opencv@3/"
- additional_defines="-DOpenCV_DIR=${OpenCV_DIR}"
- MATRIX_EVAL="brew install opencv@3"

- os: osx
compiler: clang
name: macOS - native clang - opencv(latest)
env:
- additional_defines=""
- MATRIX_EVAL="brew install opencv"

- os: osx
name: macOS - vcpkg
osx_image: xcode10.1
env:
- additional_defines=""
- MATRIX_EVAL="brew install gcc && unset CC && unset CXX"
- USE_VCPKG=true
- VCPKG_DEFINES="-DCMAKE_TOOLCHAIN_FILE=$HOME/vcpkg/scripts/buildsystems/vcpkg.cmake"

- os: linux
dist: bionic
compiler: gcc
name: ubuntu 18.04 - gcc - vcpkg
env:
- additional_defines=""
- USE_VCPKG=true
- VCPKG_DEFINES="-DCMAKE_TOOLCHAIN_FILE=$HOME/vcpkg/scripts/buildsystems/vcpkg.cmake"
- MATRIX_EVAL=""

before_install:
- travis_retry eval "${MATRIX_EVAL}"

install:
# CMake upgrade on Linux
- if [[ "$TRAVIS_OS_NAME" == "linux" ]] ; then wget --no-check-certificate https://github.com/Kitware/CMake/releases/download/v3.13.4/cmake-3.13.4-Linux-x86_64.tar.gz ; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]] ; then tar -xzf cmake-3.13.4-Linux-x86_64.tar.gz ; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]] ; then export PATH=$PWD/cmake-3.13.4-Linux-x86_64/bin:$PATH ; fi
- pushd $HOME
- if [ -d "$HOME/vcpkg/.git" ] ; then echo vcpkg cached ; else rm -rf vcpkg ; git clone https://github.com/Microsoft/vcpkg ; fi
- cd vcpkg
- git pull
- if [ "${USE_VCPKG}" = true ] ; then ./bootstrap-vcpkg.sh ; fi
- if [ "${USE_VCPKG}" = true ] ; then echo "set(VCPKG_BUILD_TYPE release)" >> triplets/x64-osx.cmake ; fi
- if [ "${USE_VCPKG}" = true ] ; then echo "set(VCPKG_BUILD_TYPE release)" >> triplets/x64-linux.cmake ; fi
- if [ "${USE_VCPKG}" = true ] ; then travis_wait 45 ./vcpkg install opencv[contrib] --recurse ; fi
- popd

before_script:
- echo ${additional_defines}
- mkdir build_release
- cd build_release
- cmake .. -DCMAKE_BUILD_TYPE="Release" ${VCPKG_DEFINES} ${additional_defines}
- cd ..

script:
- cd build_release && cmake --build . --target install -- -j8 && cd ..
60 changes: 53 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,57 @@
cmake_minimum_required(VERSION 2.8)
project( yolo_mark CXX )
find_package( OpenCV REQUIRED )
cmake_minimum_required(VERSION 3.2)

set( sources main.cpp )
set(Yolo_mark_MAJOR_VERSION 1)
set(Yolo_mark_MINOR_VERSION 0)
set(Yolo_mark_PATCH_VERSION 0)
set(Yolo_mark_VERSION ${Yolo_mark_MAJOR_VERSION}.${Yolo_mark_MINOR_VERSION}.${Yolo_mark_PATCH_VERSION})

add_executable( yolo_mark ${sources} )
set(CMAKE_VERBOSE_MAKEFILE "FALSE" CACHE BOOL "Create verbose makefile")

target_compile_options( yolo_mark PUBLIC -std=c++11 -fpermissive -w -Wall )
if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE STRING "")
message(STATUS "VCPKG found: $ENV{VCPKG_ROOT}")
message(STATUS "Using VCPKG integration")
endif()

target_link_libraries( yolo_mark ${OpenCV_LIBS} -L/usr/lib64 -ldl )
project(Yolo_mark VERSION ${Yolo_mark_VERSION})

enable_language(CXX)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/Modules/" ${CMAKE_MODULE_PATH})

if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_LIST_DIR}" CACHE PATH "Install prefix" FORCE)
endif()
set(INSTALL_BIN_DIR "${CMAKE_CURRENT_LIST_DIR}" CACHE PATH "Path where exe will be installed")

find_package(OpenCV REQUIRED)

if(TARGET opencv_world)
list(APPEND OpenCV_LINKED_COMPONENTS "opencv_world")
else()
if(TARGET opencv_video)
list(APPEND OpenCV_LINKED_COMPONENTS "opencv_video")
endif()
if(TARGET opencv_videoio)
list(APPEND OpenCV_LINKED_COMPONENTS "opencv_videoio")
endif()
if(TARGET opencv_highgui)
list(APPEND OpenCV_LINKED_COMPONENTS "opencv_highgui")
endif()
if(TARGET opencv_imgproc)
list(APPEND OpenCV_LINKED_COMPONENTS "opencv_imgproc")
endif()
if(TARGET opencv_imgcodecs)
list(APPEND OpenCV_LINKED_COMPONENTS "opencv_imgcodecs")
endif()
if(TARGET opencv_core)
list(APPEND OpenCV_LINKED_COMPONENTS "opencv_core")
endif()
endif()

set(Yolo_mark_SOURCES "${CMAKE_CURRENT_LIST_DIR}/src/main.cpp")

add_executable(yolo_mark ${Yolo_mark_SOURCES})
target_link_libraries(yolo_mark ${OpenCV_LINKED_COMPONENTS})
install(TARGETS yolo_mark DESTINATION "${INSTALL_BIN_DIR}")
126 changes: 48 additions & 78 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,103 +1,73 @@
# Yolo_mark
**Windows** & **Linux** GUI for marking bounded boxes of objects in images for training Yolo v3 and v2

* To compile on **Windows** open `yolo_mark.sln` in MSVS2013/2015, compile it **x64 & Release** and run the file: `x64/Release/yolo_mark.cmd`. Change paths in `yolo_mark.sln` to the OpenCV 2.x/3.x installed on your computer:
GUI for marking bounding boxes of objects in images for training Yolo

* (right click on project) -> properties -> C/C++ -> General -> Additional Include Directories: `C:\opencv_3.0\opencv\build\include;`

* (right click on project) -> properties -> Linker -> General -> Additional Library Directories: `C:\opencv_3.0\opencv\build\x64\vc14\lib;`
* To build the tool, you need a compiler, cmake and OpenCV. Then run:

* To compile on **Linux** type in console 3 commands:
```
cmake .
make
./linux_mark.sh
```
```bash
cmake .
make
./run.sh (or run.cmd on Windows)
```

Supported both: OpenCV 2.x and OpenCV 3.x
There are also build scripts (`build.sh` and `build.ps1`) to ease building on *nix systems and on windows.

--------
To use for labeling your custom images:

1. To test, simply run
* **on Windows:** `x64/Release/yolo_mark.cmd`
* **on Linux:** `./linux_mark.sh`
* delete all files from directory `data/img`
* put your `.jpg`-images to this directory `data/img`
* change numer of classes (objects for detection) in file [`data/obj.data`](data/obj.data#L1)
* put names of objects, one for each line in file [`data/obj.names`](data/obj.names)
* run file: `yolo_mark.cmd`

2. To use for labeling your custom images:
To train the net for your custom objects, you should change 2 lines in file `yolo-obj.cfg`:

* delete all files from directory `x64/Release/data/img`
* put your `.jpg`-images to this directory `x64/Release/data/img`
* change numer of classes (objects for detection) in file `x64/Release/data/obj.data`: https://github.com/AlexeyAB/Yolo_mark/blob/master/x64/Release/data/obj.data#L1
* put names of objects, one for each line in file `x64/Release/data/obj.names`: https://github.com/AlexeyAB/Yolo_mark/blob/master/x64/Release/data/obj.names
* run file: `x64\Release\yolo_mark.cmd`
* [set number of classes (objects)](yolo-obj.cfg#L230)
* set `filter`-value
* [For Yolo-v2 `(classes + 5)*5`](yolo-obj.cfg#L224)
* For Yolo-v3 `(classes + 5)*3`
* Download [pre-trained weights](http://pjreddie.com/media/files/darknet19_448.conv.23) for the convolutional layers
* Put files: `yolo-obj.cfg`, `data/train.txt`, `data/obj.names`, `data/obj.data`, `darknet19_448.conv.23` and directory `data/img` near with executable `darknet`-file, and start training: `darknet detector train data/obj.data yolo-obj.cfg darknet19_448.conv.23`

3. To training for your custom objects, you should change 2 lines in file `x64/Release/yolo-obj.cfg`:
For a detailed description, see [darknet repo](https://github.com/AlexeyAB/darknet#how-to-train-to-detect-your-custom-objects)

* set number of classes (objects): https://github.com/AlexeyAB/Yolo_mark/blob/master/x64/Release/yolo-obj.cfg#L230
* set `filter`-value
* For Yolov2 `(classes + 5)*5`: https://github.com/AlexeyAB/Yolo_mark/blob/master/x64/Release/yolo-obj.cfg#L224
* For Yolov3 `(classes + 5)*3`
## How to get frames from video files

3.1 Download pre-trained weights for the convolutional layers (76 MB): http://pjreddie.com/media/files/darknet19_448.conv.23

3.2 Put files: `yolo-obj.cfg`, `data/train.txt`, `data/obj.names`, `data/obj.data`, `darknet19_448.conv.23` and directory `data/img` near with executable `darknet`-file, and start training: `darknet detector train data/obj.data yolo-obj.cfg darknet19_448.conv.23`
To get frames from video files (save each N frame, in example N=10), you can use this command:

For a detailed description, see: https://github.com/AlexeyAB/darknet#how-to-train-to-detect-your-custom-objects

----

#### How to get frames from videofile:

To get frames from videofile (save each N frame, in example N=10), you can use this command:
* on Windows: `yolo_mark.exe data/img cap_video test.mp4 10`
* on Linux: `./yolo_mark x64/Release/data/img cap_video test.mp4 10`

Directory `data/img` should be created before this. Also on Windows, the file `opencv_ffmpeg340_64.dll` from `opencv\build\bin` should be placed near with `yolo_mark.exe`.
Directory `data/img` should be created before this.

As a result, many frames will be collected in the directory `data/img`. Then you can label them manually using such command

As a result, many frames will be collected in the directory `data/img`. Then you can label them manually using such command:
* on Windows: `yolo_mark.exe data/img data/train.txt data/obj.names`
* on Linux: `./yolo_mark x64/Release/data/img x64/Release/data/train.txt x64/Release/data/obj.names`

----

#### Here are:
## Instruction manual

* /x64/Release/
* `yolo_mark.cmd` - example hot to use yolo mark: `yolo_mark.exe data/img data/train.txt data/obj.names`
* `train_obj.cmd` - example how to train yolo for your custom objects (put this file near with darknet.exe): `darknet.exe detector train data/obj.data yolo-obj.cfg darknet19_448.conv.23`
* `yolo-obj.cfg` - example of yoloV3-neural-network for 2 object
* /x64/Release/data/
* `obj.names` - example of list with object names
* `obj.data` - example with configuration for training Yolo v3
* `train.txt` - example with list of image filenames for training Yolo v3

* /x64/Release/data/img/`air4.txt` - example with coordinates of objects on image `air4.jpg` with aircrafts (class=0)
### Mouse control

![Image of Yolo_mark](https://habrastorage.org/files/229/f06/277/229f06277fcc49279342b7edfabbb47a.jpg)

### Instruction manual

#### Mouse control

Button | Description |
--- | --- |
Button | Description
--- | ---
Left | Draw box
Right | Move box

#### Keyboard Shortcuts

Shortcut | Description |
--- | --- |
<kbd>→</kbd> | Next image |
<kbd>←</kbd> | Previous image |
<kbd>r</kbd> | Delete selected box (mouse hovered) |
<kbd>c</kbd> | Clear all marks on the current image |
<kbd>p</kbd> | Copy previous mark |
<kbd>o</kbd> | Track objects |
<kbd>ESC</kbd> | Close application |
<kbd>n</kbd> | One object per image |
<kbd>0-9</kbd> | Object id |
<kbd>m</kbd> | Show coords |
<kbd>w</kbd> | Line width |
<kbd>k</kbd> | Hide object name |
<kbd>h</kbd> | Help |

### Keyboard Shortcuts

Shortcut | Description
--- | ---
<kbd>→</kbd> | Next image
<kbd>←</kbd> | Previous image
<kbd>r</kbd> | Delete selected box (mouse hovered)
<kbd>c</kbd> | Clear all marks on the current image
<kbd>p</kbd> | Copy previous mark
<kbd>o</kbd> | Track objects
<kbd>ESC</kbd> | Close application
<kbd>n</kbd> | One object per image
<kbd>0-9</kbd> | Object id
<kbd>m</kbd> | Show coords
<kbd>w</kbd> | Line width
<kbd>k</kbd> | Hide object name
<kbd>h</kbd> | Help
57 changes: 57 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
image: Visual Studio 2017
clone_folder: c:\projects\Yolo_mark
cache: C:\Tools\vcpkg\installed\

environment:
WORKSPACE: C:\projects
matrix:
- platform: Cygwin64
COMPILER: cygwin
CYGWIN_NOWINPATH: yes
CYGSH: C:\cygwin64\bin\bash -c
- platform: Win64
COMPILER: vs
configuration: Release
VCPKG_ROOT: C:\Tools\vcpkg
VCPKG_DEFAULT_TRIPLET: x64-windows

install:
- if [%COMPILER%]==[vs] cinst cmake ninja
- if [%COMPILER%]==[vs] set "PATH=C:\Program Files\CMake\bin;%PATH%"
- if [%COMPILER%]==[vs] call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x64
- if [%COMPILER%]==[cygwin] SET "PATH=C:\cygwin64\usr\local\bin;C:\cygwin64\bin;C:\cygwin64\usr\bin;%PATH%"
- if [%COMPILER%]==[cygwin] SET PATH=%PATH:C:\Program Files\Git\usr\bin;=%
- git submodule -q update --init --recursive
- cd %WORKSPACE%\
- cd %WORKSPACE%\
- mkdir cygwin-downloads
- ps: if($env:COMPILER -eq "cygwin") { Invoke-WebRequest https://cygwin.com/setup-x86_64.exe -OutFile $env:WORKSPACE\cygwin-setup.exe }
- if [%COMPILER%]==[cygwin] %WORKSPACE%\cygwin-setup.exe --quiet-mode --no-shortcuts --no-startmenu --no-desktop --upgrade-also --root C:\cygwin64 --local-package-dir %WORKSPACE%\cygwin-downloads --packages gcc-g++,cmake,libopencv-devel,libncurses-devel
- ps: if($env:COMPILER -eq "cygwin") { Invoke-WebRequest https://github.com/Kitware/CMake/releases/download/v3.14.0/cmake-3.14.0.tar.gz -OutFile $env:WORKSPACE\cmake-3.14.0.tar.gz }
- if [%COMPILER%]==[cygwin] %CYGSH% 'tar zxvf cmake-3.14.0.tar.gz'
- if [%COMPILER%]==[cygwin] cd %WORKSPACE%\cmake-3.14.0
- if [%COMPILER%]==[cygwin] %CYGSH% 'cmake .'
- if [%COMPILER%]==[cygwin] %CYGSH% 'make -j8'
- if [%COMPILER%]==[cygwin] %CYGSH% 'make install'
- if [%COMPILER%]==[cygwin] cd %WORKSPACE%
- if [%COMPILER%]==[vs] cd %VCPKG_ROOT%
- if [%COMPILER%]==[vs] git pull
- if [%COMPILER%]==[vs] .\bootstrap-vcpkg.bat
- if [%COMPILER%]==[vs] echo set(VCPKG_BUILD_TYPE release) >> triplets\%VCPKG_DEFAULT_TRIPLET%.cmake
- if [%COMPILER%]==[vs] .\vcpkg.exe install opencv[contrib] --recurse
- cd %WORKSPACE%\Yolo_mark\
- mkdir build_debug && cd build_debug
- if [%COMPILER%]==[cygwin] %CYGSH% 'cmake .. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE="Debug"'
- cd ..
- mkdir build_release && cd build_release
- if [%COMPILER%]==[cygwin] %CYGSH% 'cmake .. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE="Release"'
- if [%COMPILER%]==[vs] if [%configuration%]==[Release] cmake -G "Visual Studio 15 2017" -T "host=x64" -A "x64" "-DCMAKE_TOOLCHAIN_FILE=%VCPKG_ROOT%\scripts\buildsystems\vcpkg.cmake" "-DVCPKG_TARGET_TRIPLET=%VCPKG_DEFAULT_TRIPLET%" -DCMAKE_BUILD_TYPE="Release" ..
- cd ..

build_script:
- if [%COMPILER%]==[cygwin] cd build_debug && %CYGSH% 'cmake --build . --target install -- -j8' && cd ..
- if [%COMPILER%]==[cygwin] cd build_release && %CYGSH% 'cmake --build . --target install -- -j8' && cd ..
- if [%COMPILER%]==[vs] if [%configuration%]==[Release] cd build_release && cmake --build . --config Release --parallel 8 --target install && cd ..

artifacts:
- path: '*.exe'
Loading