边缘检测

cmakelists.txt添加

add_executable(node3 src/node3.cpp)
target_link_libraries(node3
  ${catkin_LIBRARIES}
)

边缘检测node3.cpp

//边缘检测
#include "opencv2/opencv.hpp"

using namespace cv;

int main(void)
{
    ///Canny边缘检测
    /*Mat srcImg = imread("1.bmp", CV_LOAD_IMAGE_COLOR);
    imshow("src", srcImg);
    Mat dstImg;
    Canny(srcImg, dstImg, 30, 80);
    imshow("Canny", dstImg);
    waitKey(0);*/

    /////Sobel边缘检测
    //Mat grad_x, grad_y;
    //Mat abs_grad_x, abs_grad_y, dst;

    //Mat src = imread("2.png", CV_LOAD_IMAGE_COLOR);
    //imshow("src", src);

    //Sobel(src, grad_x, CV_16S, 1, 0, 3, 1, 1, BORDER_DEFAULT);//因为Sobel求出来的结果有正负,8位无符号表示不全,故用16位有符号表示
    //convertScaleAbs(grad_x, abs_grad_x);//将16位有符号转化为8位无符号
    //imshow("X方向", abs_grad_x);

    //Sobel(src, grad_y, CV_16S, 0, 1, 3, 1, 1, BORDER_DEFAULT);
    //convertScaleAbs(grad_y, abs_grad_y);
    //imshow("Y方向", abs_grad_y);

    //addWeighted(abs_grad_x, 0.5, abs_grad_y, 0.5, 0, dst);
    //imshow("合并效果", dst);

    //waitKey(0);
    //destroyAllWindows();

    ///Laplacian边缘检测
    Mat grad_x, grad_y;
    Mat abs_grad_x, abs_grad_y, dst;
    Mat abs_dst;

    Mat src = imread("/home/ly/1.png", CV_LOAD_IMAGE_GRAYSCALE);
    imshow("src", src);

    Laplacian(src, dst, CV_16S, 5, 1, 0, BORDER_DEFAULT);
    convertScaleAbs(dst, abs_dst);

    imshow("Laplacian", abs_dst);

    waitKey(0);
    destroyAllWindows();
}

边缘检测_第1张图片
效果
边缘检测_第2张图片

你可能感兴趣的:(object,tracking)