1、申请ID:
2、个人邮箱:huayujing@163.com
3、原创技术文章:暂无公开发表文章。
下面是我结合自身需求,利用AI帮我写的一款抠图工具。用了最新的抠图模型。配置好的可以用GPU,用CPU也可以用,只展示了一部分代码。后期会增加自动扫描功能,定时扫描指定文件夹,有图片就会执行操作。
第一阶段:搭建基础开发环境(仅需做一次)
- 下载并安装 Python:
- 去 Python 官网下载 Python 3.11 版本(强烈建议用 3.11 稳定版,不要用 3.14 预览版,能避开 99% 的底层 Bug)。
- 关键一步: 安装时,安装界面最下方有一个 Add Python.exe to PATH 的复选框,必须打勾!然后点击默认安装。
- 安装核心依赖库:
- 按键盘的 Win + R 键,输入 cmd 回车,打开黑窗口。
- 在黑窗口里复制粘贴以下命令并回车,等待安装完成(需要全程联网): pip install torch torchvision transformers huggingface_hub pillow setuptools
第二阶段:下载 AI 模型权重在全新电脑上,你需要把 RMBG-2.0 的模型文件扒下来。
- 在桌面上新建一个名为 下载模型.py 的文件,填入以下代码:
Pythonfrom huggingface_hub importsnapshot_download# 这里会自动从官网把模型完整下载到本地snapshot_download(repo_id="briaai/RMBG-2.0",local_dir="./bria_model_temp")print("模型下载完成!")
- 双击运行这个代码。它会在同级目录下生成一个 bria_model_temp 文件夹,里面大约有将近 900MB 的文件(包含 model.safetensors, config.json, birefnet.py 等)。这就是我们的核心“大脑”。
第三阶段:组装“发货文件夹”骨架
- 在桌面上新建你要卖的商品文件夹,命名为 智能抠图专业版。
- 在里面新建 4 个子文件夹:
- 原图 (空文件夹)
- 白底图 (空文件夹)
- bria_model -> 将第二阶段下载的 bria_model_temp 里面的所有文件,复制到这里。
- env -> 找到这台电脑的 Python 安装目录(通常在 C:\Users\你的用户名\AppData\Local\Programs\Python\Python311),把里面的所有文件和文件夹完整复制过来。
第四阶段:植入核心代码与加密编译
- 在 智能抠图专业版 目录下,新建 process.py,填入最终成功的完整版代码(代码较长,必须一字不落):
Pythonimport osimport sysimport hashlibimport subprocessimport threadingimport tkinter as tkfrom tkinter import ttk, messagebox,scrolledtext, simpledialogimport torchfrom PIL import Imagefrom torchvision import transformsimport transformers # 修复 transformers 底层 meta tensor 兼容性问题if nothasattr(transformers.PreTrainedModel, "all_tied_weights_keys"): transformers.PreTrainedModel.all_tied_weights_keys = property(lambdaself: getattr(self, '_tied_weights_keys', {})) SECRET_KEY ="ZHOU_YU_SHOP_888" # 核心密钥 def get_machine_code(): try: cmd = "wmic csproduct get uuid" uuid = subprocess.check_output(cmd,shell=True).decode().split('\n')[1].strip() raw_string = f"ZHOU_YU_RMBG_PRO_{uuid}_2026" return hashlib.md5(raw_string.encode()).hexdigest().upper()[:16] except: return "HARDWARE_ERROR_001" defget_hidden_record_path(machine_code): appdata = os.getenv('APPDATA') hidden_dir = os.path.join(appdata, "Microsoft","Windows", "Templates") os.makedirs(hidden_dir, exist_ok=True) return os.path.join(hidden_dir,f"sys_win_cache_{machine_code[:8]}.dat") def check_auth(): machine_code = get_machine_code() base_dir = os.path.dirname(os.path.abspath(__file__)) license_file = os.path.join(base_dir, "license.txt") expected_key = hashlib.sha256((machine_code +SECRET_KEY).encode()).hexdigest().upper() if os.path.exists(license_file): with open(license_file, "r") as f: if f.read().strip() ==expected_key: return True, 999999,machine_code record_path = get_hidden_record_path(machine_code) used_count = 0 if os.path.exists(record_path): try: with open(record_path,"r") as f: used_count =int(f.read().strip()) except: used_count = 10 return False, max(0, 10 - used_count), machine_code def update_trial_count(machine_code): record_path = get_hidden_record_path(machine_code) used_count = 0 if os.path.exists(record_path): try: with open(record_path,"r") as f: used_count =int(f.read().strip()) except: pass with open(record_path, "w") as f: f.write(str(used_count + 1)) class MattingApp: def __init__(self, root): self.root = root self.root.title("智能商业白底图批量生成系统 Pro") self.root.geometry("650x700") self.root.resizable(True, True) self.is_pro, self.remain_count, self.machine_code = check_auth() self.processing = False self.setup_ui() def setup_ui(self): for widget in self.root.winfo_children(): widget.destroy() auth_frame = ttk.LabelFrame(self.root, text=" 授权信息 ", padding=10) auth_frame.pack(fill=tk.X, padx=15, pady=10) mc_frame = ttk.Frame(auth_frame) mc_frame.pack(fill=tk.X, anchor=tk.W, pady=2) ttk.Label(mc_frame, text="🔑 机器码: ", font=("微软雅黑", 10,"bold")).pack(side=tk.LEFT) self.mc_entry = ttk.Entry(mc_frame, width=22, font=("微软雅黑", 10, "bold")) self.mc_entry.insert(0, self.machine_code) self.mc_entry.config(state='readonly') self.mc_entry.pack(side=tk.LEFT, padx=5) ttk.Button(mc_frame, text="一键复制", command=self.copy_machine_code).pack(side=tk.LEFT, padx=5) status_frame = ttk.Frame(auth_frame) status_frame.pack(fill=tk.X, anchor=tk.W, pady=8)
- 加壳防修改:
- 在文件夹空白处按住 Shift 键,单击右键打开 PowerShell。
- 输入执行:.\env\python.exe -m py_compile process.py
- 进入生成的 __pycache__ 文件夹,将其中的 .pyc 文件剪切到根目录,重命名为 process.pyc。
- 删除原始 process.py 和 __pycache__ 文件夹。
第五阶段:制作无黑框启动脚本在同级目录下新建一个记事本文件,重命名为一键启动.vbs(注意必须改后缀名),右键编辑填入以下代码并保存:VBScriptSet ws =CreateObject("Wscript.Shell")ws.Run ".\env\pythonw.exeprocess.pyc", 0, False此时,将整个智能抠图专业版 压缩成 .zip,即可对外分发售卖。
|