35 #include <opencv2/opencv.hpp> 38 #include "segment-image-labels.h" 53 float threshold,
int minimum_size, cv::Mat &labels) {
55 image<rgb>* rgbImage =
new image<rgb>(mat.cols, mat.rows);
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];
66 image<int> *segmentation = segment_image_labels(rgbImage, sigma, threshold, minimum_size, &superpixels);
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);
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