Skip to content
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
23 changes: 23 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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)

target_link_libraries(barcodedetection 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 */

7 changes: 3 additions & 4 deletions include/ImageProcessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace artelab
{
class ImageProcessor
class ImageProcessor
{
public:

Expand All @@ -29,11 +29,10 @@ namespace artelab
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;
}

6 changes: 3 additions & 3 deletions nbproject/Makefile-Debug.mk
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ OBJECTFILES= \
${OBJECTDIR}/main.o \
${OBJECTDIR}/src/ArtelabDataset.o \
${OBJECTDIR}/src/HoughTransform.o \
${OBJECTDIR}/src/ImageProcessor.o \
${OBJECTDIR}/src/MLP.o \
${OBJECTDIR}/src/accuracy.o \
${OBJECTDIR}/src/detection.o \
Expand All @@ -48,7 +47,8 @@ OBJECTFILES= \
${OBJECTDIR}/utils-3rdparty/DirectoryInfo.o \
${OBJECTDIR}/utils-3rdparty/FileInfo.o \
${OBJECTDIR}/utils-3rdparty/TimeCounter.o \
${OBJECTDIR}/utils-3rdparty/utils.o
${OBJECTDIR}/utils-3rdparty/utils.o \
${OBJECTDIR}/src/ImageProcessor.o


# C Compiler Flags
Expand All @@ -65,7 +65,7 @@ FFLAGS=
ASFLAGS=

# Link Libraries and Options
LDLIBSOPTIONS=-lboost_filesystem -lboost_system -lboost_chrono -lboost_program_options -lopencv_core -lopencv_highgui -lopencv_ml -lopencv_imgproc
LDLIBSOPTIONS=-lboost_filesystem -lboost_system -lboost_chrono -lboost_program_options -lopencv_core -lopencv_highgui -lopencv_ml -lopencv_imgproc -lopencv_imgcodecs

# Build Targets
.build-conf: ${BUILD_SUBPROJECTS}
Expand Down
4 changes: 2 additions & 2 deletions nbproject/Makefile-Release.mk
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ OBJECTFILES= \
${OBJECTDIR}/main.o \
${OBJECTDIR}/src/ArtelabDataset.o \
${OBJECTDIR}/src/HoughTransform.o \
${OBJECTDIR}/src/ImageProcessor.o \
${OBJECTDIR}/src/MLP.o \
${OBJECTDIR}/src/accuracy.o \
${OBJECTDIR}/src/detection.o \
Expand All @@ -48,7 +47,8 @@ OBJECTFILES= \
${OBJECTDIR}/utils-3rdparty/DirectoryInfo.o \
${OBJECTDIR}/utils-3rdparty/FileInfo.o \
${OBJECTDIR}/utils-3rdparty/TimeCounter.o \
${OBJECTDIR}/utils-3rdparty/utils.o
${OBJECTDIR}/utils-3rdparty/utils.o \
${OBJECTDIR}/src/ImageProcessor.o


# C Compiler Flags
Expand Down
8 changes: 4 additions & 4 deletions src/ArtelabDataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ using std::vector;

namespace artelab
{
ArtelabDataset::ArtelabDataset(DirectoryInfo base)

ArtelabDataset::ArtelabDataset(DirectoryInfo base)
{
_base_dir = base;
}

ArtelabDataset::ArtelabDataset(const ArtelabDataset& orig)
ArtelabDataset::ArtelabDataset(const ArtelabDataset& orig)
{
*this = orig;
}
Expand Down Expand Up @@ -71,4 +71,4 @@ namespace artelab
return _data;
}

}
}
8 changes: 4 additions & 4 deletions src/HoughTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace artelab
HoughTransform::HoughTransform()
{
init();
}
}

HoughTransform::HoughTransform(cv::Mat image, bool keep_loc)
{
Expand All @@ -53,7 +53,7 @@ namespace artelab
delete [] cos_cache;
}

HoughTransform::HoughTransform(const HoughTransform& orig)
HoughTransform::HoughTransform(const HoughTransform& orig)
{
*this = orig;
}
Expand Down Expand Up @@ -98,7 +98,7 @@ namespace artelab
int hough_height = hough_space.cols / 2;
r += hough_height;

if (r < 0 || r >= hough_height*2)
if (r < 0 || r >= hough_height*2)
continue;

hough_space.at<uint>(t, r)++;
Expand Down Expand Up @@ -162,4 +162,4 @@ namespace artelab
return out_image;
}

}
}
Loading