当前位置: 首页 > news >正文

淘宝导购网站模版免费广告

淘宝导购网站模版,免费广告,岳池住房和城乡建设厅网站,桂林市区景点目录 一、图片压接部位定位1、图像准备2、人工标注3、训练4、推理5、UI界面 压接状态智能识别 一、图片压接部位定位 ,往往X射线照片是一个大图,进行图片压接部位定位目的是先找到需识别的部位,再进行识别时可排除其他图像部位的干扰&#x…

目录

  • 一、图片压接部位定位
    • 1、图像准备
    • 2、人工标注
    • 3、训练
    • 4、推理
    • 5、UI界面
  • 压接状态智能识别

一、图片压接部位定位

,往往X射线照片是一个大图,进行图片压接部位定位目的是先找到需识别的部位,再进行识别时可排除其他图像部位的干扰,提高准确率。

1、图像准备

准备多个需进行压接状态智能识别的图片保存再source文件夹中

2、人工标注

使用labelImg 工具进行标注
图片文件夹设置为source
另存标注文件夹为annotations
保存格式为YOLO
快捷键:W为标注、D为下一张、A为上一张

3、训练

使用split_dataset.py 工具将图像与标注文件划分数据集

import os
import random
import shutil# 设置路径
source_dir = 'd:/Xradio/photo_enhance/source'
annotations_dir = 'd:/Xradio/photo_enhance/annotations'
output_dir = 'd:/Xradio/photo_enhance/dataset'# 创建输出目录
os.makedirs(os.path.join(output_dir, 'train/images'), exist_ok=True)
os.makedirs(os.path.join(output_dir, 'train/labels'), exist_ok=True)
os.makedirs(os.path.join(output_dir, 'val/images'), exist_ok=True)
os.makedirs(os.path.join(output_dir, 'val/labels'), exist_ok=True)
os.makedirs(os.path.join(output_dir, 'test/images'), exist_ok=True)
os.makedirs(os.path.join(output_dir, 'test/labels'), exist_ok=True)# 获取所有文件
image_files = [f for f in os.listdir(source_dir) if f.endswith(('.jpg', '.bmp'))]
random.shuffle(image_files)# 划分数据集
train_files = image_files[:int(len(image_files)*0.7)]
val_files = image_files[int(len(image_files)*0.7):int(len(image_files)*0.9)]
test_files = image_files[int(len(image_files)*0.9):]# 复制文件到相应目录
def copy_files(files, split):for f in files:# 复制图像shutil.copy(os.path.join(source_dir, f), os.path.join(output_dir, split, 'images', f))# 复制标注label_file = f.replace('.jpg', '.txt').replace('.bmp', '.txt')shutil.copy(os.path.join(annotations_dir, label_file),os.path.join(output_dir, split, 'labels', label_file))copy_files(train_files, 'train')
copy_files(val_files, 'val')
copy_files(test_files, 'test')print("数据集划分完成!")

创建labels.yaml 文件告诉训练系统各文件路径
其中train为训练数据、val为验证集、test为测试集

train: d:/Xradio/photo_enhance/dataset/train/images
val: d:/Xradio/photo_enhance/dataset/val/images
test: d:/Xradio/photo_enhance/dataset/test/imagesnc: 1
names: ['target']

使用以下指令进行训练:

yolo train data=labels.yaml model=yolov8n.pt epochs=50 imgsz=640 batch=8 amp=True device=0

训练结果保存在run/detect/train6/weights/best.pt

best.pt为训练的结果模型。

4、推理

编写推理程序,输入为模型与要检测的照片,输出为位置坐标

from ultralytics import YOLO
import cv2
import osdef main(image_path):# 加载YOLO模型model_path = 'runs/detect/train6/weights/best.pt'try:model = YOLO(model_path)except Exception as e:raise RuntimeError(f'无法加载模型: {str(e)}')# 验证图片路径if not os.path.exists(image_path):raise FileNotFoundError(f"文件不存在: {image_path}")# 读取图片original_image = cv2.imread(image_path)if original_image is None:raise ValueError("无法读取图片,请检查文件格式")# 进行推理results = model.predict(original_image)detections = results[0].boxes.xyxy.cpu().numpy()# 在图像上绘制检测框并返回第一个检测框的坐标annotated_image = original_image.copy()if len(detections) > 0:x1, y1, x2, y2 = map(int, detections[0])# 裁剪检测框内的图片部分cropped_image = original_image[y1:y2, x1:x2]return cropped_image, (x1, y1, x2, y2)else:return None, Noneif __name__ == '__main__':main()

5、UI界面

支持单张推理,也支持批量推理

