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

vps可以用了做网站吗2017国办网站建设规范

vps可以用了做网站吗,2017国办网站建设规范,南宁物流公司网站建设,网站设计页面如何做居中核心实现思路 滑动窗口策略#xff1a;在图像上滑动固定大小的窗口#xff0c;对每个窗口进行分类多维特征提取#xff1a;结合统计特征、纹理特征、边缘特征、形状特征等随机森林分类#xff1a;训练二分类器判断窗口是否包含目标后处理优化#xff1a;使用非极大值抑制… 核心实现思路 滑动窗口策略在图像上滑动固定大小的窗口对每个窗口进行分类多维特征提取结合统计特征、纹理特征、边缘特征、形状特征等随机森林分类训练二分类器判断窗口是否包含目标后处理优化使用非极大值抑制减少重复检测 特征工程的重要性 LBP纹理特征捕捉局部纹理模式灰度共生矩阵描述纹理的统计特性边缘密度反映目标边界信息形状描述符圆形度、面积比等几何特征 实际应用建议 数据收集收集大量正负样本进行训练特征优化根据具体目标调整特征提取策略参数调优调整窗口大小、步长、置信度阈值等多尺度检测使用不同尺寸的窗口检测不同大小的目标 适用场景 计算资源受限的嵌入式设备目标具有明显纹理或形状特征的场景需要快速部署和调试的原型系统传统图像处理流程的补充 import cv2 import numpy as np from sklearn.ensemble import RandomForestClassifier from sklearn.model_selection import train_test_split from sklearn.metrics import classification_report from skimage.feature import local_binary_pattern, graycomatrix, graycoprops from skimage.measure import regionprops import os from typing import List, Tuple import matplotlib.pyplot as pltclass RandomForestObjectDetector:基于随机森林的目标检测器def __init__(self, window_size(64, 64), step_size16, n_estimators100):初始化检测器Args:window_size: 滑动窗口大小step_size: 滑动步长n_estimators: 随机森林中树的数量self.window_size window_sizeself.step_size step_sizeself.rf_classifier RandomForestClassifier(n_estimatorsn_estimators,random_state42,max_depth10,min_samples_split5)self.is_trained Falsedef extract_features(self, image_patch: np.ndarray) - np.ndarray:从图像块中提取特征Args:image_patch: 输入图像块Returns:特征向量features []# 确保图像是灰度图if len(image_patch.shape) 3:gray cv2.cvtColor(image_patch, cv2.COLOR_BGR2GRAY)else:gray image_patch.copy()# 1. 基础统计特征features.extend([np.mean(gray), # 均值np.std(gray), # 标准差np.median(gray), # 中位数np.min(gray), # 最小值np.max(gray), # 最大值np.var(gray) # 方差])# 2. 纹理特征 - LBP (局部二值模式)radius 3n_points 8 * radiuslbp local_binary_pattern(gray, n_points, radius, methoduniform)lbp_hist, _ np.histogram(lbp.ravel(), binsn_points 2, range(0, n_points 2), densityTrue)features.extend(lbp_hist)# 3. 灰度共生矩阵特征try:# 计算灰度共生矩阵glcm graycomatrix(gray, distances[1], angles[0, 45, 90, 135], levels256, symmetricTrue, normedTrue)# 提取纹理属性contrast graycoprops(glcm, contrast).mean()dissimilarity graycoprops(glcm, dissimilarity).mean()homogeneity graycoprops(glcm, homogeneity).mean()energy graycoprops(glcm, energy).mean()correlation graycoprops(glcm, correlation).mean()features.extend([contrast, dissimilarity, homogeneity, energy, correlation])except:# 如果GLCM计算失败添加默认值features.extend([0, 0, 0, 0, 0])# 4. 边缘特征edges cv2.Canny(gray, 50, 150)edge_density np.sum(edges 0) / edges.sizefeatures.append(edge_density)# 5. 梯度特征grad_x cv2.Sobel(gray, cv2.CV_64F, 1, 0, ksize3)grad_y cv2.Sobel(gray, cv2.CV_64F, 0, 1, ksize3)grad_magnitude np.sqrt(grad_x**2 grad_y**2)features.extend([np.mean(grad_magnitude),np.std(grad_magnitude)])# 6. 形状特征 (通过二值化后的连通区域)_, binary cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY cv2.THRESH_OTSU)contours, _ cv2.findContours(binary, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)if contours:# 找最大轮廓largest_contour max(contours, keycv2.contourArea)area cv2.contourArea(largest_contour)perimeter cv2.arcLength(largest_contour, True)# 形状描述符if perimeter 0:circularity 4 * np.pi * area / (perimeter ** 2)else:circularity 0features.extend([area / (gray.shape[0] * gray.shape[1]), circularity])else:features.extend([0, 0])return np.array(features)def sliding_window(self, image: np.ndarray) - List[Tuple]:在图像上应用滑动窗口Args:image: 输入图像Returns:窗口位置和图像块的列表windows []h, w image.shape[:2]for y in range(0, h - self.window_size[1] 1, self.step_size):for x in range(0, w - self.window_size[0] 1, self.step_size):window image[y:y self.window_size[1], x:x self.window_size[0]]if window.shape[:2] self.window_size:windows.append(((x, y), window))return windowsdef prepare_training_data(self, positive_samples: List[np.ndarray], negative_samples: List[np.ndarray]) - Tuple[np.ndarray, np.ndarray]:准备训练数据Args:positive_samples: 正样本图像块列表negative_samples: 负样本图像块列表Returns:特征矩阵和标签向量features []labels []print(提取正样本特征...)for sample in positive_samples:feature self.extract_features(sample)features.append(feature)labels.append(1) # 正样本标签print(提取负样本特征...)for sample in negative_samples:feature self.extract_features(sample)features.append(feature)labels.append(0) # 负样本标签return np.array(features), np.array(labels)def train(self, positive_samples: List[np.ndarray], negative_samples: List[np.ndarray]):训练随机森林分类器Args:positive_samples: 正样本图像块列表negative_samples: 负样本图像块列表print(准备训练数据...)X, y self.prepare_training_data(positive_samples, negative_samples)print(f训练数据形状: {X.shape}, 标签分布: {np.bincount(y)})# 分割训练和验证集X_train, X_val, y_train, y_val train_test_split(X, y, test_size0.2, random_state42, stratifyy)print(训练随机森林分类器...)self.rf_classifier.fit(X_train, y_train)# 验证性能val_pred self.rf_classifier.predict(X_val)print(\n验证集性能:)print(classification_report(y_val, val_pred))self.is_trained Trueprint(训练完成!)def detect(self, image: np.ndarray, confidence_threshold: float 0.7) - List[Tuple]:在图像中检测目标Args:image: 输入图像confidence_threshold: 置信度阈值Returns:检测结果列表 [(x, y, w, h, confidence), ...]if not self.is_trained:raise ValueError(模型尚未训练请先调用train()方法)detections []windows self.sliding_window(image)print(f处理 {len(windows)} 个窗口...)for (x, y), window in windows:# 提取特征features self.extract_features(window).reshape(1, -1)# 预测prediction self.rf_classifier.predict(features)[0]confidence self.rf_classifier.predict_proba(features)[0][1] # 正类概率if prediction 1 and confidence confidence_threshold:detections.append((x, y, self.window_size[0], self.window_size[1], confidence))return detectionsdef non_max_suppression(self, detections: List[Tuple], overlap_threshold: float 0.3) - List[Tuple]:非极大值抑制Args:detections: 检测结果列表overlap_threshold: 重叠阈值Returns:过滤后的检测结果if not detections:return []# 按置信度排序detections sorted(detections, keylambda x: x[4], reverseTrue)keep []while detections:# 保留置信度最高的检测current detections.pop(0)keep.append(current)# 计算与其他检测的重叠remaining []for detection in detections:iou self.calculate_iou(current, detection)if iou overlap_threshold:remaining.append(detection)detections remainingreturn keepstaticmethoddef calculate_iou(box1: Tuple, box2: Tuple) - float:计算两个边界框的IoUx1, y1, w1, h1, _ box1x2, y2, w2, h2, _ box2# 计算交集xi1 max(x1, x2)yi1 max(y1, y2)xi2 min(x1 w1, x2 w2)yi2 min(y1 h1, y2 h2)if xi2 xi1 or yi2 yi1:return 0.0intersection (xi2 - xi1) * (yi2 - yi1)union w1 * h1 w2 * h2 - intersectionreturn intersection / union if union 0 else 0.0def visualize_detections(self, image: np.ndarray, detections: List[Tuple], title: str 检测结果):可视化检测结果Args:image: 原始图像detections: 检测结果列表title: 图像标题img_vis image.copy()for x, y, w, h, confidence in detections:# 绘制边界框cv2.rectangle(img_vis, (x, y), (x w, y h), (0, 255, 0), 2)# 添加置信度标签label f{confidence:.2f}cv2.putText(img_vis, label, (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 1)plt.figure(figsize(12, 8))plt.imshow(cv2.cvtColor(img_vis, cv2.COLOR_BGR2RGB))plt.title(f{title} - 检测到 {len(detections)} 个目标)plt.axis(off)plt.show()# 使用示例 def create_sample_data():创建示例训练数据# 创建模拟的正样本 (包含目标的图像块)positive_samples []for _ in range(100):# 模拟水坝结构 - 矩形形状with一些纹理sample np.random.randint(50, 100, (64, 64), dtypenp.uint8)# 添加矩形结构cv2.rectangle(sample, (10, 20), (50, 40), 150, -1)# 添加噪声noise np.random.normal(0, 10, sample.shape)sample np.clip(sample noise, 0, 255).astype(np.uint8)positive_samples.append(sample)# 创建模拟的负样本 (背景图像块)negative_samples []for _ in range(200):# 随机背景纹理sample np.random.randint(0, 50, (64, 64), dtypenp.uint8)# 添加随机纹理noise np.random.normal(0, 15, sample.shape)sample np.clip(sample noise, 0, 255).astype(np.uint8)negative_samples.append(sample)return positive_samples, negative_samples# 完整使用示例 if __name__ __main__:# 1. 创建检测器detector RandomForestObjectDetector(window_size(64, 64), step_size32)# 2. 准备训练数据print(创建示例数据...)positive_samples, negative_samples create_sample_data()# 3. 训练模型detector.train(positive_samples, negative_samples)# 4. 创建测试图像test_image np.random.randint(0, 50, (300, 400), dtypenp.uint8)# 在测试图像中放置几个目标cv2.rectangle(test_image, (50, 50), (114, 114), 150, -1)cv2.rectangle(test_image, (200, 150), (264, 214), 150, -1)# 5. 进行检测print(进行目标检测...)detections detector.detect(test_image, confidence_threshold0.6)# 6. 应用非极大值抑制filtered_detections detector.non_max_suppression(detections, overlap_threshold0.3)print(f原始检测数量: {len(detections)})print(fNMS后检测数量: {len(filtered_detections)})# 7. 可视化结果if len(filtered_detections) 0:detector.visualize_detections(cv2.cvtColor(test_image, cv2.COLOR_GRAY2BGR), filtered_detections)else:print(未检测到目标)
http://www.w-s-a.com/news/224923/

