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

广州wap网站制作市场营销策划包括哪些内容

广州wap网站制作,市场营销策划包括哪些内容,影视公司排名,杭州定制网站将分割的mask转换为分割标签通常涉及将每个像素的类别标识(在mask中以不同的灰度值或颜色表示)转换为整数标签。这些标签通常用于机器学习或深度学习模型的训练、验证和测试阶段。 使用方式,控制台或者命令行使用以下命令: pyth…

将分割的mask转换为分割标签通常涉及将每个像素的类别标识(在mask中以不同的灰度值或颜色表示)转换为整数标签。这些标签通常用于机器学习或深度学习模型的训练、验证和测试阶段。

使用方式,控制台或者命令行使用以下命令:

python polygon_mask_conversion.py --img_path xxx_folder --mask_path xxx_folder --mode mask2poly    

转换代码,来自X_anyLabeling的tool文件夹下的转换文件。

import argparse
import json
import os
import time
import cv2from PIL import Image
from tqdm import tqdm
from datetime import dateimport numpy as np
import matplotlib as pltimport syssys.path.append("./")
from anylabeling.app_info import __version__# ======================================================================= Usage ========================================================================#
#                                                                                                                                                      #
# -------------------------------------------------------------------- mask2poly  ----------------------------------------------------------------------#
# python tools/polygon_mask_conversion.py --img_path xxx_folder --mask_path xxx_folder --mode mask2poly                                                #
#                                                                                                                                                      #
# -------------------------------------------------------------------- poly2mask  ----------------------------------------------------------------------#
# [option1] python tools/polygon_mask_conversion.py --img_path xxx_folder --mask_path xxx_folder --mode poly2mask                                      #
# [option2] python tools/polygon_mask_conversion.py --img_path xxx_folder --mask_path xxx_folder --json_path xxx_folder --mode poly2mask               #
#                                                                                                                                                      #
# ======================================================================= Usage ========================================================================#VERSION = __version__
IMG_FORMATS = [".bmp",".dng",".jpeg",".jpg",".mpo",".png",".tif",".tiff",".webp",".pfm",
]class PolygonMaskConversion:def __init__(self, epsilon_factor=0.001):self.epsilon_factor = epsilon_factordef reset(self):self.custom_data = dict(version=VERSION,flags={},shapes=[],imagePath="",imageData=None,imageHeight=-1,imageWidth=-1,)def get_image_size(self, image_file):with Image.open(image_file) as img:width, height = img.sizereturn width, heightdef mask_to_polygon(self, img_file, mask_file, json_file):self.reset()binary_mask = cv2.imread(mask_file, cv2.IMREAD_GRAYSCALE)contours, _ = cv2.findContours(binary_mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)for contour in contours:epsilon = self.epsilon_factor * cv2.arcLength(contour, True)approx = cv2.approxPolyDP(contour, epsilon, True)if len(approx) < 5:continueshape = {"label": "object","text": "","points": [],"group_id": None,"shape_type": "polygon","flags": {},}for point in approx:x, y = point[0].tolist()shape["points"].append([x, y])self.custom_data["shapes"].append(shape)image_width, image_height = self.get_image_size(img_file)self.custom_data["imagePath"] = os.path.basename(img_file)self.custom_data["imageHeight"] = image_heightself.custom_data["imageWidth"] = image_widthwith open(json_file, "w", encoding="utf-8") as f:json.dump(self.custom_data, f, indent=2, ensure_ascii=False)def polygon_to_mask(self, img_file, mask_file, json_file):with open(json_file, "r") as f:data = json.load(f)polygons = []for shape in data["shapes"]:points = shape["points"]polygon = []for point in points:x, y = pointpolygon.append((x, y))polygons.append(polygon)image_width, image_height = self.get_image_size(img_file)image_shape = (image_height, image_width)binary_mask = np.zeros(image_shape, dtype=np.uint8)for polygon_points in polygons:np_polygon = np.array(polygon_points, np.int32)np_polygon = np_polygon.reshape((-1, 1, 2))cv2.fillPoly(binary_mask, [np_polygon], color=255)cv2.imwrite(mask_file, binary_mask)def main():parser = argparse.ArgumentParser(description="Polygon Mask Conversion")parser.add_argument("--img_path", help="Path to image directory")parser.add_argument("--mask_path", help="Path to mask directory")parser.add_argument("--json_path", default="", help="Path to json directory")parser.add_argument("--epsilon_factor",default=0.001,type=float,help="Control the level of simplification when converting a polygon contour to a simplified version",)parser.add_argument("--mode",choices=["mask2poly", "poly2mask"],required=True,help="Choose the conversion mode what you need",)args = parser.parse_args()print(f"Starting conversion to {args.mode}...")start_time = time.time()converter = PolygonMaskConversion(args.epsilon_factor)if args.mode == "mask2poly":file_list = os.listdir(args.mask_path)for file_name in tqdm(file_list, desc="Converting files", unit="file", colour="blue"):img_file = os.path.join(args.img_path, file_name)mask_file = os.path.join(args.mask_path, file_name)json_file = os.path.join(args.img_path, os.path.splitext(file_name)[0] + ".json")converter.mask_to_polygon(img_file, mask_file, json_file)elif args.mode == "poly2mask":# Only binary mask transformations are supported.os.makedirs(args.mask_path, exist_ok=True)file_list = os.listdir(args.img_path)for file_name in tqdm(file_list, desc="Converting files", unit="file", colour="blue"):base_name, suffix = os.path.splitext(file_name)if suffix.lower() not in IMG_FORMATS:continueimg_file = os.path.join(args.img_path, file_name)if not args.json_path:json_file = os.path.join(args.img_path, base_name + ".json")else:json_file = os.path.join(args.json_path, base_name + ".json")mask_file = os.path.join(args.mask_path, base_name + ".png")converter.polygon_to_mask(img_file, mask_file, json_file)end_time = time.time()print(f"Conversion completed successfully!")print(f"Conversion time: {end_time - start_time:.2f} seconds")if __name__ == "__main__":main()

