Superpixel Benchmark
Superpixel benchmark, tools and algorithms.
fh_opencv.h
Go to the documentation of this file.
1 
32 #ifndef FH_OPENCV_H
33 #define FH_OPENCV_H
34 
35 #include <opencv2/opencv.hpp>
36 #include "misc.h"
37 #include "image.h"
38 #include "segment-image-labels.h"
39 
43 class FH_OpenCV {
44 public:
52  static int computeSuperpixels(const cv::Mat &mat, float sigma,
53  float threshold, int minimum_size, cv::Mat &labels) {
54 
55  image<rgb>* rgbImage = new image<rgb>(mat.cols, mat.rows);
56 
57  for (int i = 0; i < mat.rows; ++i) {
58  for (int j = 0; j < mat.cols; ++j) {
59  imRef(rgbImage, j, i).r = mat.at<cv::Vec3b>(i, j)[2];
60  imRef(rgbImage, j, i).g = mat.at<cv::Vec3b>(i, j)[1];
61  imRef(rgbImage, j, i).b = mat.at<cv::Vec3b>(i, j)[0];
62  }
63  }
64 
65  int superpixels = 0;
66  image<int> *segmentation = segment_image_labels(rgbImage, sigma, threshold, minimum_size, &superpixels);
67 
68  labels.create(mat.rows, mat.cols, CV_32SC1);
69  for (int i = 0; i < mat.rows; ++i) {
70  for (int j = 0; j < mat.cols; ++j) {
71  labels.at<int>(i, j) = imRef(segmentation, j, i);
72  }
73  }
74 
75  delete rgbImage;
76  delete segmentation;
77 
78  return superpixels;
79  }
80 };
81 
82 #endif /* FH_OPENCV_H */
83 
Wrapper for running FH on OpenCV images.
Definition: fh_opencv.h:43
static int computeSuperpixels(const cv::Mat &mat, float sigma, float threshold, int minimum_size, cv::Mat &labels)
Computer superpixels using FH, see README.md for details.
Definition: fh_opencv.h:52