#include "histo.h" #include "opencv2/imgcodecs.hpp" #include #include #include #include using namespace cv; void Roberts(const Mat& img){ Mat g, gx, gy, g2, edge, edge2; gx = Mat::zeros(img.size(), CV_16S); gy = Mat::zeros(img.size(), CV_16S); for (int i = 0; i < img.rows -1; i++) { for (int j = 0; j < img.cols -1; j++) { gx.at(i,j) = img.at(i,j) - img.at(i+1, j+1); gy.at(i,j) = img.at(i,j+1) - img.at(i+1, j); } } g = cv::abs(gx) + cv::abs(gy); convertScaleAbs(g, g2); threshold(g2, edge, 0, 255, THRESH_OTSU); threshold(g2, edge2, 0, 255, THRESH_TRIANGLE); imshow("edge", edge); imshow("edg2", edge2); //imshow("g", g * 255); //imshow("gx", gx * 255); //imshow("gy", gy * 255); } void sobel(const Mat img){ Mat g, g2, gx, gy; Sobel(img, gx, CV_32F, 1,0); Sobel(img, gy, CV_32F, 0,1); //g = cv::abs(gx) + cv::abs(gy); //cv::sqrt(gx.mul(gx) + gy.mul(gy)); convertScaleAbs(g, g2); //imshow("gx", gx / 255); //imshow("gx", gy / 255); //imshow("g2", g2); Mat dest; Laplacian(img, dest, CV_16S, 3); convertScaleAbs(dest, dest); imshow("dest", dest); waitKey(0); } int main(){ Mat img = imread("../go2.png", IMREAD_GRAYSCALE); imshow("ered", img); //Roberts(img); sobel(img); while(waitKey(3) != 'q'); return 0; }