test_slic.cpp
Go to the documentation of this file.
00001 /*
00002  * test_slic.cpp.
00003  *
00004  * Written by: Pascal Mettes.
00005  *
00006  * This file creates an over-segmentation of a provided image based on the SLIC
00007  * superpixel algorithm, as implemented in slic.h and slic.cpp.
00008  */
00009  
00010 #include <stdio.h>
00011 #include <math.h>
00012 #include <vector>
00013 #include <float.h>
00014 using namespace std;
00015 
00016 #include <opencv2/opencv.hpp>
00017 #include "slic.h"
00018 using namespace cv;
00019 
00020 
00021 int main(int argc, char *argv[]) {
00022     /* Load the image and convert to Lab colour space. */
00023     Mat image = imread("dog.png", 1);
00024     Mat lab_image;
00025     cvtColor(image, lab_image, COLOR_BGR2Lab);
00026     
00027     /* Yield the number of superpixels and weight-factors from the user. */
00028     int w = image.cols, h = image.rows;
00029     int nr_superpixels = 400;
00030     int nc = 40;
00031 
00032     double step = sqrt((w * h) / (double) nr_superpixels);
00033 
00034     /* Perform the SLIC superpixel algorithm. */
00035     Slic slic;
00036     slic.generate_superpixels(lab_image, int(step), nc);
00037     slic.create_connectivity(lab_image);
00038     slic.display_contours(image, Vec3b(0,0,255));
00039     
00040     /* Display the contours and show the result. */
00041     imshow("result", image);
00042     waitKey(0);
00043 }


jsk_perception
Author(s): Manabu Saito, Ryohei Ueda
autogenerated on Tue Jul 2 2019 19:41:07