OpenCV Hough最强的路线 [英] OpenCV Hough strongest lines

查看:99
本文介绍了OpenCV Hough最强的路线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

OpenCV中的HoughLines或HoughLinesP函数是否像HoughCircles函数那样按累加器顺序返回行列表?我想知道线的顺序.获取线路的累加器值也非常方便,因此可以使用智能和自适应阈值来代替固定阈值.是否可以在不自己重写OpenCV的情况下使用订购值或累加器值?

Do the HoughLines or HoughLinesP functions in OpenCV return the list of lines in accumulator order like the HoughCircles function does? I would like to know the ordering of lines. It would also be very handy to get a the accumulator value for the lines so an intelligent and adaptive threshold could be used instead of a fixed one. Are either the ordering or the accumulator value available without rewriting OpenCV myself?

推荐答案

HoughTransform命令按票数降序排列行.您可以在此处

HoughTransform orders lines descending by number of votes. You can see the code here

但是,投票计数随着函数的返回而丢失-唯一的方法就是修改OpenCV.

However, the vote count is lost as the function returns - the only way to have it is to modify OpenCV.

好消息是,这并不是很复杂-我自己做了一次.将输出从vector< Vec2f >更改为vector< Vec3f >,并使用投票计数填充最后一个参数,需要花费几分钟的时间.

The good news is that is not very complicated - I did it myself once. It's a metter of minutes to change the output from vector< Vec2f > to vector< Vec3f > and populate the last param with vote count.

此外,您还必须修改CvLinePolar以添加第三个参数-hough在C中实现,并且在C++中有一个包装器,因此您必须同时修改实现和包装器.

Also, you have to modify CvLinePolar to add the third parameter - hough is implemented in C, and there is a wrapper over it in C++, so you have to modify both the implementation and the wrapper.

此处要修改的主要代码

 for( i = 0; i < linesMax; i++ )
 {
        CvLinePolar line;
        int idx = sort_buf[i];
        int n = cvFloor(idx*scale) - 1;
        int r = idx - (n+1)*(numrho+2) - 1;
        line.rho = (r - (numrho - 1)*0.5f) * rho;
        line.angle = n * theta;

        // add this line, and a field voteCount to CvLinePolar
        // DO NOT FORGET TO MODIFY THE C++ WRAPPER
        line.voteCount = accum[idx];          

        cvSeqPush( lines, &line );
 }

这篇关于OpenCV Hough最强的路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