Skip to content

Instantly share code, notes, and snippets.

@raytroop
Last active September 28, 2019 11:54
Show Gist options
  • Save raytroop/9e2a398a593eba67a41558a9e8753471 to your computer and use it in GitHub Desktop.
Save raytroop/9e2a398a593eba67a41558a9e8753471 to your computer and use it in GitHub Desktop.
cmake_minimum_required(VERSION 3.12)
project(annoTool)
set(CMAKE_CXX_STANDARD 11)
find_package(gflags REQUIRED)
find_package(glog REQUIRED)
# find required opencv
find_package(OpenCV REQUIRED)
# name of executable file and path of source file
add_executable(annoTool main.cpp)
# opencv libraries
target_link_libraries(annoTool ${OpenCV_LIBS} glog::glog)
# directory of opencv headers
target_include_directories(annoTool PUBLIC ${OpenCV_INCLUDE_DIRS})
#include <iostream>
#include <string>
#include <fstream>
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include "gflags/gflags.h"
using std::cout;
using std::cin;
using std::endl;
using cv::Mat;
using cv::imread;
using cv::waitKey;
using std::stringstream;
DEFINE_string(imglist, "./image.list","img list to annotate");
DEFINE_string(annoresult, "./anno.list","file to store annotation");
int main(int argc, char* argv[]) {
gflags::ParseCommandLineFlags(&argc, &argv, true);
std::ifstream imgpaths;
std::string line;
imgpaths.open(FLAGS_imglist);
std::ofstream annrecord(FLAGS_annoresult);
while(!imgpaths.eof()) {
getline(imgpaths,line);
Mat src = imread(line);
if (src.empty()) continue;
stringstream s;
s << line;
s << "\t";
imshow(line, src);
char c = 0;
c = waitKey(0);
while (c != '1' && c != '2' && c != '3')
{
c = waitKey(0);
cout << "invaid input!\n";
}
s << c;
cout << s.str() << endl;
annrecord << s.str() << endl;
cv::destroyWindow(line);
}
imgpaths.close();
annrecord.close();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment