日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python边缘检测代码_Python中的边缘检测

發布時間:2025/3/15 python 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python边缘检测代码_Python中的边缘检测 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我試著寫一個程序,用戶輸入一個數字,它在屏幕上畫出那么多的矩形,但是三角形不能重疊。我對最后一部分有問題,我正在尋求幫助。我借用了Al-Sweigart的一本書中的邊緣檢測方法,他編寫的完整程序可以在這里找到:

以下是我正在執行的程序:import pygame, sys, random

from pygame.locals import *

def doRectsOverlap(rect1, rect2):

for a, b in [(rect1, rect2)]:

# Check if a's corners are inside b

if ((isPointInsideRect(a.left, a.top, b)) or

(isPointInsideRect(a.left, a.bottom, b)) or

(isPointInsideRect(a.right, a.top, b)) or

(isPointInsideRect(a.right, a.bottom, b))):

return True

return False

def isPointInsideRect(x, y, rect):

if (x > rect.left) and (x < rect.right) and (y > rect.top) and (y < rect.bottom):

return True

else:

return False

# set up pygame

pygame.init()

# set up the window

WINDOWWIDTH = 600

WINDOWHEIGHT = 600

windowSurface = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT), 0, 32)

pygame.display.set_caption('Rectangles')

# set up the colors

BLACK = (0, 0, 0)

WHITE = (255, 255, 255)

RED = (255, 0, 0)

GREEN = (0, 255, 0)

BLUE = (0, 0, 255)

from random import choice

foo = [BLACK, RED, GREEN, BLUE]

# draw the background

windowSurface.fill(WHITE)

print('Please enter a number:')

number = input()

x = 0

array = []

for i in array:

while int(number) > x:

x = x+1

x1 = random.randint(1, 400)

y1 = random.randint(1, 400)

x2 = random.randint(1, 400)

y2 = random.randint(1, 400)

x3 = random.randint(1, 400)

y3 = random.randint(1, 400)

x4 = random.randint(1, 400)

y4 = random.randint(1, 400)

box = pygame.draw.rect(windowSurface,random.choice(foo), (x1, y1, x2, y2))

if doRectsOverlap(box, box) == False:

box

else:

x = x-1

# draw the window onto the screen

pygame.display.update()

任何幫助都將不勝感激。謝謝您!在

總結

以上是生活随笔為你收集整理的python边缘检测代码_Python中的边缘检测的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。