如何在python中计算用于确定图形是否为十字和“a”的对齐度;中格“;给出一个可能性?
我有这样的图像,三叉戟: 和十字架: 我实现这个代码来确定十字架和三叉戟之间的区别。 我计算了极端点的位置和图形的连接点。 然后,我计算相对的端点是否与连接点在同一条线上。如果是,我有一个十字架如果不是,它是三叉戟。 我使用近似标志来确定tha对齐 我用很多图片测试了代码,但我对结果不满意 下面我写下了三叉戟的坐标,这些坐标与三叉戟不同: 第一三叉戟:如何在python中计算用于确定图形是否为十字和“a”的对齐度;中格“;给出一个可能性?,python,image-processing,Python,Image Processing,我有这样的图像,三叉戟: 和十字架: 我实现这个代码来确定十字架和三叉戟之间的区别。 我计算了极端点的位置和图形的连接点。 然后,我计算相对的端点是否与连接点在同一条线上。如果是,我有一个十字架如果不是,它是三叉戟。 我使用近似标志来确定tha对齐 我用很多图片测试了代码,但我对结果不满意 下面我写下了三叉戟的坐标,这些坐标与三叉戟不同: 第一三叉戟: #junction point [(86, 112)] #extreme points [(39, 125), (48, 159), (49
#junction point
[(86, 112)]
#extreme points
[(39, 125), (48, 159), (49, 159), (133, 118)]
第二个三叉戟:
#junction point
[(74, 58)]
#extreme points
[(67, 61), (75, 51), (81, 56), (81, 63)]
#junction point
[(128, 448)]
#extreme points
[(93, 538), (115, 358), (217, 358), (218, 494)]
第三叉戟:
#junction point
[(74, 58)]
#extreme points
[(67, 61), (75, 51), (81, 56), (81, 63)]
#junction point
[(128, 448)]
#extreme points
[(93, 538), (115, 358), (217, 358), (218, 494)]
第四三叉戟:
#junction point
[(62, 100)]
#extreme points
[(59, 97), (59, 98), (62, 103), (65, 98)]
第四个三叉戟的图像:
显然是一个三叉戟,但对于我的代码:是一个“怀疑”的情况。
如何改进代码?
我不认为这是改变“怀疑范围”的问题
当app=1.0和appmax=1.2时,我得到了类似的结果
我的代码:
#app is the mininum approximation flag. < 2 is a aligned
app =2
def is_aligned (p1,p2,p3, approx = app):
appmax = 3 #appmax is the maximum approximation flag. >3 is not aligned
x1, y1 = p1
x2, y2 = p2
x3, y3 = p3
#print("abs dist")
#print(abs(((y3-y1) / (y2-y1)) - ((x3-x1) / (x2-x1))))
dist = abs(((y3-y1) / (y2-y1)) - ((x3-x1) / (x2-x1)))
if dist <= approx:
percentdist = 100
return dist <= approx, percentdist
else:
propor1 = appmax-approx #proxMax-proxMin
propor2 = dist - approx #approxmin
percentdist = 100*propor2/propor1
return dist<=appmax, percentdist
listalign = list()
listalign2= list()
def is_crux(v1, v2, v3, v4, o, approx=app):
others = [v2, v3, v4]
percentage = 200
for v in others:
print("iscrux1")
align, percentage = is_aligned(v1, v, o, approx)
if align:
listalign.append(percentage)
#print("percentage")
#print(percentage)
others.remove(v)
align2, percentage2 = is_aligned(others[0], others[1], o, approx)
if align2:
percentage = percentage + percentage2
listalign2.append(percentage2)
return True, percentage
break
return False, percentage
listapercent = list()
def angles(bpoints, epoints):
bcoord = bpoints
ecoord = epoints
angvero = 2
if (len(bpoints) == 1 and len(epoints) == 4):
angvero, percentage = is_crux(ecoord[0], ecoord[1], ecoord[2], ecoord[3], bcoord[0])
#print("percentage")
#print(percentage)
listapercent.append(percentage)
# 3 cases: 1 if true (100-100) 1 if false (100-100 preso da is crux) and 1 if doubt (100 e 40 o 30 e 70)
if(angvero == True and percentage == 200):
angvero = 1
return angvero
elif(angvero == False and percentage == 200):
angvero = 0
return angvero
else:
#calculating second %%%
somma = percentage
prob1 = 100 * 100 / somma
#print("prob1")
#print(prob1)
# obtaining percentage
prob2 = 100 * (percentage/2) / somma
#print("prob2")
#print(prob2)
angvero = "doubt"
#print(angvero)
#angvero = angles(erows,ecols, brows, bcols)
elif(len(bpoints) == 1 and len(epoints) == 3):
angvero = 0
return angvero
elif(len(bpoints) == 0 and len(epoints) == 3):
angvero = 0
return angvero
#print(angvero)
return angvero
#app是最小近似值标志2是对齐的
app=2
def对齐(p1、p2、p3,近似值=app):
appmax=3#appmax是最大近似标志。>3没有对齐
x1,y1=p1
x2,y2=p2
x3,y3=p3
#打印(“abs区”)
#打印(abs((y3-y1)/(y2-y1))-((x3-x1)/(x2-x1)))
dist=abs((y3-y1)/(y2-y1))-((x3-x1)/(x2-x1)))
如果区