From b59d0c2ea48836b890fcef8047188dfd8e463d36 Mon Sep 17 00:00:00 2001 From: Entscheider Date: Thu, 3 Dec 2020 16:57:45 +0100 Subject: [PATCH] Update project for recent OpenCV versions --- CMakeLists.txt | 4 ++-- Readme.md | 20 ++++++++++---------- apps/SimpleTest/main.cpp | 4 ++-- apps/SuperPixelGui/mainwindow.cpp | 4 ++-- apps/SuperPixelGui/utils.cpp | 21 +++------------------ lib/3rd/ThreadPool.h | 2 ++ lib/Pixel/ClusterSet.cpp | 2 +- lib/Voxel/RSlic3_impl.h | 4 ++-- 8 files changed, 24 insertions(+), 37 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7872745..217da22 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,9 +6,9 @@ CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11) CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X) if(COMPILER_SUPPORTS_CXX11) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread") elseif(COMPILER_SUPPORTS_CXX0X) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -pthread") else() message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.") endif() diff --git a/Readme.md b/Readme.md index 4aae62a..d0ea6e2 100644 --- a/Readme.md +++ b/Readme.md @@ -1,9 +1,9 @@ # Overview -RSlic is a library written in C++ for computing Superpixel and Supervoxel using OpenCV. It based on the Slic-Algorithmus (http://ivrg.epfl.ch/research/superpixels). +RSlic is a C++ library to compute Superpixels and Supervoxel and is based on OpenCV. It implements the [Slic-Algorithmus](https://web.archive.org/web/20170608065725/http://ivrl.epfl.ch/research/superpixels). # Features -- Compute Superpixel and Supervoxel -- Support for the zero parameter version of the SLIC algorithm (SLICO) +- Compute Superpixel (2D) and Supervoxel (3D) +- Support for the zero parameter version of the SLIC algorithm named SLICO - Support for custom metrics - Ability to save any iteration while computing (e.g. SuperPixelGUI makes use of it) @@ -38,10 +38,10 @@ add_executable(myproj main.cpp ...) target_link_libraries(myproj ${RSLIC_LIB}) ``` -By the way: Your project will (and have to) use C++11 now. +By doing this, your project will (and have to) use C++11. ## Including the files -If you would like to use Superpixel the simplest way would be to import RSlic/RSlic2H.h: +If you like to use Superpixel, the simplest way would be to import RSlic/RSlic2H.h: ```cpp #include @@ -55,7 +55,7 @@ and if you want to use Supervoxel: Of course you can use Superpixel and Supervoxel at the same time. ## Simple introduction RSlic -Executing the Slic-Algorithmus is very simple. Let's say you have a gray image img, want n Superpixel with a special stiffness. Then: +Executing the Slic-Algorithmus is very simple. Let's say you have a gray image `img` wnr want `n` Superpixel with a special stiffness. Then your code should look like: ```cpp #include @@ -73,8 +73,8 @@ for (int i=0; i < 10; i++){ //Do 10 Iterations slic = slic->finalize(); ``` -Now you can work with *slic*. Mainly you want to use -*slic->getClusters()*. See the documentation for more details. +Now you can work with `slic`. Mainly you want to use +`slic->getClusters()`. See the documentation for more details. You're not sure if you have a gray image or a colorful one? @@ -105,11 +105,11 @@ Slic2P slic = shutUpAndTakeMyMoney(img, n, hardness, false, 10); //Slic2P slic = shutUpAndTakeMyMoney(img, n, hardness, true, 10); ``` -Note that Slic is often intended to be applied on top of LAB images. So you may want to convert your image before using the functions above. (Use OpenCV for this) +Note that Slic is often intended to be applied on LAB images. So you may want to convert your image before using the functions above with, for instance, OpenCV. # 3rd Party Code This library uses the ThreaPool file from https://github.com/progschj/ThreadPool. The RSlic library uses threads if 'PARALLEL' is enabled in CMakeCache. # License -BSD license +This code is licensed under BSD-3 license diff --git a/apps/SimpleTest/main.cpp b/apps/SimpleTest/main.cpp index 1a56dff..0ca6180 100644 --- a/apps/SimpleTest/main.cpp +++ b/apps/SimpleTest/main.cpp @@ -132,7 +132,7 @@ int main(int argc, char **argv) { auto img = cv::imread(settings->filename, cv::IMREAD_UNCHANGED); if (img.type() == CV_8UC4) { - cv::cvtColor(img, img, CV_BGRA2BGR); + cv::cvtColor(img, img, cv::COLOR_BGRA2BGR); } auto grad = buildGrad(img); @@ -146,7 +146,7 @@ int main(int argc, char **argv) { switch (img.type()) { case CV_8UC3: - cvtColor(img, img_lab, CV_BGR2Lab); // See paper + cvtColor(img, img_lab, cv::COLOR_BGR2Lab); // See paper slic = Slic2::initialize(img_lab, grad, s, settings->stiffness, pool); break; case CV_8UC1: diff --git a/apps/SuperPixelGui/mainwindow.cpp b/apps/SuperPixelGui/mainwindow.cpp index 5d4a115..7762df0 100644 --- a/apps/SuperPixelGui/mainwindow.cpp +++ b/apps/SuperPixelGui/mainwindow.cpp @@ -46,7 +46,7 @@ void WorkerObject::work(cv::Mat m, SlicSetting *settings, QWidget* tabwdg) { int step = sqrt(m.cols * m.rows / settings->count); auto grad = RSlic::Pixel::buildGrad(m); emit message(tr("Initializing Slic ...")); - auto slic = RSlic::Pixel::Slic2::initialize(utils::makeLabIfNecessary(m), grad, step, settings->stiffness, pool); + auto slic = RSlic::Pixel::Slic2::initialize(::utils::makeLabIfNecessary(m), grad, step, settings->stiffness, pool); if (slic.get() == nullptr) { emit failed(tr("Wrong Parameter"), tr("No Superpixel can be build. May you should play with the parameters")); return; @@ -124,7 +124,7 @@ MainWindow::MainWindow(QWidget *parent) : colorClusterAction->setChecked(true); connect(colorClusterAction, SIGNAL(triggered(bool)), SLOT(setClusterFill(bool))); viewbar->addAction(colorClusterAction); - drawContourAction = new QAction("Draw", this); + drawContourAction = new QAction("Draw Edges", this); drawContourAction->setCheckable(true); colorClusterAction->setChecked(true); connect(drawContourAction, SIGNAL(triggered(bool)), SLOT(setClusterContour(bool))); diff --git a/apps/SuperPixelGui/utils.cpp b/apps/SuperPixelGui/utils.cpp index 2bcd2cb..0069f78 100644 --- a/apps/SuperPixelGui/utils.cpp +++ b/apps/SuperPixelGui/utils.cpp @@ -68,7 +68,7 @@ namespace { case QImage::Format_RGB888: { cv::Mat result = Policy::start(img, CV_8UC3); if (swap) { - cv::cvtColor(result, result, CV_RGB2BGR); + cv::cvtColor(result, result, cv::COLOR_RGB2BGR); } return result; } @@ -133,7 +133,7 @@ namespace { case CV_8UC3 : { if (swap) { - cv::cvtColor(mat, mat, CV_BGR2RGB); + cv::cvtColor(mat, mat, cv::COLOR_BGR2RGB); } return mat_to_qimage_ref_policy(mat, QImage::Format_RGB888); @@ -180,26 +180,11 @@ QImage utils::mat2QImage(const cv::Mat &src) { return mat_to_qimage_cpy(src, true); } -/* -cv::Mat utils::qImage2Mat(const QImage &img) -{ - return cv::Mat(img.height(), img.width(), CV_8UC3, - const_cast(img.bits()), - img.bytesPerLine()).clone(); -} -QImage utils::mat2QImage(const cv::Mat & src){ - //cv::Mat temp; - //cv::cvtColor(src, temp,CV_BGR2RGB); - QImage dest((const uchar *) src.data, src.cols, src.rows, src.step, QImage::Format_RGB888); - dest.bits(); - return dest.rgbSwapped(); -} -*/ cv::Mat utils::makeLabIfNecessary(const cv::Mat &m) { cv::Mat res; if (m.type() == CV_8UC3) { - cv::cvtColor(m, res, CV_BGR2Lab); + cv::cvtColor(m, res, cv::COLOR_BGR2Lab); } else res = m; return res; diff --git a/lib/3rd/ThreadPool.h b/lib/3rd/ThreadPool.h index a0c6d0a..13083b6 100644 --- a/lib/3rd/ThreadPool.h +++ b/lib/3rd/ThreadPool.h @@ -11,6 +11,8 @@ #include #include +#include + //https://github.com/progschj/ThreadPool class ThreadPool { public: diff --git a/lib/Pixel/ClusterSet.cpp b/lib/Pixel/ClusterSet.cpp index 1bf5a29..b6d6111 100644 --- a/lib/Pixel/ClusterSet.cpp +++ b/lib/Pixel/ClusterSet.cpp @@ -1,4 +1,4 @@ -#include "clusterset.h" +#include "ClusterSet.h" #include "../priv/Useful.h" using namespace RSlic::Pixel; diff --git a/lib/Voxel/RSlic3_impl.h b/lib/Voxel/RSlic3_impl.h index 06386f2..e8fecda 100644 --- a/lib/Voxel/RSlic3_impl.h +++ b/lib/Voxel/RSlic3_impl.h @@ -106,7 +106,7 @@ namespace RSlic { Mat_ label; Mat_ dist; - iterateCommonRes(const cv::Mat::MSize &size) : label(3, size, -1), dist(3, size, DINF) { + iterateCommonRes(const cv::MatSize &size) : label(3, size, -1), dist(3, size, DINF) { } inline double &distAt(int y, int x, int t) { @@ -128,7 +128,7 @@ namespace RSlic { } namespace { template - inline RSlic::Voxel::priv::iterateCommonResP iterateCommonIteration(F f, int beg, int end, const cv::Mat::MSize &size, const vector ¢ers, int s, ThreadPoolP pool) { + inline RSlic::Voxel::priv::iterateCommonResP iterateCommonIteration(F f, int beg, int end, const cv::MatSize &size, const vector ¢ers, int s, ThreadPoolP pool) { RSlic::Voxel::priv::iterateCommonResP result(new RSlic::Voxel::priv::iterateCommonRes(size)); const int w = size[1]; const int h = size[0];