http://www.dinnco.com/news/83291.html

相关文章:

  • 环保企业的网站怎么做网店运营入门基础知识
  • 企业做网站优劣基本seo技术在线咨询
  • 保健品企业网站百度竞价代理商
  • 动态域名解析免费seo免费培训
  • 做直销会员网站如何做谷歌seo推广
  • 给卖假性药的做网站一般要判多久网络公司网站建设
  • 企业网站怎么做百度seo课程培训入门
  • 做360手机网站优化快网页seo优化
  • 商标可以做网站吗网络推广方案怎么写
  • 020网站开发多少钱情感营销
  • 平台网站开发品牌建设的五个要素
  • 如何选择赣州网站建设谷歌外贸平台
  • 自己可以做网站服务器吸引人的微信软文
  • 广州网站建设 企业头条新闻今日头条官方版本
  • wordpress 幻灯seo站长综合查询
  • 住小帮装修案例seo运营学校
  • 临沂做网站多少钱惠州seo关键词推广
  • 哪个网站专门做代购网站页面禁止访问
  • 工会网站建设的重要性网站seo如何做好优化
  • 做网站按什么收费网店seo名词解释
  • 党政网站群建设方案网络推广引流
  • 东莞做外贸网站重庆森林讲的什么内容
  • 专门做熟妇的网站北京网站优化步
  • 政府官方网站建设需要多少钱小广告多的网站
  • thinkphp做网站有什么好处北京官方seo搜索引擎优化推荐
  • 厦门网站制作推广哪个模板建站好
  • 专业网站设计都选亿企邦百度怎么投广告
  • 婚纱网站营销型网站建设
  • 电脑网站搜索如何做nba排名西部和东部
  • 课程资源网站教建设现状分析营销方式和营销策略