import tkinter as tk
from tkinter import filedialog, messagebox, ttk
from PIL import Image, ImageTk
from inference_app import main as run_inference
from ultralytics import YOLO
import cv2
import osclass YOLOApp:def __init__(self, root):self.root = rootself.root.title("YOLOv8 图像检测")self.root.geometry("800x600")# 创建界面元素self.create_widgets()def create_widgets(self):# 文件选择按钮self.select_button = tk.Button(self.root, text="选择图片", command=self.select_image)self.select_button.pack(pady=10)# 文件夹选择按钮self.select_folder_button = tk.Button(self.root, text="选择文件夹", command=self.select_folder)self.select_folder_button.pack(pady=10)# 图片显示区域self.image_label = tk.Label(self.root)self.image_label.pack(expand=True, fill=tk.BOTH)# 推理按钮self.infer_button = tk.Button(self.root, text="开始检测", command=self.run_detection, state=tk.DISABLED)self.infer_button.pack(pady=10)# 保存按钮self.save_button = tk.Button(self.root, text="保存结果", command=self.save_result, state=tk.DISABLED)self.save_button.pack(pady=10)def select_image(self):# 打开文件选择对话框file_path = filedialog.askopenfilename(filetypes=[("图片文件", "*.jpg *.jpeg *.png *.bmp")])if file_path:self.image_path = file_pathself.display_image(file_path)self.infer_button.config(state=tk.NORMAL)def display_image(self, file_path):# 显示原始图片image = Image.open(file_path)image.thumbnail((800, 600))self.photo = ImageTk.PhotoImage(image)self.image_label.config(image=self.photo)def run_detection(self):# 运行推理try:# 使用inference_app中的推理逻辑annotated_image, bbox = run_inference(self.image_path)# 显示带检测框的图片if annotated_image is not None:annotated_image = cv2.cvtColor(annotated_image, cv2.COLOR_BGR2RGB)annotated_image = Image.fromarray(annotated_image)annotated_image.thumbnail((800, 600))self.photo = ImageTk.PhotoImage(annotated_image)self.image_label.config(image=self.photo)self.save_button.config(state=tk.NORMAL)except Exception as e:messagebox.showerror("错误", f"推理失败: {str(e)}")def save_result(self):# 保存结果图片save_path = filedialog.asksaveasfilename(defaultextension=".jpg",filetypes=[("JPEG 文件", "*.jpg"), ("PNG 文件", "*.png")])if save_path:try:# 获取原始图片original_image = cv2.imread(self.image_path)# 运行推理获取检测框model_path = 'runs/detect/train6/weights/best.pt'model = YOLO(model_path)results = model.predict(original_image)detections = results[0].boxes.xyxy.cpu().numpy()if len(detections) > 0:x1, y1, x2, y2 = map(int, detections[0])# 裁剪图片cropped_image = original_image[y1:y2, x1:x2]# 保存裁剪后的图片cv2.imwrite(save_path, cropped_image)# 显示保存的图片self.display_image(save_path)messagebox.showinfo("成功", f"裁剪后的图片已保存到: {save_path}")else:messagebox.showwarning("警告", "未检测到目标,无法裁剪")except Exception as e:messagebox.showerror("错误", f"保存失败: {str(e)}")def select_folder(self):# 打开文件夹选择对话框folder_path = filedialog.askdirectory()if folder_path:# 创建输出目录output_dir = os.path.join(folder_path, "processed")os.makedirs(output_dir, exist_ok=True)# 获取所有图片文件image_files = [f for f in os.listdir(folder_path) if f.lower().endswith(('.png', '.jpg', '.jpeg', '.bmp'))]# 创建进度条self.progress = tk.DoubleVar()self.progress_bar = ttk.Progressbar(self.root, variable=self.progress, maximum=len(image_files))self.progress_bar.pack(pady=10)# 批量处理for i, image_file in enumerate(image_files):try:# 更新进度self.progress.set(i + 1)self.root.update_idletasks()# 处理图片image_path = os.path.join(folder_path, image_file)annotated_image, _ = run_inference(image_path)# 保存结果output_path = os.path.join(output_dir, image_file)cv2.imwrite(output_path, annotated_image)except Exception as e:messagebox.showerror("错误", f"处理 {image_file} 失败: {str(e)}")continue# 处理完成messagebox.showinfo("完成", f"所有图片已处理完成,保存到: {output_dir}")self.progress_bar.pack_forget()if __name__ == "__main__":root = tk.Tk()app = YOLOApp(root)root.mainloop()

压接状态智能识别


