32 #ifndef VLSLIC_OPENCV_H 33 #define VLSLIC_OPENCV_H 35 #include <opencv2/opencv.hpp> 51 double regularization,
int min_region_size,
int iterations, cv::Mat &labels)
54 float* image =
new float[mat.rows*mat.cols*mat.channels()];
55 for (
int i = 0; i < mat.rows; ++i) {
56 for (
int j = 0; j < mat.cols; ++j) {
57 if (mat.channels() == 1) {
58 image[j + mat.cols*i] = mat.at<
unsigned char>(i, j);
60 else if (mat.channels() == 3) {
61 image[j + mat.cols*i + mat.cols*mat.rows*0] = mat.at<cv::Vec3b>(i, j)[0];
62 image[j + mat.cols*i + mat.cols*mat.rows*1] = mat.at<cv::Vec3b>(i, j)[1];
63 image[j + mat.cols*i + mat.cols*mat.rows*2] = mat.at<cv::Vec3b>(i, j)[2];
68 vl_uint32* segmentation =
new vl_uint32[mat.rows*mat.cols];
69 vl_size height = mat.rows;
70 vl_size width = mat.cols;
71 vl_size channels = mat.channels();
73 vl_slic_segment_t(segmentation, image, width, height, channels, region_size,
74 regularization, min_region_size, iterations);
77 labels.create(mat.rows, mat.cols, CV_32SC1);
78 for (
int i = 0; i < mat.rows; ++i) {
79 for (
int j = 0; j < mat.cols; ++j) {
80 labels.at<
int>(i, j) = (
int) segmentation[j + mat.cols*i];
static void computeSuperpixels(const cv::Mat &mat, int region_size, double regularization, int min_region_size, int iterations, cv::Mat &labels)
Computing superpixels using vlSLIC.
Definition: vlslic_opencv.h:50
Wrapper for running vlSLIC on OpenCV images.
Definition: vlslic_opencv.h:41