Commit c9e3e220 authored by Maximilien Cuony's avatar Maximilien Cuony Committed by Maximilien Cuony

Implementation of SelectiveSearchSegmentation

parent ef4dd5e5
......@@ -8,3 +8,4 @@ Extended Image Processing
5. Joint Bilateral Filter
6. Superpixels
7. Graph segmentation
8. Selective search from segmentation
......@@ -67,6 +67,18 @@
publisher={Springer}
}
@article{uijlings2013selective,
title={Selective search for object recognition},
author={Uijlings, Jasper RR and van de Sande, Koen EA and Gevers, Theo and Smeulders, Arnold WM},
journal={International journal of computer vision},
volume={104},
number={2},
pages={154--171},
year={2013},
publisher={Springer}
}
@article{Min2014,
title={Fast global image smoothing based on weighted least squares},
author={Min, Dongbo and Choi, Sunghwan and Lu, Jiangbo and Ham, Bumsub and Sohn, Kwanghoon and Do, Minh N},
......
......@@ -32,13 +32,16 @@ the use of this software, even if advised of the possibility of such damage.
#include "opencv2/ximgproc/segmentation.hpp"
#include "opencv2/highgui.hpp"
#include <opencv2/core/utility.hpp>
#include <opencv2/opencv.hpp>
#include "opencv2/core.hpp"
#include "opencv2/imgproc.hpp"
#include <iostream>
using namespace cv;
using namespace cv::ximgproc::segmentation;
Scalar hsv_to_rgb(Scalar);
Scalar color_mapping(int);
static void help() {
std::cout << std::endl <<
"A program demonstrating the use and capabilities of a particular graph based image" << std::endl <<
......@@ -55,9 +58,9 @@ Scalar hsv_to_rgb(Scalar c) {
float * p = in.ptr<float>(0);
p[0] = c[0] * 360;
p[1] = c[1];
p[2] = c[2];
p[0] = (float)c[0] * 360.0f;
p[1] = (float)c[1];
p[2] = (float)c[2];
cvtColor(in, out, COLOR_HSV2RGB);
......@@ -97,7 +100,7 @@ int main(int argc, char** argv) {
gs->setSigma(atof(argv[3]));
if (argc > 4)
gs->setK(atoi(argv[4]));
gs->setK((float)atoi(argv[4]));
if (argc > 5)
gs->setMinSize(atoi(argv[5]));
......@@ -137,9 +140,9 @@ int main(int argc, char** argv) {
for (int j = 0; j < output.cols; j++) {
Scalar color = color_mapping(p[j]);
p2[j*3] = color[0];
p2[j*3 + 1] = color[1];
p2[j*3 + 2] = color[2];
p2[j*3] = (uchar)color[0];
p2[j*3 + 1] = (uchar)color[1];
p2[j*3 + 2] = (uchar)color[2];
}
}
......
/*
By downloading, copying, installing or using the software you agree to this
license. If you do not agree to this license, do not download, install,
copy or use the software.
License Agreement
For Open Source Computer Vision Library
(3-clause BSD License)
Copyright (C) 2013, OpenCV Foundation, all rights reserved.
Third party copyrights are property of their respective owners.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the names of the copyright holders nor the names of the contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
This software is provided by the copyright holders and contributors "as is" and
any express or implied warranties, including, but not limited to, the implied
warranties of merchantability and fitness for a particular purpose are
disclaimed. In no event shall copyright holders or contributors be liable for
any direct, indirect, incidental, special, exemplary, or consequential damages
(including, but not limited to, procurement of substitute goods or services;
loss of use, data, or profits; or business interruption) however caused
and on any theory of liability, whether in contract, strict liability,
or tort (including negligence or otherwise) arising in any way out of
the use of this software, even if advised of the possibility of such damage.
*/
#include "opencv2/ximgproc/segmentation.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/core.hpp"
#include "opencv2/imgproc.hpp"
#include <iostream>
#include <ctime>
using namespace cv;
using namespace cv::ximgproc::segmentation;
static void help() {
std::cout << std::endl <<
"A program demonstrating the use and capabilities of a particular image segmentation algorithm described" << std::endl <<
" in Jasper R. R. Uijlings, Koen E. A. van de Sande, Theo Gevers, Arnold W. M. Smeulders: " << std::endl <<
" \"Selective Search for Object Recognition\"" << std::endl <<
"International Journal of Computer Vision, Volume 104 (2), page 154-171, 2013" << std::endl << std::endl <<
"Usage:" << std::endl <<
"./selectivesearchsegmentation_demo input_image (single|fast|quality)" << std::endl <<
"Use a to display less rects, d to display more rects, q to quit" << std::endl;
}
int main(int argc, char** argv) {
if (argc < 3) {
help();
return -1;
}
setUseOptimized(true);
setNumThreads(8);
std::srand((int)std::time(0));
Mat img = imread(argv[1]);
Ptr<SelectiveSearchSegmentation> gs = createSelectiveSearchSegmentation();
gs->setBaseImage(img);
if (argv[2][0] == 's') {
gs->switchToSingleStrategy();
} else if (argv[2][0] == 'f') {
gs->switchToSelectiveSearchFast();
} else if (argv[2][0] == 'q') {
gs->switchToSelectiveSearchQuality();
} else {
help();
return -2;
}
std::vector<Rect> rects;
gs->process(rects);
int nb_rects = 10;
char c = (char)waitKey();
while(c != 'q') {
Mat wimg = img.clone();
int i = 0;
for(std::vector<Rect>::iterator it = rects.begin(); it != rects.end(); ++it) {
if (i++ < nb_rects) {
rectangle(wimg, *it, Scalar(0, 0, 255));
}
}
imshow("Output", wimg);
c = (char)waitKey();
if (c == 'd') {
nb_rects += 10;
}
if (c == 'a' && nb_rects > 10) {
nb_rects -= 10;
}
}
return 0;
}
......@@ -47,6 +47,56 @@ namespace cv {
namespace ximgproc {
namespace segmentation {
// Helpers
// Represent an edge between two pixels
class Edge {
public:
int from;
int to;
float weight;
bool operator <(const Edge& e) const {
return weight < e.weight;
}
};
// A point in the sets of points
class PointSetElement {
public:
int p;
int size;
PointSetElement() { }
PointSetElement(int p_) {
p = p_;
size = 1;
}
};
// An object to manage set of points, who can be fusionned
class PointSet {
public:
PointSet(int nb_elements_);
~PointSet();
int nb_elements;
// Return the main point of the point's set
int getBasePoint(int p);
// Join two sets of points, based on their main point
void joinPoints(int p_a, int p_b);
// Return the set size of a set (based on the main point)
int size(unsigned int p) { return mapping[p].size; }
private:
PointSetElement* mapping;
};
class GraphSegmentationImpl : public GraphSegmentation {
public:
GraphSegmentationImpl() {
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment