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

Movie loader #3

Open
wants to merge 7 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
4 changes: 4 additions & 0 deletions .clang_complete
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-DBarcode3rdParty_EXPORTS
-DBarcodeLibrary_EXPORTS
-I/home/kurohi/Progs/BarcodeDetectionHough/include
-I/home/kurohi/Progs/BarcodeDetectionHough/utils-3rdparty
25 changes: 25 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
cmake_minimum_required (VERSION 2.9.0)
project (BarcodeDetectionHough)

find_package(OpenCV 3.4 REQUIRED)

add_definitions(-std=c++11)

find_package(Boost COMPONENTS filesystem system chrono program_options REQUIRED)
include_directories (${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
add_definitions(${Boost_DEFINITIONS})

include_directories("${CMAKE_SOURCE_DIR}/include")
include_directories("${CMAKE_SOURCE_DIR}/utils-3rdparty")

file(GLOB SOURCES "${CMAKE_SOURCE_DIR}/src/*.cpp")
file(GLOB SOURCES_3RD_PARTY "${CMAKE_SOURCE_DIR}/utils-3rdparty/*.cpp")
add_library(BarcodeLibrary SHARED ${SOURCES})
add_library(Barcode3rdParty SHARED ${SOURCES_3RD_PARTY})

add_executable (barcodedetection main.cpp)
add_executable (barcodeonmovie main_movie.cpp)

target_link_libraries(barcodedetection BarcodeLibrary Barcode3rdParty ${OpenCV_LIBS} ${Boost_LIBRARIES})
target_link_libraries(barcodeonmovie BarcodeLibrary Barcode3rdParty ${OpenCV_LIBS} ${Boost_LIBRARIES})
7 changes: 4 additions & 3 deletions README
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Requirements
----

° Any C++08 compiler (actually used g++ 4.8.1)
° OpenCv 2.4.* with Qt 4 support enabled
° Boost 1.53 or more recent builds
° Any C++08 compiler (actually used g++ 9.1.0)
° OpenCv 3.4.* with Qt 4 support enabled
° Boost 1.65 or more recent builds



Expand All @@ -24,6 +24,7 @@ In order to facilitate it, the shared library linked by the makefile are:
° opencv_highgui
° opencv_ml
° opencv_imgproc
° opencv_imgcodecs

If you encounter any problem check if the required libraries are installed in your system.

Expand Down
6 changes: 3 additions & 3 deletions include/ArtelabDataset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
#define BARCODEDATASET_HPP

#include <opencv2/core/core.hpp>
#include <map>
#include "DirectoryInfo.hpp"

namespace artelab
{

class ArtelabDataset
class ArtelabDataset
{
public:

typedef struct
typedef struct
{
FileInfo original;
FileInfo detection_gt;
Expand All @@ -37,4 +38,3 @@ namespace artelab
}

#endif /* BARCODEDATASET_HPP */

4 changes: 2 additions & 2 deletions include/HoughTransform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
#define HOUGHTRANSFORM_HPP

#include <opencv2/core/core.hpp>
#include <map>

namespace artelab
{

class HoughTransform
class HoughTransform
{
public:

Expand Down Expand Up @@ -56,4 +57,3 @@ namespace artelab
}

#endif /* HOUGHTRANSFORM_HPP */

41 changes: 22 additions & 19 deletions include/ImageProcessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,33 @@

namespace artelab
{
class ImageProcessor
{
public:
class ImageProcessor
{
public:

ImageProcessor(std::string mlp_file, cv::Size win_size, std::string outdir="", bool quiet=false, bool show=false);
virtual ~ImageProcessor();
ImageProcessor(std::string mlp_file, cv::Size win_size, std::string outdir="", bool quiet=false, bool show=false);
virtual ~ImageProcessor();

ImageProcessor& show(bool b=true);
ImageProcessor& set_output(std::string outdir);
ImageProcessor& show(bool b=true);
ImageProcessor& set_output(std::string outdir);

results process(std::string imagename, ArtelabDataset::barcode_image barcode);
results process(std::string imagename, ArtelabDataset::barcode_image barcode);
cv::Mat processSimple(cv::Mat img, double& angle);
void drawRectangles(cv::Mat& img_bb, cv::Rect rect, double angle);
std::vector<cv::Rect> getRectangles(cv::Mat img_hist_projection, double angle);

private:

MLP _mlp;
cv::Size _winsize;
DirectoryInfo _output;
bool _show;
bool _quiet;

void show_image(std::string name, cv::Mat img);
};
private:

MLP _mlp;
cv::Size _winsize;
DirectoryInfo _output;
bool _show;
bool _quiet;

void show_image(std::string name, cv::Mat img);
};

}

#endif /* IMAGEPROCESSOR_HPP */

#endif /* IMAGEPROCESSOR_HPP */
5 changes: 2 additions & 3 deletions include/MLP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace artelab
{

class MLP
class MLP
{
public:

Expand All @@ -23,10 +23,9 @@ namespace artelab
void predict(const cv::Mat& samples, cv::Mat& outPredictions);

private:
cv::NeuralNet_MLP _model;
cv::Ptr<cv::ml::ANN_MLP> _model;
};

}

#endif /* MLP_H */

7 changes: 3 additions & 4 deletions include/accuracy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
namespace artelab
{

typedef struct
{
double jaccard;
typedef struct
{
double jaccard;
cv::Mat jaccard_hist;
double time;
} results;
Expand All @@ -22,4 +22,3 @@ namespace artelab
}

#endif /* ACCURACY_HPP */

3 changes: 1 addition & 2 deletions include/detection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
#include <opencv2/core/core.hpp>

namespace artelab
{
{

std::vector<cv::Rect> object_rectangles(cv::Mat feature_image, int thresh=70);

}

#endif /* DETECTION_HPP */

3 changes: 1 addition & 2 deletions include/mlp_threshold.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@

namespace artelab
{

cv::Mat threshold_mlp(MLP& nnetwork, cv::Size win_size, HoughTransform& hough);

}

#endif /* MAKE_PATTERNS_HPP */

45 changes: 23 additions & 22 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ vector<string> imagenames_to_process(FileInfo file)
vector<string> names;
std::ifstream infile;
infile.open(file.fullName().c_str());

while(!infile.eof())
{
string line;
Expand All @@ -43,12 +43,13 @@ vector<string> imagenames_to_process(FileInfo file)
return names;
}

int main(int argc, char** argv)
{
int main(int argc, char** argv)
{
po::options_description desc("Usage");
desc.add_options()
("help", "print help")
("dataset,d", po::value<string>()->default_value(datasetdir), "dataset directory")
("netfile,n", po::value<string>()->default_value(netfile), "trained network file")
("output,o", po::value<string>()->default_value(outdir), "if specified, intermediate images are saved there")
("whitelist,w", po::value<string>()->default_value(whitelist), "list of image names to process")
("show,s", "show intermediate images")
Expand All @@ -57,55 +58,56 @@ int main(int argc, char** argv)

po::variables_map vm;
po::store(po::parse_command_line(argc, argv, desc), vm);
po::notify(vm);
po::notify(vm);

if (vm.count("help"))
{
cout << desc << endl;
return EXIT_SUCCESS;
}

datasetdir = vm["dataset"].as<string>();
outdir = vm["output"].as<string>();
whitelist = vm["whitelist"].as<string>();
display = vm.count("show") > 0;
quiet = vm.count("quiet") > 0;

netfile = vm["netfile"].as<string>();

DirectoryInfo dataset_dir(datasetdir);

ArtelabDataset dataset(dataset_dir);
dataset.load_dataset();
if(!quiet) cout << "Dataset Loaded: " << dataset.count() << " Images" << endl;

cv::Size win_size(61, 3);

std::map<string, barcodeimage> images = dataset.get_barcodes();
std::map<string, barcodeimage>::iterator it;

vector<string> white_list;
if(whitelist != "")
if(whitelist != "")
white_list = imagenames_to_process(FileInfo(whitelist));

double accuracy = 0, time = 0;
int count = 0;
cv::Mat jaccard_hist = cv::Mat::zeros(10, 1, CV_32F);

ImageProcessor pr(netfile, win_size, outdir, quiet, display);

for(it = images.begin(); it != images.end(); it++)
{
if(white_list.size() > 0 && std::find(white_list.begin(), white_list.end(), it->first) == white_list.end())
{
continue;
}

results res = pr.process(it->first, it->second);

accuracy += res.jaccard;
time += res.time;
jaccard_hist += res.jaccard_hist;
count++;

if(display)
{
char c;
Expand All @@ -114,15 +116,14 @@ int main(int argc, char** argv)
c = cv::waitKey();
} while (c != 32);
}

}
cout << endl

cout << endl
<< "Number of images: " << count << endl
<< "TOTAL ACCURACY (jaccard): " << accuracy/count << endl
<< "TOTAL ACCURACY BY THRESHOLD (jaccard): " << jaccard_hist/count << endl
<< "Average time (sec): " << time/count << endl;

return EXIT_SUCCESS;
}

Loading