• 哈哈11122
    了解作者
  • C/C++
    开发工具
  • 1KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 21
    下载次数
  • 2018-08-08 16:03
    上传日期
激光线提取,steger,非常稳定可靠,海森矩阵,比灰度重心法好
main.rar
  • main.cpp
    4.4KB
内容介绍
#include "opencv2/core/core.hpp" #include "opencv2/highgui/highgui.hpp" #include "opencv2/imgproc/imgproc.hpp" #include <iostream> #include <vector> #include <string> class ExtractLines{ private: cv::Mat Src, //Define Mat to hold source image Img, //Original image Dst, //Processed image Dx, //Partial derivative with respect to x Dy, //Partial derivative with respect to y Dxx, //Second derivate with respect to x Dxy, //Second partial derivative with respect to x and y, Dxy = Dyx Dyy; //Second derivative with respect to y std::vector<cv::Point> *DetectPoints; void ComputeDerivative(void); void ComputeHessian(void); public: ExtractLines(const cv::Mat& Img); void imshow(void) const; inline ~ExtractLines(){delete DetectPoints;} }; /** * @brief Compute first and second partial derivative matrixes. * Call ComputeHessian() after all the derivative matrixes * has been computed. **/ void ExtractLines::ComputeDerivative(void){ cv::Mat Mask_Dx = (cv::Mat_<float>(3, 1) << 1, 0 , -1); cv::Mat Mask_Dy = (cv::Mat_<float>(1, 3) << 1, 0 , -1); cv::Mat Mask_Dxx = (cv::Mat_<float>(3, 1) << 1, -2 , 1); cv::Mat Mask_Dyy = (cv::Mat_<float>(1, 3) << 1, -2 , 1); cv::Mat Mask_Dxy = (cv::Mat_<float>(2, 2) << 1, -1 , -1, 1); cv::filter2D(Dst, Dx, CV_32FC1, Mask_Dx); cv::filter2D(Dst, Dy, CV_32FC1, Mask_Dy); cv::filter2D(Dst, Dxx, CV_32FC1, Mask_Dxx); cv::filter2D(Dst, Dxy, CV_32FC1, Mask_Dxy); cv::filter2D(Dst, Dyy, CV_32FC1, Mask_Dyy); ComputeHessian(); } /** * @brief Compute first and second partial derivative matrixes. * Call ComputeHessian() after all the derivative matrixes * has been computed. **/ void ExtractLines::ComputeHessian(void){ for(int x = 0; x < Dst.cols; x++) { for(int y = 0; y < Dst.rows; y++) { if(Src.at<uchar>(y,x) > 10) { cv::Mat Hessian(2,2,CV_32FC1),Eigenvalue,Eigenvector; Hessian.at<float>(0, 0) = Dxx.at<float>(y, x); Hessian.at<float>(0, 1) = Dxy.at<float>(y, x); Hessian.at<float>(1, 0) = Dxy.at<float>(y, x); Hessian.at<float>(1, 1) = Dyy.at<float>(y, x); cv::eigen(Hessian, Eigenvalue, Eigenvector); double Nx, Ny; if(fabs(Eigenvalue.at<float>(0, 0)) >= fabs(Eigenvalue.at<float>(1, 0))) { Nx = Eigenvector.at<float>(0, 0); Ny = Eigenvector.at<float>(0, 1); } else { Nx = Eigenvector.at<float>(1, 0); Ny = Eigenvector.at<float>(1, 1); } double denominator = Dxx.at<float>(y,x) * Nx * Nx + 2 * Dxy.at<float>(y,x) * Nx * Ny + Dyy.at<float>(y,x) * Ny * Ny, t; if(denominator != 0.0) { t = -(Dx.at<float>(y,x) * Nx + Dy.at<float>(y,x) * Ny) / denominator; if(fabs(t * Nx) <= 0.5 && fabs(t * Ny) <= 0.5) { cv::Point_<float> res(x,y); (*DetectPoints).push_back(res); } } } } } } /** * @brief Constructor, init the image and preprocess the input image with Gaussian filter. Throw error if cannot open the image. @param img_name: the input file name. **/ ExtractLines::ExtractLines(const cv::Mat& Input_img){ Src = Input_img.clone(); Img = Input_img.clone(); cv::cvtColor(Src, Src, CV_BGR2GRAY); //Convert RGB image to gray space Dst = Src.clone(); cv::GaussianBlur(Dst, Dst, cv::Size(0, 0), 3, 3); DetectPoints = new std::vector<cv::Point>; ComputeDerivative(); } /** * @brief Draw detected salient points on original image using cv::circle and display the result. **/ void ExtractLines::imshow(void) const{ for(unsigned int i = 0; i < (*DetectPoints).size(); i++){ cv::circle(Img, (*DetectPoints)[i], 0.3, cv::Scalar(0, 0, 200)); } cv::imshow("result", Img); cv::waitKey(0); } #ifndef TEST int main() { cv::Mat Src= cv::imread("test.BMP",1); if(!Src.data){ printf("fail to open the image!\n"); return -1; } ExtractLines lines(Src); lines.imshow(); return 0; } #endif
评论
    相关推荐
    • gravity.rar
      重心法实现光斑中心定位,matlab程序
    • 41414141.rar
      介绍了空间光通信中基于CCD 的精跟踪图像处理部分的器件选择和软件算法的实 现。按照实验要求的具体参数,选择了合适的高帧频CCD 作为精跟踪的探测装置,并在PC 上 实现了相关的跟踪算法,并进行了研究。...
    • BigDog-Quadruped-Robot.rar
      Key Technology Analysis of BigDog Quadruped Robot
    • wxdb2006-4.rar
      dos前言 中国科学院西安光机所网络信息中心 2006年12月
    • 3D机房.zip
      不多说,上干货 ! 风靡的3D机房具体实现,目前主要提供有以下管理功能:设备资产管理、机房空间统计、机房功耗统计、机房载重统计、场景可视化温度云、机房高级搜索、机房设备空间搜索、机房动环监控、机房链路管理。
    • 720度万能全景开发包flash+AS3+3d+源文件+源代码.rar
      flash全景开源代码,只要换下图片就是自己的作品!! flash全景开源代码,flash3D学习案例,pv3d很好的例子
    • Gait-Tracking-With-x-IMU-master.zip
      x-IMU matlab zupt惯性室内定位算法
    • 上汽软件大赛提交作品.rar
      小车在制定道路上自动驾驶,自动识别车道线等标识。
    • 倒车入库.rar
      主要用来仿真侧方位停车过程中的运动轨迹,为自动泊车做理论基础。
    • 雨流计数法.rar
      可通过matlab 实现雨滴计数法,可直接调用