test_slic.cpp
Go to the documentation of this file.
1 /*
2  * test_slic.cpp.
3  *
4  * Written by: Pascal Mettes.
5  *
6  * This file creates an over-segmentation of a provided image based on the SLIC
7  * superpixel algorithm, as implemented in slic.h and slic.cpp.
8  */
9 
10 #include <stdio.h>
11 #include <math.h>
12 #include <vector>
13 #include <float.h>
14 using namespace std;
15 
16 #include <opencv2/opencv.hpp>
17 #include "slic.h"
18 using namespace cv;
19 
20 
21 int main(int argc, char *argv[]) {
22  /* Load the image and convert to Lab colour space. */
23  Mat image = imread("dog.png", 1);
24  Mat lab_image;
25  cvtColor(image, lab_image, COLOR_BGR2Lab);
26 
27  /* Yield the number of superpixels and weight-factors from the user. */
28  int w = image.cols, h = image.rows;
29  int nr_superpixels = 400;
30  int nc = 40;
31 
32  double step = sqrt((w * h) / (double) nr_superpixels);
33 
34  /* Perform the SLIC superpixel algorithm. */
35  Slic slic;
36  slic.generate_superpixels(lab_image, int(step), nc);
37  slic.create_connectivity(lab_image);
38  slic.display_contours(image, Vec3b(0,0,255));
39 
40  /* Display the contours and show the result. */
41  imshow("result", image);
42  waitKey(0);
43 }
void create_connectivity(const cv::Mat &image)
Definition: slic.cpp:195
CvImagePtr cvtColor(const CvImageConstPtr &source, const std::string &encoding)
double sqrt()
unsigned int step
void generate_superpixels(const cv::Mat &image, int step, int nc)
Definition: slic.cpp:123
Definition: slic.h:38
void display_contours(cv::Mat &image, cv::Vec3b colour)
Definition: slic.cpp:270
int main(int argc, char *argv[])
Definition: test_slic.cpp:21


jsk_perception
Author(s): Manabu Saito, Ryohei Ueda
autogenerated on Mon May 3 2021 03:03:27