資源簡介
python代碼,進行曲線的匹配過程,完整可編譯,有輸入的樣本可供實驗
代碼片段和文件信息
#!/usr/bin/env?python
#?-*-?coding:?utf-8?-*-
import?math
import?numpy?as?np
SAMPLE_WIDTH?=?3
#?ALFA?=?0?#?maybe??ignore
THETA?=?0??#?旋轉角
GAMA?=?1??#?縮放
M?=?10???#?描述符個數
class?SkylinePoint?(object):
????def?__init__(self?px?py):
????????self.PointX?=?px
????????self.PointY?=?py
????????self.PointN?=?[]
????#?func?:?calculate?the?polar?point?potical?means?the?potical?of?skyline.
????def?cal_polar_point(self?px?py?potical):
????????pointnx?=?px?-?potical[0]
????????pointny?=?py?-?potical[1]
????????self.PointN?=?[pointnx?pointny]
????????return?self.PointN
class?SkylineCurve(SkylinePoint):
????def?__init__(self?pointsx?pointsy):
????????super(SkylineCurve?self).__init__(0?0)
????????self.PointsX?=?pointsx
????????self.PointsY?=?pointsy
????????self.PicLen?=?len(pointsx)??#?picture?lenth
????????self.Potical?=?[]
????????self.PointsN?=?[]
????????self.fourier_des?=?[]
????????self.fourier_des_normal?=?[]
????#?func?:?Calculate?the?curve?Potical
????def?cal_potical(self):
????????line_len?=?0
????????for?i?in?range(self.PicLen?-?1):
????????????line_len?+=?math.sqrt((self.PointsX[i+1]-self.PointsX[i])**2+(self.PointsY[i+1]-self.PointsY[i])**2)
????????area_sum?=?0
????????for?i?in?range(self.PicLen):
????????????area_sum?+=?SAMPLE_WIDTH?*?self.PointsY[i]
????????poticalx?=?1.0?*?self.PicLen?/?line_len
????????poticaly?=?1.0?*?area_sum?/?line_len
????????self.Potical?=?[poticalx?poticaly]
????????return?self.Potical
????#?func?:?calculate?the?solar?points?of?the?skyline
????def?cal_polar_points(self?potical):
????????for?i?in?range(self.PicLen):
????????????pointsx?=?self.PointsX[i]
????????????pointsy?=?self.PointsY[i]
????????????#?print(pointsx)
????????????#?print(pointsy)
????????????#?print?(potical)
????????????self.PointsN.append(self.cal_polar_point(pointsx?pointsy?potical))
????????return?self.PointsN
????#?func?:?FFT?to?get??the?fourier?description?words
????def?get_fourier_des(self?pointsn):
????????pointsn_y_list?=?[]
????????for?i?in?range(self.PicLen):
????????????????pointsn_y_list.append(pointsn[i][1])
????????pointsn_y_array?=?np.array(pointsn_y_list)
????????transformed?=?np.fft.fft(pointsn_y_array)
????????fourier_des_real?=?transformed.real.tolist()
????????fourier_des_image?=?transformed.imag.tolist()
????????for?i?in?range(M):
????????????if?M?<=?self.PicLen:
????????????????#?self.fourier_des.append(math.sqrt(fourier_des_real[i]?**?2?+?fourier_des_image[i]?**?2))
????????????????self.fourier_des?=?[fourier_des_real[:M]?fourier_des_image[:M]]
????????????else:
????????????????#?print?‘M?is?out?the?max?size?of?the?Picture?!?Please?change?the?M.‘
????????????????print(‘M?is?out?the?max?size?of?the?Picture?!?Please?change?the?M.‘)
????????return?self.fourier_des
????#?func?:?normal?the?y?of?points
????#????????????y?-?min
????#???????????----------
????#????????????max?-?min
????def?normal_polar_pointsy(self?pointsy)
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????466??2018-04-11?00:16??curvematching\.idea\CurveMatching.iml
?????文件????????352??2018-04-11?01:15??curvematching\.idea\dictionaries\Administrator.xm
?????文件????????201??2018-04-11?00:16??curvematching\.idea\misc.xm
?????文件????????278??2018-04-11?00:16??curvematching\.idea\modules.xm
?????文件??????18915??2018-04-14?00:24??curvematching\.idea\workspace.xm
?????文件???????3908??2018-04-13?19:33??curvematching\datastruct.py
?????文件???????3942??2018-04-13?19:33??curvematching\datastruct.pyc
?????文件????????229??2018-04-11?00:36??curvematching\distance.py
?????文件????????462??2018-04-11?16:51??curvematching\distance.pyc
?????文件???????2349??2018-04-13?23:02??curvematching\main.py
?????文件???????1070??2018-04-13?19:37??curvematching\readdata.py
?????文件???????1669??2018-04-13?19:37??curvematching\readdata.pyc
?????文件?????824608??2018-04-12?22:06??curvematching\skylinePoints.txt
?????文件??????46621??2017-02-13?22:37??curvematching\venv\Include\abstract.h
?????文件???????1144??2017-02-13?22:37??curvematching\venv\Include\asdl.h
?????文件????????243??2017-02-13?22:37??curvematching\venv\Include\ast.h
?????文件????????824??2017-02-13?22:37??curvematching\venv\Include\bitset.h
?????文件????????948??2017-02-13?22:37??curvematching\venv\Include\boolob
?????文件????????955??2017-02-13?22:37??curvematching\venv\Include\bufferob
?????文件???????1998??2017-02-13?22:37??curvematching\venv\Include\bytearrayob
?????文件???????1179??2017-02-13?22:37??curvematching\venv\Include\bytesob
?????文件???????2879??2017-02-13?22:37??curvematching\venv\Include\bytes_methods.h
?????文件????????679??2017-02-13?22:37??curvematching\venv\Include\cellob
?????文件???????5215??2017-08-26?23:47??curvematching\venv\Include\ceval.h
?????文件???????3085??2017-02-13?22:37??curvematching\venv\Include\classob
?????文件???????3019??2017-02-13?22:37??curvematching\venv\Include\cob
?????文件???????4519??2017-02-13?22:37??curvematching\venv\Include\code.h
?????文件???????6383??2017-02-13?22:37??curvematching\venv\Include\codecs.h
?????文件???????1105??2017-02-13?22:37??curvematching\venv\Include\compile.h
?????文件???????1919??2017-02-13?22:37??curvematching\venv\Include\complexob
............此處省略2859個文件信息
- 上一篇:python和Arcpy文檔
- 下一篇:Python機器學習及實踐高清
評論
共有 條評論