728x90
#-*- coding:utf-8 -*-
# 특정 공간에 빈 공간없이 최대 격자 채우기
import cv2
import numpy as np
import random
import matplotlib.pyplot as plt
w = 720
h = 720
white_color = 255
black_color = 0
radi = 20
img = np.zeros((h, w), dtype = np.uint8)
cou = 0
pp = []
while 1:
x = random.randint((-1)*int(radi/2), h+int(radi/2))
y = random.randint((-1)*int(radi/2), w+int(radi/2))
img1 = img.copy()
a1 = sum(sum((img1 > 127)))
cv2.circle(img1, (x, y), radi, white_color, -1)
a2 = sum(sum((img1 > 127)))
#print(a1, a2)
if (a2 - a1) > radi*radi*3.1: # 10 : 310, 20 : 1250
img = img1
cou += 1
print(cou)
else:
img = img
pp.append(cou)
cv2.imshow('img', img)
cv2.waitKey(100)
plt.plot(pp,'.-')
plt.pause(0.01)
plt.clf()


단위 면적 : 720 x 720
#1 CASE :
. 입자 반지름 : 20, 최대 수량 : ~ 202 => 20 / 720 = 1 / 31 => 관계 #1 : 202 / 31


#2 CASE :
. 입자 반지름 : 10, 최대 수량 : ~ 810 => 10 / 720 = 1 / 72 => 관계 #2 : 810 / 72 = 405 / 31


#3 CASE :
. 입자 반지름 : 30, 최대 수량 : ~ 90 => 30 / 720 = 1 / 24 => 관계 #3 : 90 / 72 = 45 / 31


#4 CASE :
. 입자 반지름 : 40, 최대 수량 : ~ 52 => 40 / 720 = 1 / 18 => 관계 #4 : 52 / 72 = 26 / 31
728x90
'파이썬(PYTHON)' 카테고리의 다른 글
논문 초안 - 작성 중 (2) | 2022.01.14 |
---|---|
4가지 크기의 입자로 빈 공간을 최대한 채우는 비율 (0) | 2022.01.13 |
뱅크 추적 (0) | 2022.01.05 |
컨베이어 원료 인식 (0) | 2022.01.05 |
최대 소수 구하기 (100 짜리 까지 진행 중) (0) | 2022.01.05 |