import cv2
import numpy as np
# خوندن تصویر
image = cv2.imread('path/to/image')
# تبدیل تصویر به HSV
hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
# تعیین بازه رنگی سفید از رنگ s و v ها
lower_white = np.array([0, 0, 220])
upper_white = np.array([0, 0, 255])
# پیدا کنیم که کدوم بخشای تصویر تو بازه مشخص وجود دارن
mask = cv2.inRange(hsv, lower_white, upper_white)
# محاسبه تعداد پیکسلای سفید
total_pixels = mask.shape[0] * mask.shape[1]
white_pixels = np.count_nonzero(mask)
# محاسبه درصد رنگ سفید
white_percentage = white_pixels * 100.0 / total_pixels
# نمایش نتیجه
print("Percentage of white pixels:", white_percentage)
if white_percentage > 50:
print("The image is mostly white.")
else:
print("The image is mostly black.")
#پروژه_تشخیص_رنگ
Coders
import cv2 import numpy as np # خوندن تصویر image = cv2.imread('path/to/image') # تبدیل تصویر به H
کتابخونه
cv2
فقط داخل سیستم نصب میشه
import numpy as np
import matplotlib.pyplot as plt
# ساخت یه دایره با اندازه یکسان در تمام جهتها
circle = plt.Circle((0, 0), 0.5, color='gray', fill=True)
# مختصات محورها تو حالت خاکستری روشن
x = np.linspace(-1, 1, 1000)
X, Y = np.meshgrid(x, x)
Z = np.sqrt(X*X + Y*Y)
# رسم محورها و دایره در یه نمودار
fig, ax = plt.subplots()
ax.contourf(X, Y, Z, levels=30, cmap='gray')
ax.add_artist(circle)
# رسم نمودار
plt.axis('scaled')
plt.show()
#نشون_دادن_کره_ماه
Coders
import numpy as np import matplotlib.pyplot as plt # ساخت یه دایره با اندازه یکسان در تمام جهتها c
کتابخونه هاشم که بلدین کدوما هستن
import tkinter as tk
import time
class TimerApp:
def init(self, master):
self.master = master
master.title("Timer App")
self.time_var = tk.StringVar()
self.time_var.set('00:00:00')
self.timer_label = tk.Label(master, textvariable=self.time_var, font=('Helvetica', 48))
self.timer_label.pack()
self.start_button = tk.Button(master, text="Start", command=self.start_timer)
self.start_button.pack()
self.running = False
def start_timer(self):
if not self.running:
self.running = True
self.start_button.config(text="Stop")
self.start_time = time.time()
self.update_timer()
else:
self.master.after_cancel(self.timer_job)
self.running = False
self.start_button.config(text="Start")
def update_timer(self):
elapsed_time = time.time() - self.start_time
hours, rem = divmod(elapsed_time, 3600)
minutes, seconds = divmod(rem, 60)
time_string = '{:02}:{:02}:{:02}'.format(int(hours), int(minutes), int(seconds))
self.time_var.set(time_string)
self.timer_job = self.master.after(1000, self.update_timer)
root = tk.Tk()
timer_app = TimerApp(root)
root.mainloop()
#ساخت_یک_تایمر_پیشرفته