基于Python編寫監(jiān)控視頻存儲(chǔ)計(jì)算器
這篇文章主要來和大家介紹一下如何使用Python開發(fā)一個(gè)簡單的監(jiān)控視頻存儲(chǔ)計(jì)算器,下面是示例代碼,希望對大家有所幫助
完整代碼
import tkinter as tk
from tkinter import ttk
import math
from tkinter.font import Font
class StorageCalculator:
def __init__(self, root):
self.root = root
self.root.title("監(jiān)控視頻存儲(chǔ)計(jì)算器")
self.root.geometry("600x800")
self.root.configure(bg='#f0f0f0')
# 設(shè)置主題和樣式
self.style = ttk.Style()
self.style.theme_use('clam') # 使用clam主題作為基礎(chǔ)
# 定義顏色方案
self.colors = {
'primary': '#2196F3', # 主色調(diào)
'secondary': '#64B5F6', # 次要色調(diào)
'bg': '#f0f0f0', # 背景色
'text': '#212121', # 文字顏色
'success': '#4CAF50' # 成功色
}
# 設(shè)置自定義字體
self.title_font = Font(family="微軟雅黑", size=12, weight="bold")
self.normal_font = Font(family="微軟雅黑", size=10)
self.result_font = Font(family="微軟雅黑", size=11, weight="bold")
# 配置樣式
self.style.configure('Title.TLabel',
font=self.title_font,
background=self.colors['bg'],
foreground=self.colors['primary'])
self.style.configure('Normal.TLabel',
font=self.normal_font,
background=self.colors['bg'])
self.style.configure('Custom.TButton',
font=self.normal_font,
background=self.colors['primary'],
padding=(20, 10))
self.style.configure('Tab.TNotebook',
background=self.colors['bg'])
self.style.configure('Result.TLabelframe',
background=self.colors['bg'])
# 創(chuàng)建主標(biāo)題
self.create_header()
# 創(chuàng)建notebook
self.notebook = ttk.Notebook(root, style='Tab.TNotebook')
self.notebook.pack(fill='both', expand=True, padx=20, pady=(0, 20))
# 創(chuàng)建計(jì)算頁面
self.create_forward_page()
self.create_reverse_page()
# 創(chuàng)建頁腳
self.create_footer()
def create_header(self):
"""創(chuàng)建頭部標(biāo)題區(qū)域"""
header_frame = ttk.Frame(self.root)
header_frame.pack(fill='x', padx=20, pady=20)
title = ttk.Label(header_frame,
text="監(jiān)控視頻存儲(chǔ)計(jì)算器",
style='Title.TLabel')
title.pack()
subtitle = ttk.Label(header_frame,
text="專業(yè)的存儲(chǔ)空間評估工具",
style='Normal.TLabel')
subtitle.pack()
def create_forward_page(self):
"""創(chuàng)建正向計(jì)算頁面"""
self.forward_frame = ttk.Frame(self.notebook, padding="20")
self.notebook.add(self.forward_frame, text=" 計(jì)算存儲(chǔ)需求 ")
# 創(chuàng)建輸入?yún)^(qū)域
input_frame = ttk.LabelFrame(self.forward_frame,
text="參數(shù)輸入",
padding="15")
input_frame.pack(fill='x', padx=10, pady=5)
# 添加輸入控件
self.create_input_field(input_frame, "攝像頭數(shù)量:", 0, self.normal_font)
self.cameras = self.entry
self.create_input_field(input_frame, "每天錄像時(shí)間(小時(shí)):", 1, self.normal_font)
self.hours = self.entry
self.hours.insert(0, "24") # 默認(rèn)24小時(shí)
self.create_input_field(input_frame, "需要保存的天數(shù):", 2, self.normal_font)
self.days = self.entry
# 攝像頭類型選擇
ttk.Label(input_frame, text="攝像頭類型:",
font=self.normal_font).grid(row=3, column=0,
sticky=tk.W, pady=5)
self.camera_type = ttk.Combobox(input_frame, width=25,
font=self.normal_font)
self.camera_type['values'] = ['200萬像素', '300萬像素', '400萬像素', '500萬像素']
self.camera_type.current(0)
self.camera_type.grid(row=3, column=1, sticky=tk.W, pady=5)
# 編碼方式選擇
ttk.Label(input_frame, text="編碼方式:",
font=self.normal_font).grid(row=4, column=0,
sticky=tk.W, pady=5)
self.encoding = ttk.Combobox(input_frame, width=25,
font=self.normal_font)
self.encoding['values'] = ['H.264', 'H.265']
self.encoding.current(1) # 默認(rèn)H.265
self.encoding.grid(row=4, column=1, sticky=tk.W, pady=5)
# 計(jì)算按鈕
btn_frame = ttk.Frame(self.forward_frame)
btn_frame.pack(fill='x', pady=20)
calc_btn = ttk.Button(btn_frame,
text="計(jì)算存儲(chǔ)需求",
style='Custom.TButton',
command=self.calculate_forward)
calc_btn.pack(expand=True)
# 結(jié)果顯示區(qū)域
self.forward_result_frame = ttk.LabelFrame(self.forward_frame,
text="計(jì)算結(jié)果",
padding="15",
style='Result.TLabelframe')
self.forward_result_frame.pack(fill='x', padx=10, pady=5)
self.storage_label = ttk.Label(self.forward_result_frame,
text="",
font=self.result_font)
self.storage_label.pack(anchor=tk.W)
self.recommendation_label = ttk.Label(self.forward_result_frame,
text="",
font=self.result_font)
self.recommendation_label.pack(anchor=tk.W)
def create_reverse_page(self):
"""創(chuàng)建反向計(jì)算頁面"""
self.reverse_frame = ttk.Frame(self.notebook, padding="20")
self.notebook.add(self.reverse_frame, text=" 計(jì)算存儲(chǔ)時(shí)間 ")
# 創(chuàng)建輸入?yún)^(qū)域
input_frame = ttk.LabelFrame(self.reverse_frame,
text="參數(shù)輸入",
padding="15")
input_frame.pack(fill='x', padx=10, pady=5)
# 添加輸入控件
self.create_input_field(input_frame, "硬盤容量(TB):", 0, self.normal_font)
self.storage_size = self.entry
self.create_input_field(input_frame, "攝像頭數(shù)量:", 1, self.normal_font)
self.rev_cameras = self.entry
self.create_input_field(input_frame, "每天錄像時(shí)間(小時(shí)):", 2, self.normal_font)
self.rev_hours = self.entry
# 攝像頭類型選擇
ttk.Label(input_frame, text="攝像頭類型:",
font=self.normal_font).grid(row=3, column=0,
sticky=tk.W, pady=5)
self.rev_camera_type = ttk.Combobox(input_frame, width=25,
font=self.normal_font)
self.rev_camera_type['values'] = ['200萬像素', '300萬像素', '400萬像素', '500萬像素']
self.rev_camera_type.current(0)
self.rev_camera_type.grid(row=3, column=1, sticky=tk.W, pady=5)
# 編碼方式選擇
ttk.Label(input_frame, text="編碼方式:",
font=self.normal_font).grid(row=4, column=0,
sticky=tk.W, pady=5)
self.rev_encoding = ttk.Combobox(input_frame, width=25,
font=self.normal_font)
self.rev_encoding['values'] = ['H.264', 'H.265']
self.rev_encoding.current(1) # 默認(rèn)H.265
self.rev_encoding.grid(row=4, column=1, sticky=tk.W, pady=5)
# 計(jì)算按鈕
btn_frame = ttk.Frame(self.reverse_frame)
btn_frame.pack(fill='x', pady=20)
calc_btn = ttk.Button(btn_frame,
text="計(jì)算可存儲(chǔ)天數(shù)",
style='Custom.TButton',
command=self.calculate_reverse)
calc_btn.pack(expand=True)
# 結(jié)果顯示區(qū)域
self.reverse_result_frame = ttk.LabelFrame(self.reverse_frame,
text="計(jì)算結(jié)果",
padding="15",
style='Result.TLabelframe')
self.reverse_result_frame.pack(fill='x', padx=10, pady=5)
self.days_label = ttk.Label(self.reverse_result_frame,
text="",
font=self.result_font)
self.days_label.pack(anchor=tk.W)
def create_footer(self):
"""創(chuàng)建頁腳"""
footer = ttk.Label(self.root,
text="? 2024 專業(yè)視頻監(jiān)控存儲(chǔ)解決方案",
style='Normal.TLabel')
footer.pack(pady=10)
def create_input_field(self, parent, label_text, row, font):
"""創(chuàng)建統(tǒng)一的輸入字段"""
ttk.Label(parent, text=label_text,
font=font).grid(row=row, column=0,
sticky=tk.W, pady=5)
self.entry = ttk.Entry(parent, width=25,
font=font)
self.entry.grid(row=row, column=1, sticky=tk.W, pady=5)
return self.entry
def calculate_storage(self, cameras, hours_per_day, days, camera_type, encoding):
"""
計(jì)算存儲(chǔ)需求
camera_type: 攝像頭類型 (200萬/300萬/400萬/500萬)
encoding: 編碼方式 (H.264/H.265)
"""
# 每天存儲(chǔ)空間(GB)
daily_storage = {
'200萬像素': {
'H.264': 42.19, # 4096kbps
'H.265': 21.09 # 2048kbps
},
'300萬像素': {
'H.264': 42.19, # 4096kbps
'H.265': 21.09 # 2048kbps
},
'400萬像素': {
'H.264': 42.19, # 4096kbps
'H.265': 21.09 # 2048kbps
},
'500萬像素': {
'H.264': 63.28, # 6144kbps
'H.265': 31.64 # 3072kbps
}
}
# 計(jì)算單個(gè)攝像頭每天實(shí)際存儲(chǔ)量
daily_per_camera = daily_storage[camera_type][encoding] * (hours_per_day / 24)
# 計(jì)算總存儲(chǔ)量
total_storage_gb = daily_per_camera * cameras * days
# 轉(zhuǎn)換為TB并返回
return round(total_storage_gb / 1024, 2)
def calculate_days(self, storage_tb, cameras, hours_per_day, camera_type, encoding):
"""
計(jì)算可存儲(chǔ)天數(shù)
"""
daily_storage = {
'200萬像素': {
'H.264': 42.19,
'H.265': 21.09
},
'300萬像素': {
'H.264': 42.19,
'H.265': 21.09
},
'400萬像素': {
'H.264': 42.19,
'H.265': 21.09
},
'500萬像素': {
'H.264': 63.28,
'H.265': 31.64
}
}
# 計(jì)算單個(gè)攝像頭每天實(shí)際存儲(chǔ)量
daily_per_camera = daily_storage[camera_type][encoding] * (hours_per_day / 24)
# 計(jì)算可存儲(chǔ)天數(shù)
total_gb = storage_tb * 1024
days = total_gb / (daily_per_camera * cameras)
return round(days, 1)
def calculate_forward(self):
try:
cameras = int(self.cameras.get())
hours = float(self.hours.get())
days = int(self.days.get())
camera_type = self.camera_type.get()
encoding = self.encoding.get()
if cameras <= 0 or hours <= 0 or days <= 0:
raise ValueError("請輸入大于0的數(shù)值")
# 獲取單個(gè)攝像頭每天的存儲(chǔ)量
daily_storage = {
'200萬像素': {
'H.264': 42.19,
'H.265': 21.09
},
'300萬像素': {
'H.264': 42.19,
'H.265': 21.09
},
'400萬像素': {
'H.264': 42.19,
'H.265': 21.09
},
'500萬像素': {
'H.264': 63.28,
'H.265': 31.64
}
}
daily_per_camera = daily_storage[camera_type][encoding] * (hours / 24)
daily_total = daily_per_camera * cameras
storage = self.calculate_storage(cameras, hours, days, camera_type, encoding)
self.storage_label.config(
text=f"每天存儲(chǔ)空間: {round(daily_total, 2)} GB/天\n"
f"總存儲(chǔ)容量: {storage} TB",
foreground=self.colors['success'])
self.recommendation_label.config(
text=f"建議配置: {math.ceil(storage)} TB 硬盤\n"
f"(基于{camera_type}攝像頭,{encoding}編碼)\n"
f"單個(gè)攝像頭: {round(daily_per_camera, 2)} GB/天",
foreground=self.colors['success'])
except ValueError as e:
self.storage_label.config(
text="輸入錯(cuò)誤!",
foreground='red')
self.recommendation_label.config(
text="請檢查輸入的數(shù)值是否正確",
foreground='red')
def calculate_reverse(self):
try:
storage = float(self.storage_size.get())
cameras = int(self.rev_cameras.get())
hours = float(self.rev_hours.get())
camera_type = self.rev_camera_type.get()
encoding = self.rev_encoding.get()
if storage <= 0 or cameras <= 0 or hours <= 0:
raise ValueError("請輸入大于0的數(shù)值")
# 獲取單個(gè)攝像頭每天的存儲(chǔ)量
daily_storage = {
'200萬像素': {
'H.264': 42.19,
'H.265': 21.09
},
'300萬像素': {
'H.264': 42.19,
'H.265': 21.09
},
'400萬像素': {
'H.264': 42.19,
'H.265': 21.09
},
'500萬像素': {
'H.264': 63.28,
'H.265': 31.64
}
}
daily_per_camera = daily_storage[camera_type][encoding] * (hours / 24)
daily_total = daily_per_camera * cameras
days = self.calculate_days(storage, cameras, hours, camera_type, encoding)
self.days_label.config(
text=f"每天存儲(chǔ)空間: {round(daily_total, 2)} GB/天\n"
f"單個(gè)攝像頭: {round(daily_per_camera, 2)} GB/天\n"
f"可存儲(chǔ)天數(shù): {days} 天\n"
f"約等于 {round(days/30, 1)} 個(gè)月 或 {round(days/365, 1)} 年\n"
f"(基于{camera_type}攝像頭,{encoding}編碼)",
foreground=self.colors['success'])
except ValueError as e:
self.days_label.config(
text="輸入錯(cuò)誤!\n請檢查輸入的數(shù)值是否正確",
foreground='red')
def main():
root = tk.Tk()
app = StorageCalculator(root)
root.mainloop()
if __name__ == "__main__":
main()效果圖

