0
我有matlab代码来获取Hough变换矩阵,theta和rho值。如何获取Hough变换矩阵,hough变换的theta和rho值在opencv中cpp
[H,T,R] = hough(EdgeImage);
如何获得OpenCV中H
,T
,R
值?
我有matlab代码来获取Hough变换矩阵,theta和rho值。如何获取Hough变换矩阵,hough变换的theta和rho值在opencv中cpp
[H,T,R] = hough(EdgeImage);
如何获得OpenCV中H
,T
,R
值?
在OpenCV中,调用HT为:
vector<Vec2f> lines;
HoughLines(edges, lines, 1, CV_PI/180.0, 100);
其中edge
是您的二进制输入图像,并且lines
是Vec2f
一个std::vector
,即2个浮子的值的矢量:第一值是rho
,第二个是theta
。
OpenCV不会输出H
参数空间,如果您还需要自己编写一些代码并使HoughLines
也输出H
值。但是,这在实践中很少需要。
这是一个关于如何使用标准Hough变换,改编自OpenCV tutorials一个简单的例子:
#include <opencv2\opencv.hpp>
#include <vector>
using namespace std;
using namespace cv;
int main()
{
// Load image
Mat3b img = imread("path_to_image");
Mat3b res = img.clone();
// Convert to grayscale
Mat1b gray;
cvtColor(img, gray, COLOR_BGR2GRAY);
// Compute edges
Mat1b edges;
Canny(gray, edges, 100, 400);
vector<Vec2f> lines;
HoughLines(edges, lines, 1, CV_PI/180.0, 100);
for (size_t i = 0; i < lines.size(); i++)
{
// rho and theta values
float rho = lines[i][0];
float theta = lines[i][1];
// Draw the line
Point pt1, pt2;
double a = cos(theta), b = sin(theta);
double x0 = a*rho, y0 = b*rho;
pt1.x = cvRound(x0 + 1000 * (-b));
pt1.y = cvRound(y0 + 1000 * (a));
pt2.x = cvRound(x0 - 1000 * (-b));
pt2.y = cvRound(y0 - 1000 * (a));
line(res, pt1, pt2, Scalar(0, 0, 255), 2);
}
imshow("Input", img);
imshow("Output", res);
waitKey();
return 0;
}
输入:
输出:
请分享你迄今在opencv中尝试过的东西。它似乎支持Hough,那么你的具体问题是什么? –
我找到了sobel边缘图像,现在我想对sobel边缘图像应用hough变换来获得Hough变换矩阵,theta和rho值。 –
如果你分享你的工作,有人(而不是我)可能会帮助你。请参阅http://stackoverflow.com/questions/15279892/to-find-minute-circles-using-hough-circle-function-in-opencv-for-iris作为您的区域中一个好问题的样子的例子。 –