-
Notifications
You must be signed in to change notification settings - Fork 147
/
test_slic.cpp
43 lines (36 loc) · 1.19 KB
/
test_slic.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
* test_slic.cpp.
*
* Written by: Pascal Mettes.
*
* This file creates an over-segmentation of a provided image based on the SLIC
* superpixel algorithm, as implemented in slic.h and slic.cpp.
*/
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <float.h>
using namespace std;
#include "slic.h"
int main(int argc, char *argv[]) {
/* Load the image and convert to Lab colour space. */
IplImage *image = cvLoadImage(argv[1], 1);
IplImage *lab_image = cvCloneImage(image);
cvCvtColor(image, lab_image, CV_BGR2Lab);
/* Yield the number of superpixels and weight-factors from the user. */
int w = image->width, h = image->height;
int nr_superpixels = atoi(argv[2]);
int nc = atoi(argv[3]);
double step = sqrt((w * h) / (double) nr_superpixels);
/* Perform the SLIC superpixel algorithm. */
Slic slic;
slic.generate_superpixels(lab_image, step, nc);
slic.create_connectivity(lab_image);
/* Display the contours and show the result. */
slic.display_contours(image, CV_RGB(255,0,0));
cvShowImage("result", image);
cvWaitKey(0);
cvSaveImage(argv[4], image);
}