到此這篇關(guān)于基于Python編寫監(jiān)控視頻存儲(chǔ)計(jì)算器的文章就介紹到這了,更多相關(guān)Python監(jiān)控視頻存儲(chǔ)計(jì)算器內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Python中如何使用pypandoc進(jìn)行格式轉(zhuǎn)換操作
這篇文章主要介紹了Python中如何使用pypandoc進(jìn)行格式轉(zhuǎn)換操作,pypandoc是一個(gè)強(qiáng)大的文檔轉(zhuǎn)換工具,它可以將各種標(biāo)記語言轉(zhuǎn)換為不同的格式,支持多種輸入和輸出格式,并允許用戶添加自定義樣式、模板和過濾器2021-06-06
Python Pandas數(shù)據(jù)中對時(shí)間的操作
這篇文章主要介紹了Python Pandas數(shù)據(jù)中對時(shí)間的操作,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-07-07
Python2到Python3的遷移過程中報(bào)錯(cuò)AttributeError: ‘str‘ objec
在 Python 編程過程中,AttributeError: 'str' object has no attribute 'decode' 是一個(gè)常見的錯(cuò)誤,這通常會(huì)在處理字符串時(shí)出現(xiàn),尤其是在 Python 2 到 Python 3 的遷移過程中,本文將詳細(xì)介紹該問題的根源,并提供解決方案,需要的朋友可以參考下2025-04-04
Python使用py2neo操作圖數(shù)據(jù)庫neo4j的方法詳解
這篇文章主要介紹了Python使用py2neo操作圖數(shù)據(jù)庫neo4j的方法,結(jié)合實(shí)例形式詳細(xì)分析了Python使用py2neo操作圖數(shù)據(jù)庫neo4j的具體步驟、原理、相關(guān)使用技巧與操作注意事項(xiàng),需要的朋友可以參考下2020-01-01
解決plt.imshow顯示cv2.imread讀取的圖像有色差發(fā)藍(lán)的四種方法問題
本文主要介紹了解決plt.imshow顯示cv2.imread讀取的圖像有色差發(fā)藍(lán)的四種方法問題,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-04-04
Gradio機(jī)器學(xué)習(xí)模型快速部署工具應(yīng)用分享
這篇文章主要為大家介紹了Gradio機(jī)器學(xué)習(xí)模型快速部署工具應(yīng)用分享原文翻譯,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-04-04
python中使用you-get庫批量在線下載bilibili視頻的教程
這篇文章主要介紹了使用python中you-get庫批量在線下載bilibili視頻的方法,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-03-03

