def adjustPoints(points, leftSidePoint, rightSidePoint): # Function to adjust landmarks points of the forehead & fix corruptions of improvement # Use shape_predictor_81 as a reference for points indexes: # points = [69,70,71,73,80] # LeftSidePoint = 76 | rightSidePoint = 79 slopes = [] slopeThreshold = 0.4 # slope > 0.4 = corruption -> fix totalSlopeThreshold = 1 # sum of slopes > 1 = corruption -> fix leftPoint = points[0] rightPoint = points[3] criticalLeftPoint = points[1] criticalRightPoint = points[4] # if any point is higher than a (accurate located point) -> fix if leftPoint[1] < criticalLeftPoint[1]: points[0, 1] = np.average([criticalLeftPoint[1], leftSidePoint[1]]) if rightPoint[1] < criticalRightPoint[1]: points[3, 1] = np.average([criticalRightPoint[1], rightSidePoint[1]]) # Collect some slopes of the usually corrupted points slopes.append(slope(points[1], points[2], True)) slopes.append(slope(points[2], points[4], True)) # Calculate slope differences & sum difference = abs(np.diff(slopes)) _sum = np.sum(slopes) # If calculation results (either) too high = corruption -> fix if difference > slopeThreshold: issueIndex = np.argmax(slopes) if issueIndex == 0: points[1, 1] = max(points[4, 1], points[2, 1]) else: points[4, 1] = max(points[1, 1], points[2, 1]) if _sum > totalSlopeThreshold: points[1, 1] = np.average(points[[4, 2], 1]) points[4, 1] = np.average(points[[1, 2], 1]) points[2, 1] = np.average(points[[4, 1], 1]) return points
def do_intercept(x1, y1, x2, y2): if slope(x1, y1, x2, y2) == inf: print(end="The x-") else: print(end="The y-") print(end="intercept of the line between ") print_point(x1, y1) print(end=" and ") print_point(x2, y2) print(" is", intercept(x1, y1, x2, y2))
def do_slope(x1, y1, x2, y2): print(end="The slope of the line between ") print_point(x1, y1) print(end=" and ") print_point(x2, y2) print(end=" is ") m = slope(x1, y1, x2, y2) if m == inf: print("undefined") else: print(m)
import sys print(sys.platform) print(sys.maxsize) print(sys.path) sys.path.append("modules") print(sys.path) import geometry result = geometry.distance(1, 1, 5, 5) print(result) result = geometry.slope(1, 2, 5, 6) print(result)
# 載入內建的 sys 模組並取得資訊 import sys print(sys.platform) print(sys.maxsize) print(sys.path) print("--------------") # 自己建立 10_geometry 模組,載入使用 # import geometry as geo # geo為模組的別名 # res = geo.distance(1,1,5,5) # print(res) # res = geo.slope(1,2,5,6) # print(res) # 調整搜尋模組的路徑 sys.path.append("modules") # 新增模組路徑 print(sys.path) # 印出模組的搜尋路徑 print("--------------") import geometry as geo # geo為模組的別名 res = geo.distance(1, 1, 5, 5) print(res) res = geo.slope(1, 2, 5, 6) print(res)
# import built-in module sys import sys as system print(system.platform) print("------------------------") print(system.maxsize) print("------------------------") print(system.path) print("------------------------") # added path of self-created module to python system.path.append("../modules") # import self-created geometry module import geometry print(geometry.distance(1, 1, 5, 5)) print(geometry.slope(1, 1, 5, 5)) # import self-created circle module import circle print(circle.cal_area(3)) print(circle.cal_perimeter(3))
#載入內建的sys模組並取得資訊 #import sys #print(sys.platform) #print(sys.maxsize) #import sys as s #print(s.platform) #print(s.maxsize) #建立geometry模組,載入使用 #import geometry as G #x = G.dis(1,2,7,10) #print(x) # #y = G.slope(5,9,15,29) #print(y) #建立一個模組專用的資料夾modules並將geometry置入 #因為模組路徑改變,載入失敗 #調整搜尋模組的路徑 import sys sys.path.append("modules") #新增的資料夾 >> 新增路徑 print(sys.path) #印出模組的搜尋路徑的列表 #再次嘗試載入模組並使用 import geometry as G x = G.dis(1, 2, 7, 10) print(x) y = G.slope(5, 9, 15, 29) print(y)
Created on Tue Feb 9 09:25:01 2021 @author: Jeff """ # 11 Python Module 模組的載入與使用 #%% sys模組 # 取得系統相關資訊 import sys print(sys.platform) #印出作業系統 print(sys.maxsize) #印出整數型態的最大值 # 調整搜尋模組的路徑 print(sys.path) #印出搜尋模組的路徑 sys.path.append("Modules") #在模組的搜尋路經中,加入新的路徑 #%% 自訂模組 ''' 建立幾何運算模組 建立檔案geometry.py 定義平面幾何運算的函式 ''' import geometry dis = geometry.distance(1, 1, 5, 5) print(dis) slope = geometry.slope(2, 2, 4, 4) print(slope)
import sys as system system.path.append("modules") import geometry # 计算两点距离 result = geometry.distance(1, 1, 5, 5) print("两点距离:", result) # 计算斜率 result = geometry.slope(1, 2, 4, 5) print("斜率:", result)
# Module 模組的載入與使用 # import sys # print(sys.path) # print(sys.platform) # from PengPeng_Python_Learn.Modules import geometry #这也是一种加载路径的方法 # import geometry # result= geometry.distance(1, 1, 3, 4) # print(result) # result= geometry.slope(2, 3, 4, 6) # print(result) # 调整搜寻模组的路径 import sys print(sys.path) # 印出模组的搜寻路径 sys.path.append("Modules") # 添加python当前路径下的Modules路径 print(sys.path) # 印出模组的搜寻路径列表 import geometry result = geometry.distance(1, 1, 3, 4) print(result) result = geometry.slope(2, 3, 4, 6) print(result)
# 載入內建的sys模組並取得資訊 # 建立geometry模組,並載入使用 import sys sys.path.append("modules") #在模組的搜尋路徑列表中[新增路徑] import geometry result = geometry.distance(1, 1, 5, 5) print(result) result = geometry.slope(1, 2, 3, 4) print(result) # 調整搜尋模組的路徑 # import sys # print(sys.path) #印出模組的搜尋路徑列表
# -*- coding: utf-8 -*- """ Created on Fri Dec 7 22:55:39 2018 @author: Home love 模組的使用 """ import sys sys.path.append("python") #再模組的搜尋路徑列表中「新增路徑」 print(sys.platform) print(sys.maxsize) print(sys.path) import geometry as gt rs = gt.distance(1, 1, 5, 5) print(rs) rs = gt.slope(1, 2, 5, 6) print(rs)
#載入內建sys模組並取得資訊 # import sys as system # 模組 as 別名(代號) # print(system.platform) # print(system.maxsize) #調整模組搜尋路徑 import sys #print(sys.path) # 印出模組的搜尋路徑 sys.path.append("modules") #當前路徑(相對路徑)下的搜尋路徑 #建立 geometry.py,載入使用 import geometry result = geometry.distance(1, 1, 5, 5) # geometry.distance 模組中函數名稱 print(result) result = geometry.slope(1, 2, 5, 6) #geometry.distance print(result)
# 載入內建的 sys 模組並取得資訊 # import sys as system # print(system.platform) # print(system.maxsize) # 建立geometry模組, 載入並使用 # import geometry # result=geometry.distance(1,1,5,5) # print(result) # result=geometry.slope(1,2,5,6) # print(result) # 調整搜尋模組的路徑 import sys sys.path.append("mod") #在模組的搜尋紀錄中心新增 print(sys.path) #印出模組的搜尋路徑 import geometry print(geometry.distance(3, 3, 3, 3)) print(geometry.slope(1, 2, 5, 6))
import sys print(sys.platform) import sys as system print(system.maxsize) print("======================") #建立geometry模組 載入使用 # # import geometry #這是模組跟主程式同一層 或是以下的順序收尋找的到的位置 # dis = geometry.distance(1,1,5,5) # print(dis) # slope1 = geometry.slope(1,2,5,6) # print("斜率:", slope1) #調整收尋模組的路徑 import sys print(sys.path) #印出模組的收尋路徑 #按照順序去收尋模組 #若將模組放到modules資料夾 會找不到 因為收尋路徑沒有modules資料夾 所以import指令要改 import sys sys.path.append("modules") #可以寫絕對路徑或相對路徑 #在模組的收尋路徑列表中[新增路徑] import geometry dis = geometry.distance(1, 1, 5, 5) print(dis) slope1 = geometry.slope(1, 2, 5, 6) print("斜率:", slope1) print(sys.path) #可以再路徑中找到modules 以後找模組也會找剛剛新增的資料夾