相关文章:

  • cctv5+手机在线直播观看seo关键词排名优化方法
  • 网站建设公司怎么谈单怎么开通微信小程序商店
  • 深圳做网站案例一个服务器可以备案几个网站
  • 网络营销策划名词解释泉州百度推广排名优化
  • 一键生成网站的软件互联网营销师是干什么
  • 网站后台管理水印怎么做手机优化设置
  • 哪个网站做图文素材多wordpress++优化
  • 建设网站就选用什么样的公司网站类型分类有哪些
  • 找平面设计师网站网站建设须知
  • 建设联结是不是正规网站wordpress 微博同步
  • 瑞安微网站建设广州推广
  • 做旅游宣传网站的流程图中国企业集成网电子商务
  • 开发商城网站开发成交功能网站
  • 网站建设公司专业公司排名搭建网站的企业
  • 网站建设难吗海南智能网站建设报价
  • 企业网站建设选题的依据及意义校园网站建设的论文
  • 网站版面设计方案水电维修在哪个网站上做推广好些
  • 邹平建设局官方网站企业宣传片广告公司
  • 南京建设集团网站建站极速通
  • 网站建设与推广员岗位职责网站开发应如何入账
  • 企业网站的作用和目的手机回收站
  • 大连零基础网站建设培训电话郎溪做网站
  • 成都科技网站建设注册公司最少需要多少注册资金
  • 找公司做网站注意事项麻城建设局网站停办
  • 沧州企业做网站wordpress 消息通知
  • 网站开发外包计入什么科目怎样申请网站空间
  • 西安建设局网站小孩把巴塘网站建设
  • 做网站 客户一直要求改郑州做优惠券网站的公司
  • 专门做特卖的网站是什么东北石油大学秦皇岛吧
  • 网站建设需要云主机吗wordpress 下载数据表插件