-
-
Save Euler29/a7b4f385da1fbf64cc9b1a106281231b to your computer and use it in GitHub Desktop.
otonom_araba_kod_4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def egim_bul(lines,witdh): | |
lines=lines | |
witdh=witdh | |
a=0 | |
le=[] | |
re=[] | |
try: | |
for line in lines: | |
coords=line[0] | |
#ilk iki deger ustteki nokta,son iki alttaki nokta. | |
print('x1',coords[0],'y1',coords[1],'x2',coords[2],'y2',coords[3]) | |
#dogrunun alt noktasının x değerine bakarak sagda ya da solda olduguna bakılır. | |
if coords[2]<(witdh/2): | |
#solda oldugu icin dogru egimi le dizisine eklenir. | |
m=(-((coords[3]-coords[1])/(coords[2]-coords[0]))) | |
le.append(m) | |
if coords[2]>(witdh/2): | |
#ilk if blogunun tersi | |
m=(-((coords[3]-coords[1])/(coords[2]-coords[0]))) | |
re.append(m) | |
cv2.line(img,(coords[0],coords[1]),(coords[2],coords[3]),[0,255,0],3) | |
a=a+1 | |
print(a) | |
l_ort=sum(le)/len(le) | |
r_ort=sum(re)/len(re) | |
#sağ ve soldaki çizgilerin eğim ortalaması alındı.Buna bakarak yön belirle. | |
if l_ort<0 and r_ort<0: | |
print('sol_ort:',l_ort,'sag_ort:',r_ort) | |
return 'sola' | |
if l_ort>0 and r_ort>0: | |
print('sol_ort:',l_ort,'sag_ort:',r_ort) | |
return 'saga' | |
if l_ort<0 and r_ort>0: | |
print('sol_ort:',l_ort,'sag_ort:',r_ort) | |
return 'ileri' | |
if l_ort>0 and r_ort<0: | |
print('sol_ort:',l_ort,'sag_ort:',r_ort) | |
return 'ileri' | |
except: | |
print('Hata var') | |
pass | |
#eger buldugunuz cizgiler azsa bu şekilde eğimlerin ortalamasını almaktansa sadece sag ve soldaki herhangi bir çizginin egiminede bakabilirsiniz. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment