Skip to content

Commit

Permalink
Update project for recent OpenCV versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Entscheider committed Dec 3, 2020
1 parent 55661f7 commit b59d0c2
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 37 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
20 changes: 10 additions & 10 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -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 <RSlic/RSlic2H.h>
Expand All @@ -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 <RSlic/RSlic2H.h>
Expand All @@ -73,8 +73,8 @@ for (int i=0; i < 10; i++){ //Do 10 Iterations
slic = slic->finalize<distanceGray>();
```
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?
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions apps/SimpleTest/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions apps/SuperPixelGui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)));
Expand Down
21 changes: 3 additions & 18 deletions apps/SuperPixelGui/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<uchar*>(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;
Expand Down
2 changes: 2 additions & 0 deletions lib/3rd/ThreadPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include <functional>
#include <stdexcept>

#include <stddef.h>

//https://github.com/progschj/ThreadPool
class ThreadPool {
public:
Expand Down
2 changes: 1 addition & 1 deletion lib/Pixel/ClusterSet.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "clusterset.h"
#include "ClusterSet.h"
#include "../priv/Useful.h"

using namespace RSlic::Pixel;
Expand Down
4 changes: 2 additions & 2 deletions lib/Voxel/RSlic3_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ namespace RSlic {
Mat_<ClusterInt> label;
Mat_<double> 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) {
Expand All @@ -128,7 +128,7 @@ namespace RSlic {
}
namespace {
template<typename F>
inline RSlic::Voxel::priv::iterateCommonResP iterateCommonIteration(F f, int beg, int end, const cv::Mat::MSize &size, const vector<Vec3i> &centers, int s, ThreadPoolP pool) {
inline RSlic::Voxel::priv::iterateCommonResP iterateCommonIteration(F f, int beg, int end, const cv::MatSize &size, const vector<Vec3i> &centers, 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];
Expand Down

0 comments on commit b59d0c2

Please sign in to comment.