我试图在图像中找到文本的边界框,目前正在使用这种方法:
// calculate the local variances of the grayscale image
Mat t_mean, t_mean_2;
Mat grayF;
outImg_gray.convertTo(grayF, CV_32F);
int winSize = 35;
blur(grayF, t_mean, cv::Size(winSize,winSize));
blur(grayF.mul(grayF), t_mean_2, cv::Size(winSize,winSize));
Mat varMat = t_mean_2 - t_mean.mul(t_mean);
varMat.convertTo(varMat, CV_8U);
// threshold the high variance regions
Mat varMatRegions = varMat > 100;
Run Code Online (Sandbox Code Playgroud)
给出这样的图像时:
然后,当我显示varMatRegions
我得到这个图像:
正如你所看到的那样,它将左侧的文本块与卡片的标题结合起来,对于大多数卡片而言,这种方法效果很好,但在较繁忙的卡片上它可能会导致问题.
这些轮廓连接不好的原因是它使得轮廓的边界框几乎占据了整个卡片.
任何人都可以建议一种不同的方式来查找文本以确保正确检测文本吗?
200分,谁能在这两张卡上方找到文字.
我有一个矩形左上角的坐标,以及从0到180和-0到-180的宽度,高度和旋转.
我试图获取矩形周围的实际框的边界坐标.
什么是计算边界框坐标的简单方法
A点并不总是在最小值上,它可以在任何地方.
如果需要,我可以在as3中使用矩阵变换工具包.
现在,NSAttributedString在iOS 6中可用.出于布局目的,我想知道如何在固定宽度下计算NSAttributedString所需的高度.我正在寻找与NSString相当的东西,- (CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size
但是对于NSAttributedString.
要计算NSAttributedStrings的绘图大小,有两种方法可用:
- (CGSize)size
不能使用,因为它没有考虑任何宽度.- (CGRect)boundingRectWithSize:(CGSize)size options:(NSStringDrawingOptions)options context:(NSStringDrawingContext *)context
,但不知怎的,它没有给我正确的高度.我觉得这个方法很麻烦.如果我运行以下代码,它bounding size: 572.324951, 19.000000
会让我忽略200的给定宽度.它应该给我一些像100的高度.NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] init]; NSDictionary *attributes = @{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue" size:15], NSForegroundColorAttributeName : [UIColor blueColor]}; [attributedString appendAttributedString:[[NSAttributedString alloc] initWithString:@"Attributed String\n" attributes:attributes]]; [attributedString appendAttributedString:[[NSAttributedString alloc] initWithString:@"Attributed String\n" attributes:attributes]]; [attributedString appendAttributedString:[[NSAttributedString alloc] initWithString:@"Attributed String\n" attributes:attributes]]; [attributedString appendAttributedString:[[NSAttributedString alloc] initWithString:@"Attributed String\n" attributes:attributes]]; [attributedString appendAttributedString:[[NSAttributedString alloc] initWithString:@"Attributed String\n" attributes:attributes]]; CGRect frame = [attributedString boundingRectWithSize:CGSizeMake(200, 1000) options:0 …
我有两个矩形a和b,它们的边平行于坐标系的轴.我的坐标为x1,y1,x2,y2.
我试图确定,它们不仅重叠,而且它们有多重叠?我试图弄清楚他们是否真的是同一个矩形给予或采取一些摆动的空间.那么他们的面积95%是一样的吗?
有没有帮助计算重叠百分比?
给定一个坐标(lat,long),我试图计算一个与坐标相距给定距离(例如50km)的方形边界框.所以作为输入我有lat,long和distance,作为输出,我想要两个坐标; 一个是西南(左下角),另一个是东北(右上角).我在这里看到了几个试图用Python解决这个问题的答案,但我特别想找一个Java实现.
为了清楚起见,我打算仅在地球上使用该算法,因此我不需要容纳可变半径.
它不一定非常准确(+/- 20%很好),它只能用于计算小距离(不超过150公里)的边界框.所以我很高兴为一个有效的算法牺牲一些准确性.任何帮助深表感谢.
编辑:我应该更清楚,我真的是在一个正方形,而不是一个圆圈.我知道正方形的中心和沿着正方形周长的各个点之间的距离不是像圆圈一样的恒定值.我猜我的意思是一个正方形,如果你从中心画一条直线到周长上的四个点中的任何一个点,导致一条线垂直于周边的边,那么这4条线的长度相同.
math trigonometry geospatial bounding-box latitude-longitude
基本上我是在问JavaScript这个问题:从旋转的矩形计算边界框坐标
在这种情况下:
如何通过JavaScript计算旋转的HTML元素(给定其宽度,高度和旋转角度)周围的边界框(所有红色数字)的X,Y,高度和宽度?一个棘手的问题是将旋转的HTML元素(蓝色框)的原始X/Y坐标用作某种方式的偏移(这在下面的代码中没有表示).这可能需要查看CSS3的变换原点来确定中心点.
我有一个部分解决方案,但X/Y坐标的计算不正常...
var boundingBox = function (iX, iY, iAngle) {
var x, y, bx, by, t;
//# Allow for negetive iAngle's that rotate counter clockwise while always ensuring iAngle's < 360
t = ((iAngle < 0 ? 360 - iAngle : iAngle) % 360);
//# Calculate the width (bx) and height (by) of the .boundingBox
//# NOTE: See https://stackoverflow.com/questions/3231176/how-to-get-size-of-a-rotated-rectangle
bx …
Run Code Online (Sandbox Code Playgroud) 我需要从JavaScript中获取SVG中<path>屏幕上的维度.
我的SVG上没有任何"转换"或"缩放"(转换,缩放).唯一改变的是viewBox,它将改变SVG中所有元素的大小.
我一直在使用myPath.getBBox(),即使我更改了我的viewBox,返回的宽度保持不变.
所以我想知道这个viewBox与路径大小的关系是什么.也许有一个计算宽度的函数?
假设您有以下图像:
现在我想要提取每个独立字母的单个图像,为此任务我已经恢复了轮廓,然后绘制了一个边界框,在这种情况下为角色'a':
在此之后,我想提取每个框(在这种情况下为字母'a')并将其保存到图像文件中.
预期结果:
到目前为止,这是我的代码:
import numpy as np
import cv2
im = cv2.imread('abcd.png')
im[im == 255] = 1
im[im == 0] = 255
im[im == 1] = 0
im2 = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
ret,thresh = cv2.threshold(im2,127,255,0)
contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
for i in range(0, len(contours)):
if (i % 2 == 0):
cnt = contours[i]
#mask = np.zeros(im2.shape,np.uint8)
#cv2.drawContours(mask,[cnt],0,255,-1)
x,y,w,h = cv2.boundingRect(cnt)
cv2.rectangle(im,(x,y),(x+w,y+h),(0,255,0),2)
cv2.imshow('Features', im)
cv2.imwrite(str(i)+'.png', im)
cv2.destroyAllWindows()
Run Code Online (Sandbox Code Playgroud)
提前致谢.
我正在尝试使用OpenCV简化以下图像:
我们这里有很多红色的形状.其中一些完全包含其他人.他们中的一些人与邻居相交.我的目标是通过用联合多边形的边界框替换任何两个相交的形状来统一所有相交的形状.(重复直到没有更多相交的形状).
通过交叉我的意思是触摸.希望这使它100%清晰:
我正在努力使用标准的形态学操作来有效地做到这一点; 显然它可以在O(N ^ 2)中天真地完成,但那太慢了.扩张没有帮助,因为一些形状只相差1px,如果它们没有相交,我不希望它们合并.
bounding-box ×10
geometry ×3
math ×3
opencv ×3
image ×2
javascript ×2
rotation ×2
algorithm ×1
android ×1
c++ ×1
css ×1
geospatial ×1
ios ×1
python ×1
string ×1
svg ×1
text ×1
trigonometry ×1