91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 10KB
    文件類型: .py
    金幣: 1
    下載: 0 次
    發布日期: 2021-05-14
  • 語言: Python
  • 標簽: Sutherland-H??

資源簡介

基于python的多邊形幾何操作的代碼 實現任意多邊形(凹、凸、帶內環)的輸入及顯示 ,可自定義多邊形(邊界、內部)的顏色; 實現兩個任意多邊形的裁剪; 實現任意多邊形的平移、旋轉、縮放、翻轉; 支持多步以上操作;

資源截圖

代碼片段和文件信息

import?numpy?as?np
import?cv2

#?============================================================================

CANVAS_SIZE?=?(600800)
CANVAS_COLOR?=?(0?0?0)
FINAL_LINE_COLOR?=?(255?255?255)
FINAL_POLY_COLOR?=?(50?149?216)
WORKING_LINE_COLOR?=?(127?127?127)

#?============================================================================

class?PolygonDrawer(object):
????def?__init__(self?window_name):
????????self.window_name?=?window_name?#?Name?for?our?window
????????self.done?=?False?#?Flag?signalling?we‘re?done
????????self.innerdone?=?False?#Flag?signalling?inner?done
self.cutdone?=?False?#?Flag?signalling?we‘re?done
self.cutinnerdone?=?False?#?Flag?signalling?we‘re?done
self.transform?=?False?#?Flag?transformation?is?done
????????self.current?=?(0?0)?#?Current?position?so?we?can?draw?the?line-in-progress
self.cutcurrent?=?(0?0)?#?Current?position?so?we?can?draw?the?line-in-progress
????????self.points?=?[]?#?List?of?points?defining?our?polygon
????????self.innerpoints?=?[]?#List?of?inner?points?defining?out?polygon
self.cutpoints?=?[]?#List?of?points?defining?our?cut-tube
self.cutinnerpoints?=?[]?#List?of?points?definig?our?cutinner-tube


????def?on_mouse(self?event?x?y?buttons?user_param):
????????#?Mouse?callback?that?gets?called?for?every?mouse?event?(i.e.?moving?clicking?etc.)

????????if?self.done:?#?Nothing?more?to?do
????????????return

????????if?event?==?cv2.EVENT_MOUSEMOVE:
????????????#?We?want?to?be?able?to?draw?the?line-in-progress?so?update?current?mouse?position
????????????self.current?=?(x?y)
????????elif?event?==?cv2.EVENT_LBUTTONDOWN:
????????????#?Left?click?means?adding?a?point?at?current?position?to?the?list?of?points
????????????print(“Adding?point?#%d?with?position(%d%d)“?%?(len(self.points)?x?y))
????????????self.points.append((x?y))
????????elif?event?==?cv2.EVENT_RBUTTONDOWN:
????????????#?Right?click?means?we‘re?done
????????????print(“Completing?polygon?with?%d?points.“?%?len(self.points))
????????????self.done?=?True

????def?on_innermouse(self?event?x?y?buttons?user_param):
????????#?Mouse?callback?that?gets?called?for?every?mouse?event?(i.e.?moving?clicking?etc.)

????????if?self.innerdone:?#?Nothing?more?to?do
????????????return

????????if?event?==?cv2.EVENT_MOUSEMOVE:
????????????#?We?want?to?be?able?to?draw?the?line-in-progress?so?update?current?mouse?position
????????????self.current?=?(x?y)
????????elif?event?==?cv2.EVENT_LBUTTONDOWN:
????????????#?Left?click?means?adding?a?point?at?current?position?to?the?list?of?points
????????????print(“Adding?inner?point?#%d?with?position(%d%d)“?%?(len(self.innerpoints)?x?y))
????????????self.innerpoints.append((x?y))
????????elif?event?==?cv2.EVENT_RBUTTONDOWN:
????????????#?Right?click?means?we‘re?done
????????????print(“Completing?inner?polygon?with?%d?points.“?%?len(self.innerpoints))
????????????self.innerdone?=?True
????????????
????def?on_secmouse(sel

評論

共有 條評論

相關資源