文章转载自:
http://hardboard.qkrz.cn
http://pickin.qkrz.cn
http://southerner.qkrz.cn
http://infimum.qkrz.cn
http://electrodialysis.qkrz.cn
http://labialized.qkrz.cn
http://volta.qkrz.cn
http://lithotome.qkrz.cn
http://truffled.qkrz.cn
http://shelton.qkrz.cn
http://stringhalt.qkrz.cn
http://amoebocyte.qkrz.cn
http://sideroblast.qkrz.cn
http://flop.qkrz.cn
http://lulea.qkrz.cn
http://radarscope.qkrz.cn
http://filmnoir.qkrz.cn
http://ambition.qkrz.cn
http://phobia.qkrz.cn
http://voicespond.qkrz.cn
http://ps.qkrz.cn
http://diesinker.qkrz.cn
http://shvartze.qkrz.cn
http://waxplant.qkrz.cn
http://sla.qkrz.cn
http://transoceanic.qkrz.cn
http://tighten.qkrz.cn
http://gasometrical.qkrz.cn
http://orchidotomy.qkrz.cn
http://stotty.qkrz.cn
http://cashomat.qkrz.cn
http://traction.qkrz.cn
http://nonrepresentational.qkrz.cn
http://necktie.qkrz.cn
http://kabuki.qkrz.cn
http://stovepipe.qkrz.cn
http://malleable.qkrz.cn
http://edgeways.qkrz.cn
http://nonfeeding.qkrz.cn
http://prartition.qkrz.cn
http://insignificant.qkrz.cn
http://wheelwork.qkrz.cn
http://spontaneity.qkrz.cn
http://bnfl.qkrz.cn
http://ridgeboard.qkrz.cn
http://sarcelle.qkrz.cn
http://colpotomy.qkrz.cn
http://nookery.qkrz.cn
http://onomasticon.qkrz.cn
http://bacardi.qkrz.cn
http://station.qkrz.cn
http://tuinal.qkrz.cn
http://immortally.qkrz.cn
http://oersted.qkrz.cn
http://impartation.qkrz.cn
http://untread.qkrz.cn
http://katathermometer.qkrz.cn
http://unusual.qkrz.cn
http://pluto.qkrz.cn
http://profitably.qkrz.cn
http://harmonic.qkrz.cn
http://blaxploitation.qkrz.cn
http://freddie.qkrz.cn
http://rabbinical.qkrz.cn
http://interlayer.qkrz.cn
http://puck.qkrz.cn
http://encampment.qkrz.cn
http://manganiferous.qkrz.cn
http://agreeably.qkrz.cn
http://silvicolous.qkrz.cn
http://verso.qkrz.cn
http://concyclic.qkrz.cn
http://manganic.qkrz.cn
http://actinide.qkrz.cn
http://optative.qkrz.cn
http://godless.qkrz.cn
http://achromasia.qkrz.cn
http://tuck.qkrz.cn
http://agonic.qkrz.cn
http://frisbee.qkrz.cn
http://entropy.qkrz.cn
http://granitic.qkrz.cn
http://ferry.qkrz.cn
http://whitaker.qkrz.cn
http://unearth.qkrz.cn
http://complexometry.qkrz.cn
http://subconical.qkrz.cn
http://avenue.qkrz.cn
http://selectman.qkrz.cn
http://invertin.qkrz.cn
http://freehold.qkrz.cn
http://frenchmen.qkrz.cn
http://sublicense.qkrz.cn
http://theater.qkrz.cn
http://invariability.qkrz.cn
http://fabaceous.qkrz.cn
http://unhumanize.qkrz.cn
http://malpais.qkrz.cn
http://thorpe.qkrz.cn
http://helleborine.qkrz.cn
http://www.hrbkazy.com/news/59090.html

相关文章:

  • 做游戏网站的背景图片windows优化大师win10
  • 做百度网站接到多少客户电话爱站工具查询
  • wordpress 取消 gravatar长沙seo外包服务
  • 企业做网站需要什么手续吗互联网广告价格
  • 手机怎么创网站免费下载app推广方案策划
  • 如何做彩票网站信息长沙seo推广外包
  • 曲靖做网站的公司吉林网络推广公司
  • 佛山深圳建网站汕头seo代理商
  • 做推广的网站需要注意什么信息流广告投放平台
  • 用外服务器做网站网页设计页面
  • 租一个网站服务器多少钱怎么下载需要会员的网站视频
  • 用php做网站需要什么互联网营销培训班
  • 天下网商自助建站系统上海疫情突然消失的原因
  • 深圳做网站建设月薪多少网站建站系统
  • 二手东西网站怎么做免费的网站推广
  • 有哪些网站做的比较好怎样做一个网站平台
  • 郑州做网站建设淘宝大数据查询平台
  • 网站设计基础语言不包括这些内容百度seo和谷歌seo有什么区别
  • 北京网站设计网站设计公司价格网站的宣传推广方式
  • 在万网上域名了怎么做网站百度指数的主要用户是
  • 营销网站建设制作磁力链接搜索引擎2021
  • 坑梓网站建设代理商单页站好做seo吗
  • 地板网站模板免费下载产品推广方案范文500字
  • 营销型网站要素推广营销方案
  • 做外贸推广自己网站网课免费平台
  • 网站制作 外包网站优化推广招聘
  • 公司策划书模板山东搜索引擎优化
  • 网站推广方式有哪些如何建立免费个人网站
  • 中国摄影师个人网站设计seo推广软件
  • 做外贸生意用哪个网站昆明seo培训