資源簡介
哈哈哈哈鏡子代碼
代碼片段和文件信息
#哈哈鏡的原理:輸入圖像f(xy)?設置圖像中心坐標Center(cx?xy)為縮放中心點。
#圖像上任意一點到中心點的相對坐標tx=?x-cxty=y-cy.哈哈鏡效果分為圖像拉伸放大和圖像縮小。
#對于圖像拉伸放大,設置圖像變換的半徑為radius哈哈鏡變換后的圖像為p(xy).
#?x?=?(tx/2)*(sqrt(tx*tx?+?ty*ty)/radius)+cx
#?y?=?(ty/2)*(sqrt(tx*tx?+?ty*ty)/radius)+cy
#對于圖像縮小,設置圖像變換的半徑為radius哈哈鏡變換后的圖像為p(xy).
#?x?=?cos(atan2(ty??tx))*?12*(sqrt(tx*tx?+?ty*ty))+cx
#?y?=?sin(atan2(ty??tx))*?12*(sqrt(tx*tx?+?ty*ty))+cy
#?-*-?coding:?UTF-8?-*-
import?cv2
import?numpy?as?np
import?math
def?Maxframe(frame):?????????????????#定義圖像拉伸放大函數
????height?width?n?=?frame.shape????#獲取輸入圖像的長寬和通道
????center_X?=?width?/?2??????????????#計算公式
????center_Y?=?height?/?2
????radius?=?400?????????????????????#這里直接定義半徑了
????newX?=?0?????????????????????????#初始變換后的坐標
????newY?=?0
????real_radius?=int(radius?/?2.0)???#計算公式
????new_data?=?frame.copy()?????????#復制一個與原圖像一樣的圖片
????for?i?in?range(width):????????????????#建立循環移動像素遍歷寬度方向的像素
????????for?j?in?range(height):???????????????#遍歷高度方向的像素
????????????tX?=?i?-?center_X??????????????????#計算公式
????????????tY?=?j?-?center_Y
????????????distance?=?tX?*?tX?+?tY?*?tY
????????????if?distance?
????????????????newX?=?int(tX/?2.0)
????????????????newY?=?int(tY/?2.0)
????????????????newX?=?int(newX?*?(math.sqrt(distance)?/?real_radius))
????????????????newX?=?int(newX?*?(math.sqrt(distance)/?real_radius))
????????????????newX?=?int(newX?+?center_X)
????????????????newY?=?int(newY?+?center_Y)
????????????????if?newX ????????????????????new_data[j?i][0]?=?frame[newY?newX][0]????????#將計算后的坐標移動到原坐標
????????????????????new_data[j?i][1]?=?frame[newY?newX][1]
????????????????????new_data[j?i][2]?=?frame[newY?newX][2]
????????????else:??????????????????????????????????????????#若變換點距離太遠,圖像像素不變動
????????????????new_data[j?i][0]?=?frame[j?i][0]
????????????????new_data[j?i][1]?=?frame[j?i][1]
????????????????new_data[j?i][2]?=?frame[j?i][2]
????return?new_data
def?Minframe(frame):??????????????????#定義圖像縮小函數
????height?width?n?=?frame.shape
????center_X?=?width?/?2
????center_Y?=?height?/?2
????radius?=?400
????newX?=?0
????newY?=?0
????real_radius?=int(radius?/?2.0)
????new_data?=?frame.copy()
????for?i?in?range(width):
????????for?j?in?range(height):
????????????tX?=?i?-?center_X
????????????tY?=?j?-?center_Y
????????????theta?=?math.atan2(tY?tX)
????????????radius?=?math.sqrt((tX?*?tX)?+?(tY?*?tY))?????????????#與上面一樣,計算公式不一樣
????????????newR?=?math.sqrt(radius)?*12
????????????newX?=?int(center_X?+?(newR?*?math.cos(theta)))
????????????newY?=?int(center_Y?+?(newR?*?math.sin(theta)))
????????????if?newX?0?and??newX?>width:
????????????????newX?=?0
????????????if?newY?<0?and?newY?>height:
????????????????newY?=?0
????????????if?newX ????????????????new_data[j?i][0]?=?frame[newY?newX][0]
????????????????new_data[j?i][1]?=?frame[newY?newX][1]
??
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????4336??2020-10-08?06:22??01鍝堝搱闀滃師鐞嗗強浠g爜.py
?????文件?????????788??2020-10-08?06:22??__MACOSX\._01鍝堝搱闀滃師鐞嗗強浠g爜.py
?????文件???????25928??2020-10-08?06:24??1.jpg
?????文件?????????387??2020-10-08?06:24??__MACOSX\._1.jpg
- 上一篇:多項式擬合(LSM.py)
- 下一篇:MaixPy之識別顏色-動態識別色塊
評論
共有 條評論