Skip to content

include/cvw/algorithms/edge.hpp

Edge detection algorithms. More...

Namespaces

Name
cvw

Detailed Description

Edge detection algorithms.

Author: Charliechen114514

Version: 1.0.0

Since: 1.0.0

Date: 2026-05-15

Provides Canny edge detection and Sobel derivative operators with expected-based error handling.

Source code

cpp

#pragma once
#include "detail.hpp"
#include <opencv2/imgproc.hpp>

namespace cvw {

[[nodiscard]] inline expected<Image<Gray>, AlgorithmError>
canny(Image<Gray> img, double threshold_lo, double threshold_hi,
      int aperture_size = 3) {
    auto ec = detail::check_non_empty(img);
    if (!ec) {
        return unexpected(ec.error());
    }

    cv::Mat dst;
    cv::Canny(img.mat(), dst, threshold_lo, threshold_hi, aperture_size);
    return Image<Gray>(std::move(dst));
}

[[nodiscard]] inline expected<Image<Float1>, AlgorithmError>
sobel(Image<Gray> img, int dx, int dy, int kernel_size = 3) {
    auto ec = detail::check_non_empty(img);
    if (!ec) {
        return unexpected(ec.error());
    }

    cv::Mat dst;
    cv::Sobel(img.mat(), dst, CV_32FC1, dx, dy, kernel_size);
    return Image<Float1>(std::move(dst));
}

} // namespace cvw

Updated on 2026-05-17 at 13:22:38 +0000

Built with VitePress