用houghLines估计偏斜水平 [英] estimate the skew level with houghLines
问题描述
我想从图像中检测偏斜水平。我有以下代码:
public void analyze(CvMat img){
rows = img .rows();
cols = img.cols();
//从rois创建边缘图
CvMat edgeMap = cvCreateMat(rows,cols,CV_8UC1);
cvCanny(img,edgeMap,100,400,3);
//转换为hough
CvMemStorage storage = cvCreateMemStorage(0);
lines = cvHoughLines2(edgeMap,storage,CV_HOUGH_PROBABILISTIC,1,
EuclideanDistance euclideanDistance = new EuclideanDistance();
double maxDistance = Double.MIN_VALUE;
for(int i = 0; i< lines.total(); ++ i){
Pointer line = cvGetSeqElem(lines,i);
CvPoint pt1 = new CvPoint(line).position (0);
CvPoint pt2 = new CvPoint(line).position(1);
double distance = euclideanDistance.getDistance(pt1,pt2);
double currentAngle = Math.atan2(pt2 .y() - pt1.y(),
pt2.x() - pt1.x())
* 180 / Math.PI;
System.out.println(currentAngle) ;
if(距离> maxDistance){
skewAngle = currentAngle;
}
}
我的测试图片是
我认为偏斜水平是-16度但我的c ode说,那是25 ...
for也打出平均角度25。这个我的hough参数错了吗?
//这里的编辑是来自houghLines的图纸
问候语
首先,由于你有一个相当清晰的文字,我建议你在Canny和Hough之前使用扩张/侵蚀。你会在字母里面获得更多的积分,霍夫肯定会从中受益。
其次,你选择最佳角度作为两点之间的最大距离。一行。
double distance = euclideanDistance.getDistance(pt1,pt2);
...
if(distance> maxDistance){
skewAngle = currentAngle;
}
这不起作用,因为实际上Hough可能检测到不相关的线,比任何文本行都长:
如果你向自己显示每一步所做的事情你会得到一个更好的算法 - 你在Canny之后得到的,Hough变换产生了什么线等等。 / p>
i want to detect the skew level from an image. I've the following code:
public void analyse(CvMat img) {
rows = img.rows();
cols = img.cols();
// create edge-map from rois
CvMat edgeMap = cvCreateMat(rows, cols, CV_8UC1);
cvCanny(img, edgeMap, 100, 400, 3);
// transform to hough
CvMemStorage storage = cvCreateMemStorage(0);
lines = cvHoughLines2(edgeMap, storage, CV_HOUGH_PROBABILISTIC, 1,
EuclideanDistance euclideanDistance = new EuclideanDistance();
double maxDistance = Double.MIN_VALUE;
for (int i = 0; i < lines.total(); ++i) {
Pointer line = cvGetSeqElem(lines, i);
CvPoint pt1 = new CvPoint(line).position(0);
CvPoint pt2 = new CvPoint(line).position(1);
double distance = euclideanDistance.getDistance(pt1, pt2);
double currentAngle = Math.atan2(pt2.y() - pt1.y(),
pt2.x() - pt1.x())
* 180 / Math.PI;
System.out.println(currentAngle);
if (distance > maxDistance) {
skewAngle = currentAngle;
}
}
My test image is
I think the skew level is by -16 degree but my code says, that is by 25...
The for prints out a avg angle by 25,too. Thats wrong with my hough parameters?
//EDIT here is a drawing from the houghLines
greetings
Firstly, since you've got a rather clear text, I suggest you used dilate/erode prior to Canny and Hough. You'll get much more points inside the letters, from which Hough will definitely benefit.
Secondly, you choose you "best angle" as a maximum distance between two points of a line.
double distance = euclideanDistance.getDistance(pt1, pt2);
...
if (distance > maxDistance) {
skewAngle = currentAngle;
}
This will NOT work, because in fact Hough may detect an uncorrelated line, which is longer than any line of text:
You may come out with a better algorithm if you display to yourself every step that is made - what you get after Canny, what lines did Hough transform produce etc.
这篇关于用houghLines估计偏斜水平的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!