CN118710670A - Multi-angle contour point extraction method and storage medium based on 3D engine - Google Patents
Multi-angle contour point extraction method and storage medium based on 3D engine Download PDFInfo
- Publication number
- CN118710670A CN118710670A CN202410694998.3A CN202410694998A CN118710670A CN 118710670 A CN118710670 A CN 118710670A CN 202410694998 A CN202410694998 A CN 202410694998A CN 118710670 A CN118710670 A CN 118710670A
- Authority
- CN
- China
- Prior art keywords
- target
- contour
- contour point
- point set
- data
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T7/00—Image analysis
- G06T7/10—Segmentation; Edge detection
- G06T7/13—Edge detection
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T7/00—Image analysis
- G06T7/60—Analysis of geometric attributes
- G06T7/62—Analysis of geometric attributes of area, perimeter, diameter or volume
-
- Y—GENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02T—CLIMATE CHANGE MITIGATION TECHNOLOGIES RELATED TO TRANSPORTATION
- Y02T10/00—Road transport of goods or passengers
- Y02T10/10—Internal combustion engine [ICE] based vehicles
- Y02T10/40—Engine management systems
Landscapes
- Engineering & Computer Science (AREA)
- Physics & Mathematics (AREA)
- Computer Vision & Pattern Recognition (AREA)
- General Physics & Mathematics (AREA)
- Theoretical Computer Science (AREA)
- Geometry (AREA)
- Image Analysis (AREA)
- Image Processing (AREA)
Abstract
本申请公开了一种基于3D引擎的多角度轮廓点提取方法及存储介质,该方法包括:获取目标模型;确定目标模型对应的目标3D引擎及目标3D引擎摄像机;通过目标3D引擎摄像机在目标拍摄角度下对目标模型进行拍摄,得到目标图像;针对目标图像进行像素点遍历,得到第一目标轮廓点集;根据目标递归算法对第一目标轮廓点集进行拆分,得到n个轮廓点集;在n大于1时,对n个轮廓点集采用射线交叉法判断其内外轮廓,得到内外轮廓数据;基于格林公式计算n个轮廓点集中轮廓点构成的多边形的面积,得到n个面积数据;对n个轮廓点集、内外轮廓数据和n个面积数据进行整合导出,得到目标轮廓点数据。采用本申请实施例,提高了轮廓点的提取效率。
The present application discloses a multi-angle contour point extraction method based on a 3D engine and a storage medium, the method comprising: obtaining a target model; determining a target 3D engine and a target 3D engine camera corresponding to the target model; photographing the target model at a target shooting angle through the target 3D engine camera to obtain a target image; performing pixel point traversal on the target image to obtain a first target contour point set; splitting the first target contour point set according to a target recursive algorithm to obtain n contour point sets; when n is greater than 1, using a ray crossing method to determine the inner and outer contours of the n contour point sets to obtain inner and outer contour data; calculating the area of a polygon formed by contour points in the n contour point sets based on the Green's formula to obtain n area data; integrating and deriving the n contour point sets, the inner and outer contour data and the n area data to obtain target contour point data. The embodiment of the present application improves the efficiency of contour point extraction.
Description
技术领域Technical Field
本申请涉及图像处理技术领域,尤其涉及一种基于3D引擎的多角度轮廓点提取方法及存储介质。The present application relates to the field of image processing technology, and in particular to a multi-angle contour point extraction method and storage medium based on a 3D engine.
背景技术Background Art
随着人工智能技术的不断发展,大模型在计算机视觉领域的应用越来越广泛。计算机视觉是一种模拟人类视觉系统的技术,通过图像处理、特征提取、模式识别等技术手段,实现对图像内容的理解和分析。而大模型则是指模型参数数量庞大、训练数据量巨大的深度学习模型。轮廓是用于形状分析以及对象检测和识别的有用工具,所以大量的轮廓点集是大模型训练所需要的,这就需要用到轮廓点提取技术。With the continuous development of artificial intelligence technology, large models are increasingly used in the field of computer vision. Computer vision is a technology that simulates the human visual system and uses image processing, feature extraction, pattern recognition and other technical means to understand and analyze image content. Large models refer to deep learning models with a large number of model parameters and a huge amount of training data. Contours are useful tools for shape analysis and object detection and recognition, so a large number of contour point sets are required for large model training, which requires the use of contour point extraction technology.
当前,多数轮廓提取技术都是针对固定角度下的模型或图片进行轮廓点提取,例如,轮廓提取法、区域增长法等,这是因为它们都是对图片进行处理,而图片是提前拍摄好的,不能改变,那么轮廓提取技术就只能处理这一个角度的图片,导致最终得到的轮廓点数据较少,提取效率低,为此如何提高轮廓提取技术的提取效率的问题亟待解决。Currently, most contour extraction technologies are used to extract contour points from models or images at fixed angles, such as contour extraction method, region growing method, etc. This is because they all process images, and the images are taken in advance and cannot be changed. Therefore, contour extraction technology can only process images at this angle, resulting in less contour point data and low extraction efficiency. Therefore, the problem of how to improve the extraction efficiency of contour extraction technology needs to be solved urgently.
发明内容Summary of the invention
本申请实施例提供一种基于3D引擎的多角度轮廓点提取方法及存储介质,通过获取需要拍摄的物体的3D模型,接着,可以使用3D引擎摄像机对该3D模型进行拍摄,能实现360度无死角的拍摄,得到多个角度下该3D模型的图像,然后,对图像进行轮廓提取,能够得到大量的轮廓点数据,这大大提高了轮廓提取技术的提取效率。The embodiment of the present application provides a multi-angle contour point extraction method and storage medium based on a 3D engine. By obtaining a 3D model of an object to be photographed, a 3D engine camera can be used to photograph the 3D model, thereby achieving 360-degree shooting without blind spots, and obtaining images of the 3D model at multiple angles. Then, contours are extracted from the images to obtain a large amount of contour point data, which greatly improves the extraction efficiency of the contour extraction technology.
第一方面,本申请实施例提供了一种基于3D引擎的多角度轮廓点提取方法,所述方法包括:In a first aspect, an embodiment of the present application provides a multi-angle contour point extraction method based on a 3D engine, the method comprising:
获取目标模型;所述目标模型为3D模型;Acquire a target model; the target model is a 3D model;
确定所述目标模型对应的目标3D引擎以及目标3D引擎摄像机;Determine a target 3D engine and a target 3D engine camera corresponding to the target model;
通过所述目标3D引擎摄像机在目标拍摄角度下对所述目标模型进行拍摄,得到目标图像;所述目标拍摄角度为360度中的任一角度;The target model is photographed by the target 3D engine camera at a target shooting angle to obtain a target image; the target shooting angle is any angle in 360 degrees;
针对所述目标图像进行像素点遍历,找出其中的所有轮廓点,得到第一目标轮廓点集;Perform pixel traversal on the target image to find all contour points therein to obtain a first target contour point set;
根据目标递归算法对所述第一目标轮廓点集进行拆分,得到n个轮廓点集;n为大于或等于1的整数;The first target contour point set is split according to the target recursive algorithm to obtain n contour point sets; n is an integer greater than or equal to 1;
在n大于1时,对所述n个轮廓点集采用射线交叉法判断其内外轮廓,得到内外轮廓数据;所述内外轮廓数据包括所述n个轮廓点集中每一轮廓点集的轮廓属性;所述轮廓属性为内轮廓或外轮廓;When n is greater than 1, the inner and outer contours of the n contour point sets are determined by using a ray intersection method to obtain inner and outer contour data; the inner and outer contour data include contour attributes of each contour point set in the n contour point sets; the contour attribute is an inner contour or an outer contour;
基于格林公式计算所述n个轮廓点集中轮廓点构成的多边形的面积,得到n个面积数据;Calculate the area of the polygon formed by the contour points in the n contour point set based on Green's formula to obtain n area data;
对所述n个轮廓点集、所述内外轮廓数据和所述n个面积数据进行整合导出,得到目标轮廓点数据。The n contour point sets, the inner and outer contour data and the n area data are integrated and exported to obtain target contour point data.
第二方面,本申请实施例提供了一种计算机可读存储介质,其中,上述计算机可读存储介质存储用于电子数据交换的计算机程序,其中,上述计算机程序使得计算机执行如本申请实施例第一方面中所描述的部分或全部步骤。In a second aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program for electronic data exchange, wherein the computer program enables a computer to execute some or all of the steps described in the first aspect of the embodiment of the present application.
第三方面,本申请实施例提供一种电子设备,包括处理器、存储器、通信接口以及一个或多个程序,其中,上述一个或多个程序被存储在上述存储器中,并且被配置由上述处理器执行,上述程序包括用于执行本申请实施例第一方面中的步骤的指令。In a third aspect, an embodiment of the present application provides an electronic device, comprising a processor, a memory, a communication interface, and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the processor, and the program includes instructions for executing the steps in the first aspect of the embodiment of the present application.
第四方面,本申请实施例提供了一种计算机程序产品,其中,上述计算机程序产品包括存储了计算机程序的非瞬时性计算机可读存储介质,上述计算机程序可操作来使计算机执行如本申请实施例第一方面中所描述的部分或全部步骤。该计算机程序产品可以为一个软件安装包。In a fourth aspect, an embodiment of the present application provides a computer program product, wherein the computer program product includes a non-transitory computer-readable storage medium storing a computer program, and the computer program is operable to cause a computer to execute some or all of the steps described in the first aspect of the embodiment of the present application. The computer program product may be a software installation package.
可以看出,本申请实施例提供的基于3D引擎的多角度轮廓点提取方法,通过将目标3D引擎中的目标3D引擎摄像机对目标模型进行拍摄,可以实现360度无死角的拍摄目标模型,得到多个角度下目标模型的目标图像,然后,对该目标图像进行轮廓提取,能够得到大量的轮廓点数据,从而,提高了轮廓提取技术的提取效率。It can be seen that the multi-angle contour point extraction method based on the 3D engine provided in the embodiment of the present application can achieve 360-degree shooting of the target model without blind spots by shooting the target model with the target 3D engine camera in the target 3D engine, and obtain the target image of the target model at multiple angles. Then, the contour is extracted from the target image to obtain a large amount of contour point data, thereby improving the extraction efficiency of the contour extraction technology.
附图说明BRIEF DESCRIPTION OF THE DRAWINGS
为了更清楚地说明本申请实施例或背景技术中的技术方案,下面将对本申请实施例或背景技术中所需要使用的附图进行说明。In order to more clearly illustrate the technical solutions in the embodiments of the present application or the background technology, the drawings required for use in the embodiments of the present application or the background technology will be described below.
图1是本申请实施例提供的一种基于3D引擎的多角度轮廓点提取方法的流程示意图;FIG1 is a flow chart of a multi-angle contour point extraction method based on a 3D engine provided in an embodiment of the present application;
图2是本申请实施例提供的一种目标图像的示意图;FIG2 is a schematic diagram of a target image provided in an embodiment of the present application;
图3是本申请实施例提供的一种第一目标轮廓点集的示意图;FIG3 is a schematic diagram of a first target contour point set provided by an embodiment of the present application;
图4是本申请实施例提供的另一种第一目标轮廓点集的示意图;FIG4 is a schematic diagram of another first target contour point set provided by an embodiment of the present application;
图5是本申请实施例提供的一种交叉射线法的原理示意图;FIG5 is a schematic diagram of the principle of a cross-ray method provided in an embodiment of the present application;
图6是本申请实施例提供的一种打印弹窗的示意图;FIG6 is a schematic diagram of a print pop-up window provided in an embodiment of the present application;
图7是本申请实施例提供的一种电子设备的结构示意图。FIG. 7 is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application.
具体实施方式DETAILED DESCRIPTION
为了使本技术领域的人员更好地理解本申请方案,下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
本申请的说明书和权利要求书及上述附图中的术语“第一”、“第二”等是用于区别不同对象,而不是用于描述特定顺序。此外,术语“包括”和“具有”以及它们任何变形,意图在于覆盖不排他的包含。例如包含了一系列步骤或单元的过程、方法、系统、产品或设备没有限定于已列出的步骤或单元,而是可选地还包括没有列出的步骤或单元,或可选地还包括对于这些过程、方法、产品或设备固有的其他步骤或单元。The terms "first", "second", etc. in the specification and claims of this application and the above-mentioned drawings are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but optionally includes steps or units that are not listed, or optionally includes other steps or units inherent to these processes, methods, products or devices.
在本文中提及“实施例”意味着,结合实施例描述的特定特征、结构或特性可以包含在本申请的至少一个实施例中。在说明书中的各个位置出现该短语并不一定均是指相同的实施例,也不是与其它实施例互斥的独立的或备选的实施例。本领域技术人员显式地和隐式地理解的是,本文所描述的实施例可以与其它实施例相结合。Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
本申请实施例所描述的电子设备可以包括智能手机(如Android手机、iOS手机、Windows Phone手机等)、平板电脑、掌上电脑、笔记本电脑、视频矩阵、监控平台、移动互联网设备(mobile internet devices,MID)或穿戴式设备等,上述仅是举例,而非穷举,包含但不限于上述装置,当然,上述电子设备还可以为服务器,例如,云服务器。The electronic devices described in the embodiments of the present application may include smart phones (such as Android phones, iOS phones, Windows Phone phones, etc.), tablet computers, PDAs, laptops, video matrices, monitoring platforms, mobile Internet devices (mobile internet devices, MID) or wearable devices, etc. The above are only examples and not exhaustive, including but not limited to the above devices. Of course, the above electronic devices can also be servers, for example, cloud servers.
下面将对本申请中涉及的一些专业名词进行解释:The following is an explanation of some professional terms involved in this application:
3D引擎:简单来说,3D引擎是一种软件工具,用于创建和渲染图形三维。它允许开开发者创建虚拟世界,并通过计算机屏幕或其他设备呈现给用户。3D引擎能够管理和组织虚拟场景中的各个元素,包括物体、光照、摄像机等。3D引擎还可以利用高级图形算法将3D场景中的物体投射到二位屏幕上,以呈现逼真的视觉效果。3D Engine: In simple terms, a 3D engine is a software tool used to create and render graphics in three dimensions. It allows developers to create virtual worlds and present them to users through computer screens or other devices. The 3D engine is able to manage and organize the various elements in the virtual scene, including objects, lighting, cameras, etc. The 3D engine can also use advanced graphics algorithms to project objects in the 3D scene onto a two-dimensional screen to present realistic visual effects.
模型:本申请中涉及的模型指的是三维模型。三维模型是物体的多边形表示,通常用计算机或者其他视频设备进行显示。显示的物体可以是现实世界的实体,也可以是是虚构的物体。任何物理自然界存在的东西都可以用三维模型表现。在3D引擎中模型通常由网格和纹理贴图组成。Model: The model referred to in this application refers to a three-dimensional model. A three-dimensional model is a polygonal representation of an object, usually displayed by a computer or other video device. The displayed object can be a real-world entity or a fictional object. Anything that exists in the physical nature can be represented by a three-dimensional model. In a 3D engine, a model usually consists of a mesh and a texture map.
轮廓点:轮廓可以简单解释为连接具有相同颜色或强度的所有连续点(沿边界)的曲线多边形。轮廓是用于形状分析以及对象检测和识别的有用工具。轮廓点就是曲线多边形上的点集,通常用二维向量Vector2D(x,y)的列表来表示,轮廓点可以分为外轮廓点和内轮廓点。Contour points: Contours can be simply interpreted as curve polygons connecting all consecutive points (along the boundary) with the same color or intensity. Contours are useful tools for shape analysis and object detection and recognition. Contour points are a set of points on a curve polygon, usually represented by a list of two-dimensional vectors Vector2D (x, y). Contour points can be divided into outer contour points and inner contour points.
随着人工智能技术的不断发展,大模型在计算机视觉领域的应用越来越广泛。计算机视觉是一种模拟人类视觉系统的技术,通过图像处理、特征提取、模式识别等技术手段,实现对图像内容的理解和分析。而大模型则是指模型参数数量庞大、训练数据量巨大的深度学习模型。轮廓是用于形状分析以及对象检测和识别的有用工具,所以大量的轮廓点集是大模型训练所需要的,这就需要用到轮廓点提取技术。With the continuous development of artificial intelligence technology, large models are increasingly used in the field of computer vision. Computer vision is a technology that simulates the human visual system and uses image processing, feature extraction, pattern recognition and other technical means to understand and analyze image content. Large models refer to deep learning models with a large number of model parameters and a huge amount of training data. Contours are useful tools for shape analysis and object detection and recognition, so a large number of contour point sets are required for large model training, which requires the use of contour point extraction technology.
当前,多数轮廓提取技术都是针对固定角度下的模型或图片进行轮廓点提取,例如,轮廓提取法、区域增长法等,这是因为它们都是对图片进行处理,而图片是提前拍摄好的,不能改变,那么轮廓提取技术就只能处理这一个角度的图片,导致最终得到的轮廓点数据较少,提取效率低。Currently, most contour extraction technologies are used to extract contour points from models or images at fixed angles, such as contour extraction method and region growing method. This is because they all process images, and the images are taken in advance and cannot be changed. Therefore, contour extraction technology can only process images at this angle, resulting in less contour point data and low extraction efficiency.
为此,本申请提供一种基于3D引擎的多角度轮廓点提取方法及存储介质,通过获取需要拍摄的物体的3D模型,接着,可以使用3D引擎摄像机对该3D模型进行拍摄,能实现360度无死角的拍摄,得到多个角度下该3D模型的图像,然后,对图像进行轮廓提取,能够得到大量的轮廓点数据,这大大提高了轮廓提取技术的提取效率。To this end, the present application provides a multi-angle contour point extraction method and storage medium based on a 3D engine. By obtaining a 3D model of the object to be photographed, the 3D model can be photographed using a 3D engine camera, which can achieve 360-degree shooting without blind spots and obtain images of the 3D model at multiple angles. Then, contour extraction is performed on the image to obtain a large amount of contour point data, which greatly improves the extraction efficiency of the contour extraction technology.
请参阅图1,图1是本申请实施例提供的一种基于3D引擎的多角度轮廓点提取方法的流程示意图,所述方法包括但不限于以下步骤:Please refer to FIG. 1 , which is a flow chart of a multi-angle contour point extraction method based on a 3D engine provided in an embodiment of the present application. The method includes but is not limited to the following steps:
S101、获取目标模型;所述目标模型为3D模型。S101, obtaining a target model; the target model is a 3D model.
本申请实施例中,目标模型可以包括以下一种:人物模型、动物模型、物品模型等等,在此不做限定。In the embodiment of the present application, the target model may include one of the following: a person model, an animal model, an object model, etc., which is not limited here.
具体实施例中,可以先确定该目标模型提取的轮廓点数据将要用于哪种使用场景,得到目标使用场景,根据该目标使用场景选择目标模型,然后,可以通过3D建模软件设计制作模型,或者,也可以从网上的模型库中下载符合需求的模型,得到目标模型,例如,目标模型提取的轮廓点数据将要用于训练一种物体识别大模型,物体识别大模型需要的数据就是物品轮廓点数据,而非人物的轮廓点数据,那么目标模型就可以是物品模型,像是某个瓶子的3D模型。In a specific embodiment, it is possible to first determine in which usage scenario the contour point data extracted from the target model will be used to obtain the target usage scenario, select the target model according to the target usage scenario, and then design and produce the model through 3D modeling software, or download a model that meets the requirements from an online model library to obtain the target model. For example, the contour point data extracted from the target model will be used to train a large object recognition model. The data required by the large object recognition model is the contour point data of the object, not the contour point data of the person. In this case, the target model can be an object model, such as a 3D model of a bottle.
S102、确定所述目标模型对应的目标3D引擎以及目标3D引擎摄像机。S102: Determine a target 3D engine and a target 3D engine camera corresponding to the target model.
本申请实施例中,目标3D引擎可以包括以下至少一种:Unity、Unreal Engine、Cocos Creato等等,在此不做限定;目标3D引擎可以包括目标3D引擎摄像机。In the embodiment of the present application, the target 3D engine may include at least one of the following: Unity, Unreal Engine, Cocos Creato, etc., which are not limited here; the target 3D engine may include a target 3D engine camera.
具体实施例中,可以根据目标模型的复杂程度来选择不同的3D引擎,例如,假设目标模型为汽车模型,汽车模型是一种比较复杂的模型,因为汽车本身就是一个复杂的物体,要想让目标模型更好的模拟出真实汽车的样子,就需要选择渲染效果好的3D引擎,那么,目标3D引擎可以为Unity 3D引擎,接着,由于Unity 3D引擎中一般自带摄像机组件,可以将该摄像机组件作为目标3D引擎摄像机,或者,也可以从外部添加摄像机组件作为目标3D引擎摄像机。In a specific embodiment, different 3D engines can be selected according to the complexity of the target model. For example, assuming that the target model is a car model, the car model is a relatively complex model because the car itself is a complex object. In order to make the target model better simulate the appearance of a real car, it is necessary to select a 3D engine with good rendering effect. Then, the target 3D engine can be the Unity 3D engine. Then, since the Unity 3D engine generally has its own camera component, the camera component can be used as the target 3D engine camera, or a camera component can be added from the outside as the target 3D engine camera.
需要解释的是,上文所描述的选择3D引擎的方法只是一种方法,实际应用中还可采用其他方法,例如,根据目标模型在3D引擎中模拟的成本大小来选择合适的3D引擎等,在此不再赘述。It should be explained that the method of selecting a 3D engine described above is only one method. Other methods can also be used in actual applications, for example, selecting a suitable 3D engine based on the cost of simulating the target model in the 3D engine, etc., which will not be repeated here.
S103、通过所述目标3D引擎摄像机在目标拍摄角度下对所述目标模型进行拍摄,得到目标图像;所述目标拍摄角度为360度中的任一角度。S103, photographing the target model at a target shooting angle through the target 3D engine camera to obtain a target image; the target shooting angle is any angle within 360 degrees.
本申请实施例中,可以先确定目标拍摄角度,再通过目标3D引擎摄像机拍摄目标模型在目标拍摄角度的图像,得到目标图像。In the embodiment of the present application, the target shooting angle can be determined first, and then the image of the target model at the target shooting angle is captured by the target 3D engine camera to obtain the target image.
可选的,步骤S103,所述通过所述目标3D引擎摄像机在目标拍摄角度下对所述目标模型进行拍摄,得到目标图像,可以包括如下步骤:Optionally, step S103, photographing the target model at a target shooting angle by the target 3D engine camera to obtain a target image, may include the following steps:
31、将所述目标模型导入所述目标3D引擎,并将所述目标模型放置于所述目标3D引擎中的预设场景中;31. Importing the target model into the target 3D engine, and placing the target model in a preset scene in the target 3D engine;
32、确定所述目标3D引擎摄像机针对所述目标模型的初始角度;32. Determine the initial angle of the target 3D engine camera relative to the target model;
33、获取目标对象的目标需求数据;33. Obtain target demand data of target objects;
34、根据所述目标需求数据确定所述目标拍摄角度;34. Determine the target shooting angle according to the target requirement data;
35、基于所述目标拍摄角度和所述初始角度确定所述目标模型的目标调节参数;35. Determine a target adjustment parameter of the target model based on the target shooting angle and the initial angle;
36、根据所述目标调节参数对所述目标模型的位置进行调节,以使所述目标模型处于所述目标拍摄角度;36. Adjust the position of the target model according to the target adjustment parameter so that the target model is at the target shooting angle;
37、将所述目标模型的纹理贴图修改为预设颜色,确定所述目标模型在所述目标3D引擎中所处的目标层级;37. Modify the texture map of the target model to a preset color, and determine the target level of the target model in the target 3D engine;
38、根据所述目标层级调节所述目标3D引擎摄像机的初始拍摄层级参数,得到目标拍摄层级参数;38. Adjust the initial shooting level parameters of the target 3D engine camera according to the target level to obtain target shooting level parameters;
39、通过所述目标拍摄层级参数的所述目标3D引擎摄像机对处于所述目标拍摄角度下的所述目标模型进行拍摄,得到所述目标图像。39. Shoot the target model at the target shooting angle using the target 3D engine camera with the target shooting level parameter to obtain the target image.
本申请实施例中,预设场景和预设颜色均可以为提前预设或默认;目标需求数据可以包括以下至少一种:用户的偏好数据、训练大模型的需求数据等等,在此不做限定;目标调节参数可以包括以下至少一种:旋转矩阵参数、平移向量参数等等,在此不做限定。In the embodiments of the present application, the preset scenes and preset colors can be preset or defaulted in advance; the target requirement data may include at least one of the following: user preference data, requirement data for training large models, etc., which are not limited here; the target adjustment parameters may include at least one of the following: rotation matrix parameters, translation vector parameters, etc., which are not limited here.
具体实施例中,可以先将目标模型导入目标3D引擎,并将目标模型放置于目标3D引擎中的预设场景中,具体的,可以是通过目标3D引擎的导入功能将目标模型加载到引擎中,然后,可以在引擎中找出或创建出上述预设场景,将目标模型放置到预设场景中的合适位置(例如,场景中心位置),使用目标3D引擎摄像机能够拍到目标模型的全貌。In a specific embodiment, the target model can be first imported into the target 3D engine, and the target model can be placed in a preset scene in the target 3D engine. Specifically, the target model can be loaded into the engine through the import function of the target 3D engine, and then the above-mentioned preset scene can be found or created in the engine, and the target model can be placed in a suitable position in the preset scene (for example, the center of the scene), and the target 3D engine camera can be used to capture the full view of the target model.
需要解释的是,为了使目标3D引擎摄像机的拍摄效果更好,一般情况下,预设场景为空场景,空场景就是除了需要拍摄的目标模型之外,没有其他内容或元素的场景。It needs to be explained that in order to make the shooting effect of the target 3D engine camera better, in general, the preset scene is an empty scene. The empty scene is a scene with no other content or elements except the target model to be shot.
接着,可以确定目标3D引擎摄像机针对目标模型的初始角度,具体的,可以先获取目标模型在目标3D引擎中的第一位置,以及目标3D引擎摄像机在目标3D引擎中的第二位置,然后,根据上述第一位置和第二位置即可确定上述初始角度;进一步的,可以获取目标对象的目标需求数据;根据目标需求数据确定目标拍摄角度,具体的,目标需求数据可以是用户手动导入到目标3D引擎的需求数据,目标需求数据可以为训练大模型的需求数据,然后,可以根据目标需求数据确定目标3D引擎摄像机需要从哪些角度进行拍摄,也即目标拍摄角度,例如,假设这个大模型是物体识别大模型,要想对它进行训练,一般需要物体的正面视角的物体数据,那么,目标拍摄角度可以为正面视角。Next, the initial angle of the target 3D engine camera with respect to the target model can be determined. Specifically, the first position of the target model in the target 3D engine and the second position of the target 3D engine camera in the target 3D engine can be obtained first, and then the initial angle can be determined based on the first position and the second position. Further, the target requirement data of the target object can be obtained; the target shooting angle can be determined based on the target requirement data. Specifically, the target requirement data can be requirement data manually imported into the target 3D engine by a user, and the target requirement data can be requirement data for training a large model. Then, the target 3D engine camera can be determined based on the target requirement data to determine the angles from which the target 3D engine camera needs to shoot, that is, the target shooting angle. For example, assuming that the large model is an object recognition large model, in order to train it, object data of the front view of the object is generally required, and then the target shooting angle can be the front view.
进一步的,可以基于目标拍摄角度和初始角度确定目标模型的目标调节参数,具体的,可以确定目标拍摄角度和初始角度相差多少角度,得到目标角度差,可以预先存储预设的角度差与调节参数之间的映射关系,基于该映射关系确定目标角度差对应的目标调节参数,然后,可以根据目标调节参数对目标模型的位置进行调节,以使目标模型处于目标拍摄角度。Furthermore, target adjustment parameters of the target model can be determined based on the target shooting angle and the initial angle. Specifically, the difference between the target shooting angle and the initial angle can be determined to obtain the target angle difference. The mapping relationship between the preset angle difference and the adjustment parameter can be pre-stored, and the target adjustment parameters corresponding to the target angle difference can be determined based on the mapping relationship. Then, the position of the target model can be adjusted according to the target adjustment parameters so that the target model is at the target shooting angle.
需要解释的是,上文描述的是对目标模型的位置进行调节,实际应用中,还可以调节目标3D引擎摄像机的位置。It should be explained that the above description is about adjusting the position of the target model. In practical applications, the position of the target 3D engine camera can also be adjusted.
接着,可以将目标模型的纹理贴图修改为预设颜色,确定目标模型在目标3D引擎中所处的目标层级,具体的,可以通过目标3D引擎的纹理编辑器对目标模型进行编辑,将目标模型的纹理贴图修改为预设颜色,该预设颜色可以是预先设置或默认的,例如,预设颜色可以默认为黑色,接着,可以在目标3D引擎中找出层级管理组件,从所述层级管理组件查看上述目标模型所处的层级,得到目标层级,进一步的,可以根据目标层级调节目标3D引擎摄像机的初始拍摄层级参数,得到目标拍摄层级参数,具体的,可以将目标3D引擎摄像机的初始拍摄层级参数调节为与目标层级相对应的拍摄层级,得到目标拍摄层级参数,如此,目标3D引擎摄像机就可以只拍摄目标模型所处的层级的照片了,排除其他层级的干扰。Next, the texture map of the target model can be modified to a preset color, and the target level of the target model in the target 3D engine can be determined. Specifically, the target model can be edited through the texture editor of the target 3D engine, and the texture map of the target model can be modified to a preset color, which can be pre-set or default. For example, the preset color can be black by default. Next, the level management component can be found in the target 3D engine, and the level of the target model can be viewed from the level management component to obtain the target level. Further, the initial shooting level parameters of the target 3D engine camera can be adjusted according to the target level to obtain the target shooting level parameters. Specifically, the initial shooting level parameters of the target 3D engine camera can be adjusted to a shooting level corresponding to the target level to obtain the target shooting level parameters. In this way, the target 3D engine camera can only take pictures of the level where the target model is located, eliminating interference from other levels.
最后,可以通过目标拍摄层级参数的目标3D引擎摄像机对处于目标拍摄角度下的目标模型进行拍摄,得到目标图像。Finally, the target model at the target shooting angle can be photographed by the target 3D engine camera of the target shooting level parameter to obtain the target image.
举个例子说明下,请参阅图2,图2是本申请实施例提供的一种目标图像的示意图,假设目标模型为一个瓶罐,那么将该目标模型放置于预设场景(空场景)中,进行拍摄,得到的目标图像如图2中所示,该目标图像中仅包含一个黑色瓶罐,其余部分均为空白颜色,这就是空场景。To give an example, please refer to Figure 2, which is a schematic diagram of a target image provided in an embodiment of the present application. Assuming that the target model is a bottle, the target model is placed in a preset scene (empty scene) and photographed. The obtained target image is shown in Figure 2. The target image only contains a black bottle, and the rest are blank colors. This is the empty scene.
需要解释的是,上述目标图像的像素可以为固定像素,也就是说,不管在何种情况下,该像素的颜色值都是不会改变的,也即目标图像不会因为光照变化、图像旋转、缩放或其他图像处理操作而改变其固有的颜色。It should be explained that the pixels of the above-mentioned target image can be fixed pixels, that is, the color value of the pixel will not change under any circumstances, that is, the target image will not change its inherent color due to lighting changes, image rotation, scaling or other image processing operations.
如此,通过将目标模型导入目标3D引擎,并将目标模型放置于预设场景中;确定目标3D引擎摄像机针对目标模型的初始角度;获取目标对象的目标需求数据;根据目标需求数据确定目标拍摄角度;基于目标拍摄角度和初始角度确定目标模型的目标调节参数;根据目标调节参数对目标模型的位置进行调节,以使目标模型处于目标拍摄角度;将目标模型的纹理贴图修改为预设颜色,确定目标模型在目标3D引擎中所处的目标层级;根据目标层级调节目标3D引擎摄像机的初始拍摄层级参数,得到目标拍摄层级参数;通过目标拍摄层级参数的目标3D引擎摄像机对处于目标拍摄角度下的目标模型进行拍摄,得到目标图像,一方面,通过精确确定角度和调节目标模型位置,可以确保目标模型以最符合需求的角度被拍摄,从而准确呈现某些特定特征或状态,得到更有针对性的目标图像,另一方面,通过明确模型在目标3D引擎中的层级,并相应地调整摄像机的初始拍摄层级参数,有助于合理安排场景中元素的层次关系,避免遮挡或混乱,使拍摄结果更具层次感。In this way, the target model is imported into the target 3D engine and placed in the preset scene; the initial angle of the target 3D engine camera for the target model is determined; the target requirement data of the target object is obtained; the target shooting angle is determined according to the target requirement data; the target adjustment parameters of the target model are determined based on the target shooting angle and the initial angle; the position of the target model is adjusted according to the target adjustment parameters so that the target model is at the target shooting angle; the texture map of the target model is modified to a preset color, and the target level of the target model in the target 3D engine is determined; the initial shooting angle of the target 3D engine camera is adjusted according to the target level hierarchical parameters, and obtain target shooting hierarchical parameters; the target model at the target shooting angle is photographed by the target 3D engine camera with the target shooting hierarchical parameters to obtain the target image. On the one hand, by accurately determining the angle and adjusting the position of the target model, it can be ensured that the target model is photographed at the angle that best meets the requirements, thereby accurately presenting certain specific features or states and obtaining a more targeted target image. On the other hand, by clarifying the hierarchy of the model in the target 3D engine and adjusting the initial shooting hierarchy parameters of the camera accordingly, it is helpful to reasonably arrange the hierarchical relationship of the elements in the scene, avoid occlusion or confusion, and make the shooting result more hierarchical.
S104、针对所述目标图像进行像素点遍历,找出其中的所有轮廓点,得到第一目标轮廓点集。S104 , performing pixel traversal on the target image to find all contour points therein and obtain a first target contour point set.
本申请实施例中,可以针对目标图像进行像素点遍历,对该目标图像中的每一个像素点都进行一次轮廓点判断,这样可以找出其中的所有轮廓点,得到第一目标轮廓点集。In the embodiment of the present application, pixel traversal can be performed on the target image, and contour point judgment can be performed once for each pixel in the target image, so that all contour points therein can be found to obtain a first target contour point set.
可选的,步骤104,所述针对所述目标图像进行像素点遍历,找出其中的所有轮廓点,得到第一目标轮廓点集,可以包括如下步骤:Optionally, step 104, traversing pixels of the target image to find all contour points therein to obtain a first target contour point set, may include the following steps:
步骤A1:获取所述目标图像中的第一像素点;Step A1: Acquire a first pixel point in the target image;
步骤A2:确定所述第一像素点周围的i个像素点;i为2、4、8中的任一数字;Step A2: determining i pixel points around the first pixel point; i is any number among 2, 4, and 8;
步骤A3:将所述第一像素点与所述i个像素点中每一像素点进行颜色比较,得到与所述第一像素点颜色不同的j个像素点;j为小于或等于i的自然数;Step A3: Compare the colors of the first pixel with each of the i pixel points to obtain j pixel points with different colors from the first pixel point; j is a natural number less than or equal to i;
步骤A4:在所述j个像素点大于指定值个点时,判断所述第一像素点为轮廓点,将所述第一像素点加入到初始轮廓点集中;所述初始轮廓点集初始为以0起始的空列表;Step A4: when the j pixel points are greater than a specified value, the first pixel point is determined to be a contour point, and the first pixel point is added to an initial contour point set; the initial contour point set is initially an empty list starting with 0;
基于预设遍历算法从所述第一像素点开始遍历所述目标图像中的像素点,每遍历一个像素点均重复一次上述步骤A1-A4,直到将所述目标图像遍历完成,得到所述第一目标轮廓点集。Based on a preset traversal algorithm, pixel points in the target image are traversed starting from the first pixel point, and the above steps A1-A4 are repeated each time a pixel point is traversed until the target image is completely traversed to obtain the first target contour point set.
本申请实施例中,指定值个点可以为提前预设或默认。In the embodiment of the present application, the designated value points may be preset or defaulted.
具体实施例中,可以先获取目标图像中的第一像素点,具体的,可以将该目标图像转化为像素矩阵,这个第一像素点可以为目标图像中固定位置上的像素点,例如,可以将上述目标图像左上角顶部的像素点作为第一像素点(0,0),接着,可以确定第一像素点周围的i个像素点,根据i的大小不同获取的点也不同,例如,i为2时,第一像素点周围的i个像素点可以为点一(0,1)和点二(1,0),接着,可以将第一像素点与i个像素点中每一像素点进行颜色比较,得到与第一像素点颜色不同的j个像素点。In a specific embodiment, the first pixel point in the target image can be obtained first. Specifically, the target image can be converted into a pixel matrix. The first pixel point can be a pixel point at a fixed position in the target image. For example, the pixel point at the top of the upper left corner of the target image can be used as the first pixel point (0,0). Then, i pixel points around the first pixel point can be determined. The points obtained are different depending on the size of i. For example, when i is 2, the i pixel points around the first pixel point can be point one (0,1) and point two (1,0). Then, the color of the first pixel point can be compared with each of the i pixel points to obtain j pixel points with a different color from the first pixel point.
进一步的,可以在j个像素点大于指定值个点时,将该第一像素点确定为轮廓点,将第一像素点加入到初始轮廓点集中,具体的,可以是将第一像素点的坐标加入到初始轮廓点集中,也即初始轮廓点集是一个二维列表。Furthermore, when the number of j pixel points is greater than a specified value, the first pixel point can be determined as a contour point, and the first pixel point can be added to the initial contour point set. Specifically, the coordinates of the first pixel point can be added to the initial contour point set, that is, the initial contour point set is a two-dimensional list.
最后,可以基于预设遍历算法从第一像素点开始遍历目标图像中的像素点,每遍历一个像素点均重复一次上述步骤A1-A4,直到将目标图像遍历完成,得到第一目标轮廓点集,具体的,预设遍历算法可以为“按行优先遍历”,对上述目标图像逐行逐列的遍历像素点,并且,对每个像素点进行一次判断是否为轮廓点,得到上述目标图像中的所有轮廓点,也即第一目标轮廓点集。Finally, the pixel points in the target image can be traversed starting from the first pixel point based on the preset traversal algorithm, and the above steps A1-A4 are repeated each time a pixel point is traversed until the target image is traversed and the first target contour point set is obtained. Specifically, the preset traversal algorithm can be "row-first traversal", traversing the pixel points of the above target image row by row and column by column, and determining whether each pixel point is a contour point, to obtain all contour points in the above target image, that is, the first target contour point set.
可选的,上述步骤A3,所述将所述第一像素点与所述i个像素点中每一像素点进行颜色比较,得到与所述第一像素点颜色不同的j个像素点,可以包括如下步骤:Optionally, the above step A3, comparing the color of the first pixel with each of the i pixel points to obtain j pixel points having a different color from the first pixel point, may include the following steps:
A31、获取所述第一像素点的RGBA颜色值,得到第一RGBA值;A31. Obtain the RGBA color value of the first pixel to obtain a first RGBA value;
A32、根据所述第一RGBA值确定所述第一像素点的颜色归属,得到第一颜色归属;A32. Determine the color attribution of the first pixel according to the first RGBA value to obtain a first color attribution;
A33、获取所述i个像素点中每一像素点的RGBA颜色值,得到i个RGBA值;A33, obtaining the RGBA color value of each pixel in the i pixels, to obtain i RGBA values;
A34、根据所述i个RGBA值确定所述i个像素点中每一像素点的颜色归属,得到i个颜色归属;A34, determining the color attribution of each pixel in the i pixels according to the i RGBA values, to obtain i color attributions;
A35、将所述i个颜色归属依次与所述第一颜色归属进行比较,得到与所述第一颜色归属不同的j个颜色归属;A35, comparing the i color attributions with the first color attribution in sequence, to obtain j color attributions different from the first color attribution;
A36、确定所述j个颜色归属对应的所述j个像素点。A36. Determine the j pixel points corresponding to the j colors.
本申请实施例中,RGBA颜色值是一种颜色模型,用于表示在计算机图形和图像处理中的颜色,其中,R表示红色通道、G表示绿色通道、B表示蓝色通道、A表示透明通道,取值范围为0~255;颜色归属可以包括以下一种:红色、绿色、蓝色、黑色等等,在此不做限定。In the embodiment of the present application, the RGBA color value is a color model used to represent colors in computer graphics and image processing, wherein R represents the red channel, G represents the green channel, B represents the blue channel, and A represents the transparent channel, with a value range of 0 to 255; color attribution may include one of the following: red, green, blue, black, etc., which is not limited here.
具体实施例中,可以先获取第一像素点的RGBA颜色值,得到第一RGBA值;根据第一RGBA值确定第一像素点的颜色归属,得到第一颜色归属,具体的,可以通过图像处理库(例如,Python中的Pillow库)对上述第一像素点进行处理,根据上述图像处理库找出与该第一像素点对应的RGBA颜色值,得到第一RGBA值,然后,可以对该第一RGBA值进行归类,具体的,可以采用“阈值法”,为每一种颜色都设置一个RGBA范围的阈值,判断上述第一RGBA值处于哪一个范围内,将该范围对应的颜色确定为上述第一像素点的颜色归属,得到第一颜色归属,例如,假设黑色的RGBA范围为A通道值大于100,并且,其他通道的值均小于100,第一RGBA值为(0,0,0,255),显然,第一RGBA值处于黑色的阈值范围内,也即第一颜色归属为黑色。In a specific embodiment, the RGBA color value of the first pixel may be first obtained to obtain a first RGBA value; the color attribution of the first pixel may be determined according to the first RGBA value to obtain the first color attribution. Specifically, the first pixel may be processed by an image processing library (for example, the Pillow library in Python), and the RGBA color value corresponding to the first pixel may be found according to the image processing library to obtain the first RGBA value. Then, the first RGBA value may be classified. Specifically, a "threshold method" may be used to set a threshold of an RGBA range for each color, determine within which range the first RGBA value is, determine the color corresponding to the range as the color attribution of the first pixel, and obtain the first color attribution. For example, assuming that the RGBA range of black is that the A channel value is greater than 100, and the values of other channels are all less than 100, and the first RGBA value is (0, 0, 0, 255), it is obvious that the first RGBA value is within the threshold range of black, that is, the first color attribution is black.
需要解释的是,上述所描述的“阈值法”只是本申请提供了一种判断颜色归属的方法,实际应用中,还可以为其他方法,例如,“颜色对比法”,可以建立一个颜色库,将像素点的RGBA值与颜色表进行比对,从而,确定其颜色归属。It should be explained that the "threshold method" described above is only a method for determining color ownership provided by this application. In practical applications, other methods can also be used. For example, the "color contrast method" can establish a color library and compare the RGBA value of the pixel with the color table to determine its color ownership.
进一步的,可以获取i个像素点中每一像素点的RGBA颜色值,得到i个RGBA值;根据i个RGBA值确定i个像素点中每一像素点的颜色归属,得到i个颜色归属;同样的,获取这i个RGBA值和i个颜色归属的方法可以与上文所描述的获取方法相同;接着,可以将i个颜色归属依次与第一颜色归属进行比较,得到与第一颜色归属不同的j个颜色归属,然后,可以确定这j个颜色归属对应的j个像素点。Furthermore, the RGBA color value of each pixel in the i pixels can be obtained to obtain i RGBA values; the color attribution of each pixel in the i pixels can be determined according to the i RGBA values to obtain i color attributions; similarly, the method for obtaining the i RGBA values and the i color attributions can be the same as the acquisition method described above; then, the i color attributions can be compared with the first color attribution in turn to obtain j color attributions different from the first color attribution, and then, the j pixels corresponding to the j color attributions can be determined.
需要解释的是,在某些极端情况下,整个目标图像中都没有找到不同的颜色归属的点,也即目标图像中的点都是相同的颜色归属,则判断该图片没有轮廓,需要重新换一个角度进行下一次拍摄。It should be explained that, in some extreme cases, no points with different color attributes are found in the entire target image, that is, all points in the target image have the same color attribute, then it is determined that the image has no contour and it is necessary to change the angle for the next shot.
如此,通过获取第一像素点的RGBA颜色值,得到第一RGBA值;根据第一RGBA值确定第一像素点的颜色归属,得到第一颜色归属;获取i个像素点中每一像素点的RGBA颜色值,得到i个RGBA值;根据i个RGBA值确定i个像素点中每一像素点的颜色归属,得到i个颜色归属;将i个颜色归属依次与第一颜色归属进行比较,得到与第一颜色归属不同的j个颜色归属;确定j个颜色归属对应的j个像素点,若j个像素点大于指定值个点时,判断第一像素点为轮廓点,一方面,通过比较上述j个像素点的RGBA值与第一像素点的RGBA值之间的差异,可以准确地判断出哪些像素点与第一像素点颜色不同,从而,确定轮廓点,另一方面,通过比较多个像素点的颜色归属,可以减少由于单个像素点的噪声或异常导致的误判,提高轮廓识别的准确性。In this way, the first RGBA value is obtained by obtaining the RGBA color value of the first pixel; the color attribution of the first pixel is determined according to the first RGBA value to obtain the first color attribution; the RGBA color value of each pixel in i pixels is obtained to obtain i RGBA values; the color attribution of each pixel in i pixels is determined according to the i RGBA values to obtain i color attributions; the i color attributions are compared with the first color attribution in turn to obtain j color attributions different from the first color attribution; j pixels corresponding to the j color attributions are determined, and if the j pixels are greater than a specified value, the first pixel is judged to be a contour point. On the one hand, by comparing the difference between the RGBA values of the above j pixels and the RGBA value of the first pixel, it is possible to accurately determine which pixels are different in color from the first pixel, thereby determining the contour point. On the other hand, by comparing the color attributions of multiple pixels, it is possible to reduce misjudgments caused by noise or abnormality of a single pixel, thereby improving the accuracy of contour recognition.
S105、根据目标递归算法对所述第一目标轮廓点集进行拆分,得到n个轮廓点集;n为大于或等于1的整数。S105 . Split the first target contour point set according to a target recursive algorithm to obtain n contour point sets; n is an integer greater than or equal to 1.
本申请实施例中,目标递归算法可以为预先设置或默认。In the embodiment of the present application, the target recursive algorithm may be preset or default.
具体实施例中,可以根据目标递归算法对上述第一目标轮廓点集进行拆分,得到n个轮廓点集。In a specific embodiment, the first target contour point set may be split according to a target recursive algorithm to obtain n contour point sets.
举个例子说明下,请参阅图3,图3是本申请实施例提供的一种第一目标轮廓点集的示意图,可以看出,图3中的第一目标轮廓点集300构成的图形为一个圆形,颜色为黑色,其中,点31为第一目标轮廓点集300中的一个轮廓点。To give an example, please refer to Figure 3, which is a schematic diagram of a first target contour point set provided in an embodiment of the present application. It can be seen that the figure formed by the first target contour point set 300 in Figure 3 is a circle, the color is black, wherein point 31 is a contour point in the first target contour point set 300.
需要解释的是,第一目标轮廓点集300仅包括图3中的圆形边缘上的点,圆形内部是不属于轮廓点的。It should be explained that the first target contour point set 300 only includes points on the edge of the circle in FIG. 3 , and the points inside the circle are not contour points.
又例如,请参阅图4,图4是本申请实施例提供的另一种第一目标轮廓点集的示意图,可以看出,图3中的第一目标轮廓点集300构成的图形为一个圆形41和一个三角形42,圆形41的颜色为黑色,三角形42的颜色为白色;这说明第一目标轮廓点集300它其实是包含了圆形41和三角形42两个部分的轮廓点集,那么在下文中的拆分过程中,第一目标轮廓点集300可以拆分出两个轮廓点集,以此类推,可以得知其他不同的点集能够拆分出多少个轮廓点集。For another example, please refer to Figure 4, which is a schematic diagram of another first target contour point set provided in an embodiment of the present application. It can be seen that the figure composed of the first target contour point set 300 in Figure 3 is a circle 41 and a triangle 42, the color of the circle 41 is black, and the color of the triangle 42 is white; this shows that the first target contour point set 300 is actually a contour point set containing two parts, the circle 41 and the triangle 42. Then, in the splitting process below, the first target contour point set 300 can be split into two contour point sets, and so on, it can be known how many contour point sets can be split into other different point sets.
需要解释的是,第一目标轮廓点集300仅包括:圆形41的外边缘上的点、三角形42的外边缘上的点,圆形41和三角形42的内部是不属于轮廓点的。It should be explained that the first target contour point set 300 only includes points on the outer edge of the circle 41 and the outer edge of the triangle 42 , and the interior of the circle 41 and the triangle 42 are not contour points.
可选的,步骤S105,所述第一目标轮廓点集包括m个点;m为大于或等于n的正整数;所述根据目标递归算法对所述第一目标轮廓点集进行拆分,得到n个轮廓点集,包括:Optionally, in step S105, the first target contour point set includes m points; m is a positive integer greater than or equal to n; the first target contour point set is split according to the target recursive algorithm to obtain n contour point sets, including:
步骤B1:获取所述第一目标轮廓点集中顺序排在第一的轮廓点,得到点p;Step B1: obtaining the contour point ranked first in the first target contour point set, and obtaining point p;
步骤B2:计算所述点p与所述第一目标轮廓点集中除了所述点p之外的所有点之间的距离,得到m-1个距离;Step B2: Calculate the distances between the point p and all points in the first target contour point set except the point p to obtain m-1 distances;
步骤B3:若所述m-1个距离均小于预设距离,则将所述点p从所述第一目标轮廓点集中除去,将所述点p加入新的点集,得到第一轮廓点集LP1;所述第一轮廓点集LP1为所述n个轮廓点集中的一个;Step B3: if the m-1 distances are all less than the preset distance, the point p is removed from the first target contour point set, and the point p is added to a new point set to obtain a first contour point set LP1; the first contour point set LP1 is one of the n contour point sets;
步骤B4:按所述第一目标轮廓点集的列表顺序对其中除了点p之外的其他点均重复上述步骤B1-B3,重复m-1次,以得到最终的所述第一轮廓点集LP1,以及所述第一目标轮廓点集拆分出所述第一轮廓点集LP1之后的第二目标轮廓点集;Step B4: repeating the above steps B1-B3 for all points except point p in the list order of the first target contour point set, repeating m-1 times, to obtain the final first contour point set LP1, and the second target contour point set after the first contour point set LP1 is split from the first target contour point set;
若所述第二目标轮廓点集中的轮廓点数量大于3,则按上述B1-B4步骤继续对所述第二目标轮廓点集进行拆分,直到所述第二目标轮廓点集中的点被取完或剩余点个数小于3,以得到所述n个轮廓点集。If the number of contour points in the second target contour point set is greater than 3, the second target contour point set is split according to the above steps B1-B4 until all the points in the second target contour point set are taken or the number of remaining points is less than 3, so as to obtain the n contour point sets.
本申请实施例中,预设距离可以为提前预设或默认;预设距离通常为两个不连续点的距离,为固定值根号2,例如,(0,1)到(1,0)的距离,根号2。In the embodiment of the present application, the preset distance may be pre-set or default; the preset distance is usually the distance between two discontinuous points, which is a fixed value square root of 2, for example, the distance from (0, 1) to (1, 0), square root of 2.
具体实施例中,可以先获取第一目标轮廓点集中顺序排在第一的轮廓点,得到点p,具体的,因为第一目标轮廓点集是一个列表,列表是有顺序的,可以从该列表中找出点p,接着,可以计算点p与第一目标轮廓点集中除了点p之外的所有点之间的距离,得到m-1个距离,具体的,可以或点p及其他点的坐标,得到点p坐标(x1,y1),可以根据两点之间的距离计算公式进行计算:In a specific embodiment, the contour point ranked first in the first target contour point set can be obtained to obtain point p. Specifically, because the first target contour point set is a list, the list is ordered, and point p can be found from the list. Then, the distance between point p and all points in the first target contour point set except point p can be calculated to obtain m-1 distances. Specifically, the coordinates of point p and other points can be obtained to obtain the coordinates of point p (x1, y1), which can be calculated according to the distance calculation formula between two points:
其中,d为m-1个距离中的任一个距离;坐标(x2,y2)为第一目标轮廓点集中除了点p之外的任一点;可以根据上述公式计算m-1次,得到m-1个距离。接着,判断这m-1个距离与预设距离之间的大小关系,若这m-1个距离均小于预设距离,说明该点为连续点集中的一个,则将点p从第一目标轮廓点集中除去,将点p加入新的点集,得到第一轮廓点集LP1,反之,若这m-1个距离不全小于预设距离,则将该点p继续保留在上述第一目标轮廓点集中。Among them, d is any distance among m-1 distances; coordinates (x2, y2) are any point in the first target contour point set except point p; m-1 distances can be calculated m-1 times according to the above formula to obtain m-1 distances. Then, the size relationship between these m-1 distances and the preset distance is determined. If these m-1 distances are all less than the preset distance, it means that the point is one of the continuous point sets, then point p is removed from the first target contour point set, and point p is added to the new point set to obtain the first contour point set LP1. On the contrary, if these m-1 distances are not all less than the preset distance, then point p is retained in the above first target contour point set.
进一步的,可以按第一目标轮廓点集的列表顺序对其中除了点p之外的其他点均重复上述步骤B1-B3,重复m-1次,每次重复,均将符合条件(即点与其余点之间的距离均小于预设距离)的点加入到第一轮廓点集LP1中,以得到最终的第一轮廓点集LP1,以及第一目标轮廓点集拆分出第一轮廓点集LP1之后的第二目标轮廓点集;Further, the above steps B1-B3 can be repeated for all points except point p in the list order of the first target contour point set, and repeated m-1 times. In each repetition, points that meet the conditions (i.e., the distances between the points and the other points are less than the preset distances) are added to the first contour point set LP1 to obtain the final first contour point set LP1, and the second target contour point set after the first contour point set LP1 is split from the first target contour point set;
需要解释的是,上文中的m指的是第一目标轮廓点集中包含的点的个数,随着拆分过程的进行,m也会随之变化。It should be explained that m in the above text refers to the number of points included in the first target contour point set, and m will change as the splitting process proceeds.
若第二目标轮廓点集中的轮廓点数量大于3,因为3个点可以形成一个最简单的多边形,所以还可以按上述B1-B4步骤继续对该第二目标轮廓点集进行拆分,每拆分一次,可以得到一个新的轮廓点集,直到第二目标轮廓点集中的点被取完或剩余点个数小于3,以得到n个轮廓点集。If the number of contour points in the second target contour point set is greater than 3, since 3 points can form a simplest polygon, the second target contour point set can be further split according to the above steps B1-B4. Each time the split is performed, a new contour point set can be obtained until all the points in the second target contour point set are taken or the number of remaining points is less than 3, so as to obtain n contour point sets.
S106、在n大于1时,对所述n个轮廓点集采用射线交叉法判断其内外轮廓,得到内外轮廓数据;所述内外轮廓数据包括所述n个轮廓点集中每一轮廓点集的轮廓属性;所述轮廓属性为内轮廓或外轮廓。S106. When n is greater than 1, the inner and outer contours of the n contour point sets are determined by using a ray intersection method to obtain inner and outer contour data; the inner and outer contour data include contour attributes of each contour point set in the n contour point sets; the contour attributes are inner contour or outer contour.
本申请实施例中,射点交叉法是一种用于确定图像中物体内外轮廓的方法。In the embodiment of the present application, the shot intersection method is a method for determining the inner and outer contours of an object in an image.
具体实施例中,在n大于1时,可以对n个轮廓点集采用射线交叉法判断其内外轮廓,从而,得到内外轮廓数据,这是因为若n等于1时,说明此时只有一个轮廓点集,无需区分内外轮廓,一个轮廓点集只能是外轮廓。In a specific embodiment, when n is greater than 1, the ray intersection method can be used to determine the inner and outer contours of n contour point sets, thereby obtaining the inner and outer contour data. This is because if n is equal to 1, it means that there is only one contour point set at this time, and there is no need to distinguish between the inner and outer contours. One contour point set can only be the outer contour.
可选的,步骤S106,所述对所述n个轮廓点集采用射线交叉法判断其内外轮廓,得到内外轮廓数据,包括:Optionally, step S106, using a ray intersection method to determine the inner and outer contours of the n contour point sets to obtain inner and outer contour data, includes:
步骤C1:获取第二轮廓点集LP2中的点A;所述第二轮廓点集LP2为所述n个轮廓点集中任一点集;Step C1: obtaining point A in the second contour point set LP2; the second contour point set LP2 is any point set in the n contour point sets;
步骤C2:通过所述射线交叉法判断所述点A与所述n个轮廓点集中除了所述第二轮廓点集LP2之外的点集的位置关系,得到n-1个位置关系;Step C2: determining the positional relationship between the point A and the point sets in the n contour point sets except the second contour point set LP2 by the ray intersection method, and obtaining n-1 positional relationships;
步骤C3:根据所述n-1个位置关系确定所述第二轮廓点集LP2的第一轮廓属性数据;Step C3: determining the first contour attribute data of the second contour point set LP2 according to the n-1 positional relationships;
对所述n个轮廓点集中除了所述第二轮廓点集LP2之外的每一轮廓点集均重复一次上述步骤C1-C3,得到n-1个轮廓属性数据;Repeat the above steps C1-C3 once for each contour point set among the n contour point sets except the second contour point set LP2, to obtain n-1 contour attribute data;
基于所述第一轮廓属性数据和所述n-1个轮廓属性数据确定所述内外轮廓数据。The inner and outer contour data are determined based on the first contour attribute data and the n-1 contour attribute data.
本申请实施例中,点与轮廓点集之间的位置关系可以包括内部关系或外部关系,不包括边界关系。边界关系就是指点位于轮廓点集组成的多边形的边上,换句话说,就是该点是轮廓点集中的一个点。In the embodiment of the present application, the positional relationship between a point and a contour point set may include an internal relationship or an external relationship, but does not include a boundary relationship. A boundary relationship means that the point is located on the edge of a polygon formed by the contour point set, in other words, the point is a point in the contour point set.
具体实施例中,可以先获取第二轮廓点集LP2中的点A,具体的,可以是按上述第二轮廓点集LP2的列表顺序进行获取,得到列表顺序排在第一的点A,当然,也可以是随机获取,接着,可以通过射线交叉法判断点A与n个轮廓点集中除了第二轮廓点集LP2之外的点集的位置关系,得到n-1个位置关系;然后,可以根据n-1个位置关系确定第二轮廓点集LP2的第一轮廓属性数据,例如,可以根据这n-1个位置关系可以确定该第二轮廓点集LP2与其他n-1个轮廓点集之间的轮廓属性,得到n-1轮廓属性,也即第一轮廓属性数据包括这n-1轮廓属性。In a specific embodiment, point A in the second contour point set LP2 can be obtained first. Specifically, point A can be obtained in the list order of the second contour point set LP2 to obtain point A that is first in the list order. Of course, it can also be obtained randomly. Then, the positional relationship between point A and the point sets in the n contour point sets except the second contour point set LP2 can be determined by the ray intersection method to obtain n-1 positional relationships. Then, the first contour attribute data of the second contour point set LP2 can be determined based on the n-1 positional relationships. For example, the contour attributes between the second contour point set LP2 and the other n-1 contour point sets can be determined based on the n-1 positional relationships to obtain n-1 contour attributes, that is, the first contour attribute data includes the n-1 contour attributes.
举个例子说明下,假设n=2,第二轮廓点集LP2就对应一个位置关系,那么就可以直接根据该位置关系确定一个轮廓属性,得到第一轮廓属性数据,也即该第一轮廓属性数据仅包括一个轮廓属性;假设,n=3,第二轮廓点集LP2就对应两个位置关系,根据这两个位置关系可以确定两个轮廓属性,得到第一轮廓属性数据,也即该第一轮廓属性数据仅包括两个轮廓属性,可以看出,第一轮廓属性数据包括了第二轮廓点集LP2与其他轮廓点集中每一个轮廓点集的轮廓属性。To illustrate, assuming n=2, the second contour point set LP2 corresponds to one positional relationship, then a contour attribute can be directly determined based on the positional relationship to obtain first contour attribute data, that is, the first contour attribute data only includes one contour attribute; assuming n=3, the second contour point set LP2 corresponds to two positional relationships, two contour attributes can be determined based on the two positional relationships to obtain first contour attribute data, that is, the first contour attribute data only includes two contour attributes. It can be seen that the first contour attribute data includes the contour attributes of the second contour point set LP2 and each contour point set in other contour point sets.
需要解释的是,位置关系为内部关系说明第二轮廓点集LP2的轮廓属性为内轮廓,位置关系为外部关系说明第二轮廓点集LP2的轮廓属性为外轮廓。It should be explained that the positional relationship being an internal relationship indicates that the contour attribute of the second contour point set LP2 is an inner contour, and the positional relationship being an external relationship indicates that the contour attribute of the second contour point set LP2 is an outer contour.
进一步的,可以对n个轮廓点集中除了第二轮廓点集LP2之外的每一轮廓点集均重复一次上述步骤C1-C3,得到n-1个轮廓属性数据;基于第一轮廓属性数据和n-1个轮廓属性数据确定内外轮廓数据,具体的,可以对第一轮廓属性数据和n-1个轮廓属性数据中的轮廓属性进行整理,去除其中的重复数据,以得到上述内外轮廓数据,这是在因为上述重复上述步骤C1-C3得到n-1个轮廓属性数据的过程中,会对已经得到轮廓属性数据的轮廓点集重复获取,以第二轮廓点集LP2为例,在第一次进行步骤C1-C3时,已经得到了第二轮廓点集LP2与另一轮廓点集A之间的轮廓属性了,但是,在之后对轮廓点集A重复上述步骤C1-C3时,还会重复获取一次轮廓点集A与第二轮廓点集LP2之间的轮廓属性,这就产生了重复数据,需要去除。Furthermore, the above steps C1-C3 can be repeated once for each contour point set among the n contour point sets except the second contour point set LP2 to obtain n-1 contour attribute data; the inner and outer contour data are determined based on the first contour attribute data and the n-1 contour attribute data. Specifically, the contour attributes in the first contour attribute data and the n-1 contour attribute data can be sorted, and the duplicate data therein can be removed to obtain the above inner and outer contour data. This is because in the process of repeating the above steps C1-C3 to obtain n-1 contour attribute data, the contour point set that has already obtained the contour attribute data will be repeatedly obtained. Taking the second contour point set LP2 as an example, when the steps C1-C3 are performed for the first time, the contour attributes between the second contour point set LP2 and another contour point set A have been obtained. However, when the above steps C1-C3 are repeated for the contour point set A later, the contour attributes between the contour point set A and the second contour point set LP2 will be repeatedly obtained again, which generates duplicate data that needs to be removed.
可选的,步骤C2,所述射线交叉法判断所述点A与第三轮廓点集LP3之间的位置关系,所述第三轮廓点集LP3为所述n个轮廓点集中除了所述第二轮廓点集LP2之外的任一点集,可以包括如下步骤:Optionally, step C2, the ray intersection method determines the positional relationship between the point A and a third contour point set LP3, wherein the third contour point set LP3 is any point set among the n contour point sets except the second contour point set LP2, may include the following steps:
D1、建立目标直角坐标系;D1. Establish the target rectangular coordinate system;
D2、确定所述点A和所述第三轮廓点集LP3在所述目标直角坐标系中的位置坐标,得到坐标A和坐标集合LP3;所述坐标集合LP3为列表,所述坐标集合LP3的列表顺序与所述第三轮廓点集LP3的顺序相同;D2, determining the position coordinates of the point A and the third contour point set LP3 in the target rectangular coordinate system, and obtaining the coordinate A and the coordinate set LP3; the coordinate set LP3 is a list, and the list order of the coordinate set LP3 is the same as the order of the third contour point set LP3;
D3、初始化目标计数器counter为0和第一多边形的第一列表索引r为1;所述目标计数器counter用于记录所述点A向正无穷大方向引出的射线A1与所述第一多边形的边的交叉次数;所述第一多边形为所述坐标集合LP3构成的多边形;D3, initialize the target counter counter to 0 and the first list index r of the first polygon to 1; the target counter counter is used to record the number of intersections between the ray A1 drawn from the point A to the positive infinity direction and the edge of the first polygon; the first polygon is the polygon formed by the coordinate set LP3;
D4、根据所述第一列表索引r依次遍历所述第一多边形的每条边与所述射线A1的交点,每检测到一个交点,将所述目标计数器counter的值加1;D4. traverse the intersections of each edge of the first polygon and the ray A1 in sequence according to the first list index r, and increase the value of the target counter counter by 1 each time an intersection is detected;
D5、若最终所述目标计数器counter的值为偶数,则确定所述点A与所述第三轮廓点集LP3之间的位置关系包括外部关系;D5. If the final value of the target counter counter is an even number, determine that the positional relationship between the point A and the third contour point set LP3 includes an external relationship;
D6、若最终所述目标计数器counter的值为奇数,则确定所述点A与所述第三轮廓点集LP3之间的位置关系包括内部关系。D6. If the final value of the target counter counter is an odd number, determine that the positional relationship between the point A and the third contour point set LP3 includes an internal relationship.
本申请实施例中,目标直角坐标系可以为二维或三维坐标系。In the embodiment of the present application, the target rectangular coordinate system may be a two-dimensional or three-dimensional coordinate system.
具体实施例中,可以先建立一个目标直角坐标系,具体的,目标直角坐标系可以为二维坐标系,可以以目标3D引擎的中心点作为原点,定义相互垂直的两个坐标轴,如x轴和y轴,并定义每条坐标轴的正负方向,得到该目标直角坐标系;接着,可以确定点A和第三轮廓点集LP3在目标直角坐标系中的位置坐标,得到坐标A和坐标集合LP3,具体的,可以使用目标3D引擎提供的相关API或函数(例如,Python中的OpenGL库)来获取点A的坐标,得到坐标A,又因为,第三轮廓点集LP3中包含有多个点,这多个点对应多个点坐标,将这多个点坐标按该第三轮廓点集LP3的列表顺序进行排列,得到坐标集合LP3。In a specific embodiment, a target rectangular coordinate system can be established first. Specifically, the target rectangular coordinate system can be a two-dimensional coordinate system. The center point of the target 3D engine can be used as the origin, and two mutually perpendicular coordinate axes, such as the x-axis and the y-axis, can be defined. The positive and negative directions of each coordinate axis are also defined to obtain the target rectangular coordinate system. Then, the position coordinates of point A and the third contour point set LP3 in the target rectangular coordinate system can be determined to obtain coordinate A and coordinate set LP3. Specifically, the relevant API or function provided by the target 3D engine (for example, the OpenGL library in Python) can be used to obtain the coordinates of point A to obtain coordinate A. Because the third contour point set LP3 contains multiple points, these multiple points correspond to multiple point coordinates, and these multiple point coordinates are arranged in the list order of the third contour point set LP3 to obtain coordinate set LP3.
接着,可以初始化一个目标计数器counter=0,以及将第一多边形对应的第一列表索引r=1;然后,可以从点A处向正无穷大方向(例如,x轴正方向)引出一条射线A1,可以根据第一列表索引r依次遍历第一多边形的每条边与射线A1的交点,每检测到一个交点,将目标计数器counter的值加1;若最终目标计数器counter的值为偶数,则确定点A与第三轮廓点集LP3之间的位置关系包括外部关系;若最终目标计数器counter的值为奇数,则确定点A与第三轮廓点集LP3之间的位置关系包括内部关系。Next, a target counter counter=0 can be initialized, and the first list index r corresponding to the first polygon can be set to 1; then, a ray A1 can be drawn from point A toward the positive infinity direction (for example, the positive direction of the x-axis), and the intersection points of each edge of the first polygon and the ray A1 can be traversed in sequence according to the first list index r, and the value of the target counter counter is increased by 1 each time an intersection is detected; if the value of the final target counter counter is an even number, then it is determined that the positional relationship between point A and the third contour point set LP3 includes an external relationship; if the value of the final target counter counter is an odd number, then it is determined that the positional relationship between point A and the third contour point set LP3 includes an internal relationship.
请参阅图5,图5是本申请实施例提供的一种交叉射线法的原理示意图,举个例子说明下,可以看出,图5中包括:第一多边形S1、点A、点B、点C、射线A1等,其中,第一多边形S1是上述坐标集合LP3构成的多边形,该第一多边形S1的各个顶点坐标组成了上述坐标集合LP3,点A、点B、点C等均代表n个轮廓点集中的一个点集,以点A为例,上述根据所述第一列表索引r依次遍历所述第一多边形的每条边与所述射线A1的交点,每检测到一个交点,将所述目标计数器counter的值加1的步骤,包括:Please refer to FIG5 , which is a schematic diagram of the principle of a cross-ray method provided by an embodiment of the present application. As an example, it can be seen that FIG5 includes: a first polygon S1, point A, point B, point C, ray A1, etc., wherein the first polygon S1 is a polygon formed by the above-mentioned coordinate set LP3, and the coordinates of each vertex of the first polygon S1 constitute the above-mentioned coordinate set LP3. Point A, point B, point C, etc. all represent a point set in the n contour point sets. Taking point A as an example, the above-mentioned step of traversing the intersection of each edge of the first polygon and the ray A1 in turn according to the first list index r, and adding 1 to the value of the target counter counter each time an intersection is detected, includes:
首先,可以定义两个点向量p1和p2,刚开始的时候,第一列表索引r=1,可以将坐标集合LP3中的第一个顶点坐标赋值给点向量p1,还可以将坐标集合LP3中的第二个顶点坐标赋值给点向量p2,这样点向量p1和p2相连就是第一多边形S1的第一条边,接着,可以检查点A的y坐标是否在点向量p1和p2的y坐标范围之内,例如,点A(x3,y3),p1(x4,y4)和p2(x5,y5),假设y4小于或等于y5,判断y3是否满足:y4≤y3≤y5,满足该条件则说明射线A1有可能与上述第一条边相交。First, two point vectors p1 and p2 can be defined. At the beginning, the first list index r=1. The first vertex coordinate in the coordinate set LP3 can be assigned to the point vector p1, and the second vertex coordinate in the coordinate set LP3 can be assigned to the point vector p2. In this way, the point vectors p1 and p2 are connected to form the first edge of the first polygon S1. Then, it can be checked whether the y coordinate of point A is within the y coordinate range of point vectors p1 and p2. For example, point A (x3, y3), p1 (x4, y4) and p2 (x5, y5), assuming that y4 is less than or equal to y5, determine whether y3 satisfies: y4≤y3≤y5. If this condition is met, it means that ray A1 may intersect with the above-mentioned first edge.
其次,检查射线A1是否与该第一条边相交,若相交则获取交点的坐标,具体的,可以根据p1和p2的坐标信息计算得到上述第一条边的直线方程,然后,可以将点A的纵坐标带入方程求解,得到交点坐标(x6,y6),需要注意的是y6与y3相等,接着,可以是判断点A的横坐标x3是否满足:x3≤x6,并且,y5!=y6,若都满足,说明射线A1与上述第一条边相交,将目标计数器counter的值加1,并且,第一列表索引r的值也加1,并对通过h对r进行模运算,得到模运算之后的r,其中,h为第一多边形的边数。Secondly, check whether ray A1 intersects with the first edge. If so, obtain the coordinates of the intersection. Specifically, the straight line equation of the first edge can be calculated based on the coordinate information of p1 and p2. Then, the ordinate of point A can be substituted into the equation to solve the intersection coordinate (x6, y6). It should be noted that y6 is equal to y3. Next, it can be determined whether the abscissa x3 of point A satisfies: x3≤x6, and y5!=y6. If all are satisfied, it means that ray A1 intersects with the first edge. The value of the target counter counter is increased by 1, and the value of the first list index r is also increased by 1. The modulus operation is performed on r through h to obtain r after the modulus operation, where h is the number of edges of the first polygon.
最后,根据最新的第一列表索引r对p1和p2重新赋值,将坐标集合LP3中的第r个顶点坐标赋值给点向量p1,将坐标集合LP3中的第(r+1)个顶点坐标赋值给点向量p2,如此,p1和p2相连就是第一多边形S1的第r条边,重复上文所述的步骤判断点A是否与第r条边相连,直到遍历完第一多边形S1的所有边,得到最终的目标计数器counter,也即点A与第三轮廓点集LP3的交点个数。Finally, p1 and p2 are reassigned according to the latest first list index r, the rth vertex coordinate in the coordinate set LP3 is assigned to the point vector p1, and the (r+1)th vertex coordinate in the coordinate set LP3 is assigned to the point vector p2. In this way, p1 and p2 are connected to form the rth edge of the first polygon S1. Repeat the above steps to determine whether point A is connected to the rth edge until all edges of the first polygon S1 are traversed to obtain the final target counter counter, that is, the number of intersections between point A and the third contour point set LP3.
S107、基于格林公式计算所述n个轮廓点集中轮廓点构成的多边形的面积,得到n个面积数据。S107, calculating the area of the polygon formed by the contour points in the n contour point set based on Green's formula to obtain n area data.
本申请实施例中,格林公式主要用于将轮廓点在平面上的曲线积分转换为面积积分,从而简化问题的求解。In the embodiments of the present application, Green's formula is mainly used to convert the curve integral of the contour point on the plane into the area integral, thereby simplifying the solution of the problem.
具体实施例中,基于格林公式依次计算上述n个轮廓点集中每一轮廓点集的面积,每个轮廓点集中的轮廓点都会构成的相应的多边形,通过计算该多边形的面积和,可以得到n个面积数据。In a specific embodiment, the area of each of the n contour point sets is calculated in turn based on Green's formula. The contour points in each contour point set will form a corresponding polygon. By calculating the sum of the areas of the polygons, n area data can be obtained.
可选的,步骤S107,所述基于格林公式计算第四轮廓点集LP4中轮廓点构成的多边形的面积,得到目标面积数据,所述第四轮廓点集LP4为所述n个轮廓点集中任一点集,可以包括如下步骤:Optionally, step S107, calculating the area of the polygon formed by the contour points in the fourth contour point set LP4 based on the Green's formula to obtain the target area data, wherein the fourth contour point set LP4 is any point set in the n contour point sets, may include the following steps:
71、获取所述第四轮廓点集LP4的轮廓点个数q;q为正整数;71. Obtain the number q of contour points of the fourth contour point set LP4; q is a positive integer;
72、在所述轮廓点个数q大于2时,初始化目标面积S为0;所述目标面积S用于累加所述第四轮廓点集LP4中各点构成的多边形的面积有向和;72. When the number of contour points q is greater than 2, initialize the target area S to 0; the target area S is used to accumulate the directed sum of the areas of the polygons formed by the points in the fourth contour point set LP4;
73、确定所述第四轮廓点集LP4在所述目标直角坐标系构成的多边形,得到第二多边形;73. Determine a polygon formed by the fourth contour point set LP4 in the target rectangular coordinate system to obtain a second polygon;
74、初始化所述第二多边形的第二列表索引k为0;所述第二列表索引k在使用之前通过所述轮廓点个数q对所述第二列表索引k进行模运算,防止所述第二列表索引k超出所述第二多边形的范围;74. Initialize the second list index k of the second polygon to 0; before using the second list index k, perform a modulo operation on the second list index k by the number of contour points q to prevent the second list index k from exceeding the range of the second polygon;
75、根据所述第二列表索引k对所述第二多边形的每条边进行迭代,根据所述格林公式计算由当前点、前一个点和下一个点形成的三角形面积,并将所述三角形面积累加到所述目标面积S中;75. Iterate each edge of the second polygon according to the second list index k, calculate the area of a triangle formed by the current point, the previous point and the next point according to the Green's formula, and add the area of the triangle to the target area S;
76、将所述目标面积S除以2并取绝对值,得到所述目标面积数据;所述目标面积数据为所述n个面积数据中的一个。76. Divide the target area S by 2 and take the absolute value to obtain the target area data; the target area data is one of the n area data.
本申请实施例中,In the embodiment of the present application,
具体实施例中,可以对第四轮廓点集LP4进行计数,以得到第四轮廓点集LP4的轮廓点个数q;接着,在轮廓点个数q大于2时,初始化目标面积S为0,这是因为构成多边形的必要条件就是要具备3个或3个以上的点;若轮廓点个数q小于或等于2,则无需进行下面的步骤。In a specific embodiment, the fourth contour point set LP4 can be counted to obtain the number q of contour points of the fourth contour point set LP4; then, when the number q of contour points is greater than 2, the target area S is initialized to 0. This is because the necessary condition for forming a polygon is to have 3 or more points; if the number q of contour points is less than or equal to 2, there is no need to perform the following steps.
接着,可以确定第四轮廓点集LP4在目标直角坐标系构成的多边形,得到第二多边形,具体的,可以将该第四轮廓点集LP4中的轮廓点放置在上述目标直角坐标系,可以按第四轮廓点集LP4的列表顺序依次连接各个轮廓点,得到第二多边形;然后,可以初始化第二多边形的第二列表索引k为0;第二列表索引k在每次使用之前都可以通过轮廓点个数q对第二列表索引k进行模运算,防止第二列表索引k超出第二多边形的范围。Next, the polygon formed by the fourth contour point set LP4 in the target rectangular coordinate system can be determined to obtain the second polygon. Specifically, the contour points in the fourth contour point set LP4 can be placed in the above-mentioned target rectangular coordinate system, and the contour points can be connected in sequence according to the list order of the fourth contour point set LP4 to obtain the second polygon; then, the second list index k of the second polygon can be initialized to 0; before each use, the second list index k can be modulo operated by the number of contour points q to prevent the second list index k from exceeding the range of the second polygon.
进一步的,可以根据第二列表索引k对第二多边形的每条边进行迭代,根据格林公式计算由当前点、前一个点和下一个点形成的三角形面积,并将三角形面积累加到目标面积S中,例如,假设第二列表索引k为0,那么当前点为上述第四轮廓点集LP4中的第一个点,前一个点为上述第四轮廓点集LP4中的最后一个点,下一个点为上述第四轮廓点集LP4中的第二个点,这三个点可以构成一个三角形,接着,可以根据格林公式计算该三角形的面积,得到第一面积,将该第一面积累加到上述目标面积S中,得到最新的目标面积S,如此重复多次,直到将第二多边形的每条边都遍历完成,得到最终的目标面积S。Furthermore, each edge of the second polygon can be iterated according to the second list index k, and the area of the triangle formed by the current point, the previous point and the next point can be calculated according to the Green's formula, and the area of the triangle is accumulated and added to the target area S. For example, assuming that the second list index k is 0, then the current point is the first point in the above-mentioned fourth contour point set LP4, the previous point is the last point in the above-mentioned fourth contour point set LP4, and the next point is the second point in the above-mentioned fourth contour point set LP4. These three points can form a triangle. Then, the area of the triangle can be calculated according to the Green's formula to obtain the first area, and the first area is accumulated and added to the above-mentioned target area S to obtain the latest target area S. This is repeated many times until each edge of the second polygon is traversed and the final target area S is obtained.
最后,可以将最终的目标面积S除以2并取绝对值,得到目标面积数据,这是因为在累加的过程中,每个三角形的面积的都被计算了两次(一次正向,一次反向),取绝对值是因为大模型训练需要的是面积的大小而不是方向;目标面积数据为上述n个面积数据中的一个。Finally, the final target area S can be divided by 2 and the absolute value is taken to obtain the target area data. This is because in the accumulation process, the area of each triangle is calculated twice (once in the forward direction and once in the reverse direction). The absolute value is taken because the large model training requires the size of the area rather than the direction. The target area data is one of the above n area data.
如此,通过获取第四轮廓点集LP4的轮廓点个数q;在轮廓点个数q大于2时,初始化目标面积S为0;确定第四轮廓点集LP4在目标直角坐标系构成的多边形,得到第二多边形;初始化第二多边形的第二列表索引k为0;根据第二列表索引k对第二多边形的每条边进行迭代,根据格林公式计算由当前点、前一个点和下一个点形成的三角形面积,并将三角形面积累加到目标面积S中;将目标面积S除以2并取绝对值,得到目标面积数据,通过格林公式来计算由特定点构成的三角形面积并累加到目标面积中,可以较为精确地得到轮廓点集所构成的多边形的面积,避免了简单估算带来的误差。In this way, the number q of contour points of the fourth contour point set LP4 is obtained; when the number q of contour points is greater than 2, the target area S is initialized to 0; the polygon formed by the fourth contour point set LP4 in the target rectangular coordinate system is determined to obtain the second polygon; the second list index k of the second polygon is initialized to 0; each edge of the second polygon is iterated according to the second list index k, and the area of the triangle formed by the current point, the previous point and the next point is calculated according to the Green's formula, and the triangle area is added to the target area S; the target area S is divided by 2 and the absolute value is taken to obtain the target area data, and the area of the triangle formed by specific points is calculated by the Green's formula and added to the target area. The area of the polygon formed by the contour point set can be obtained more accurately, avoiding the errors caused by simple estimation.
S108、对所述n个轮廓点集、所述内外轮廓数据和所述n个面积数据进行整合导出,得到目标轮廓点数据。S108, integrating and exporting the n contour point sets, the inner and outer contour data, and the n area data to obtain target contour point data.
本申请实施例中,可以通过目标3D引擎对上述n个轮廓点集、内外轮廓数据和n个面积数据进行整合导出,以得到便于使用的轮廓点数据,也即目标轮廓点数据。In an embodiment of the present application, the above-mentioned n contour point sets, inner and outer contour data and n area data can be integrated and exported through a target 3D engine to obtain contour point data that is easy to use, that is, target contour point data.
可选的,步骤S108,所述对所述n个轮廓点集、所述内外轮廓数据和所述n个面积数据进行整合导出,得到目标轮廓点数据,包括:Optionally, step S108, integrating and exporting the n contour point sets, the inner and outer contour data, and the n area data to obtain target contour point data, includes:
81、将所述n个轮廓点集、所述内外轮廓数据和所述n个面积数据的数据格式转化为预设数据格式;81. Convert the data formats of the n contour point sets, the inner and outer contour data, and the n area data into a preset data format;
82、确定所述n个轮廓点集、所述内外轮廓数据和所述n个面积数据之间的对应关系,得到目标对应关系;一个轮廓点集对应一个轮廓属性数据;一个轮廓点集对应一个面积数据;82. Determine the corresponding relationship between the n contour point sets, the inner and outer contour data and the n area data to obtain a target corresponding relationship; one contour point set corresponds to one contour attribute data; one contour point set corresponds to one area data;
83、根据所述目标对应关系将所述n个轮廓点集、所述内外轮廓数据和所述n个面积数据进行合并导出,得到所述目标轮廓点数据。83. According to the target corresponding relationship, the n contour point sets, the inner and outer contour data and the n area data are combined and exported to obtain the target contour point data.
本申请实施例中,预设数据格式可以为提前预设或默认。In the embodiment of the present application, the preset data format may be preset in advance or default.
具体实施例中,可以将上述n个轮廓点集、内外轮廓数据和n个面积数据的数据格式转化为预设数据格式,具体的,预设数据格式可以为json格式,可以通过目标3D引擎来将这些数据都转换为预设数据格式。In a specific embodiment, the data formats of the above-mentioned n contour point sets, inner and outer contour data and n area data can be converted into a preset data format. Specifically, the preset data format can be a json format, and all these data can be converted into the preset data format through the target 3D engine.
接着,可以确定n个轮廓点集、内外轮廓数据和n个面积数据之间的对应关系,得到目标对应关系,具体的,可以是每个数据都包含一个标识信息,该标识信息可以包含目标模型和拍摄角度的信息,这样就可以根据该标识信息确定上述n个轮廓点集、内外轮廓数据和n个面积数据之间的对应关系,得到目标对应关系;最后,可以根据目标对应关系将n个轮廓点集、内外轮廓数据和n个面积数据进行一一对应起来,然后,再将这些数据合并导出到一个json文件,也即目标轮廓点数据。Next, the correspondence between the n contour point sets, the inner and outer contour data and the n area data can be determined to obtain the target correspondence. Specifically, each data may contain an identification information, and the identification information may contain information about the target model and the shooting angle. In this way, the correspondence between the above-mentioned n contour point sets, the inner and outer contour data and the n area data can be determined according to the identification information to obtain the target correspondence. Finally, the n contour point sets, the inner and outer contour data and the n area data can be matched one by one according to the target correspondence, and then these data can be merged and exported to a json file, that is, the target contour point data.
请参阅图6,图6是本申请实施例提供的一种打印弹窗的示意图,在获取完上述目标轮廓点数据之后,目标3D引擎还可以弹出一个显示打印信息的打印弹窗,如图6所示,该打印弹窗可以包括时间信息、“找到颜色归属”、“有轮廓!!”、“面积27808.5”、“结束”等信息,通过该打印弹窗用户能够快速了解目标3D引擎对于上述目标模型的具体处理过程。Please refer to Figure 6, which is a schematic diagram of a print pop-up window provided in an embodiment of the present application. After obtaining the above-mentioned target contour point data, the target 3D engine can also pop up a print pop-up window displaying printing information. As shown in Figure 6, the print pop-up window can include time information, "Found color attribution", "There is contour!!", "Area 27808.5", "End" and other information. Through the print pop-up window, the user can quickly understand the specific processing process of the target 3D engine for the above-mentioned target model.
需要解释的是,上文所描述的基于3D引擎的多角度轮廓点提取方法都是针对单个目标模型来进行处理的,若需要对多个目标模型进行处理,可以为每个模型的模型纹理贴图分别赋予一个不同的颜色,假设有两个模型,一个是人物模型,一个是物体模型,可以为人物模型赋予黑色,物体模型赋予红色,如此,在上述处理第一目标轮廓点集的时候,可以将颜色作为关键字key区分不同的模型,这样提取出来的轮廓点集就包括了多个模型的轮廓点集,在目标3D引擎中,还可以通过改变人形模型和物体模型的角度和前后渲染顺序,再按照上述实施例中的基于3D引擎的多角度轮廓点提取方法提取轮廓点,可以得到海量的多模型在不同叠加状态下的数据,有助于保证训练大模型应对不同的业务场景和需求变化。业务场景可以包括多模型叠加,前后位置不同的叠加态,运动状态下的叠加等等,基于目标3D引擎,模型还可以有各种动画,以满足用户的需求。It should be explained that the multi-angle contour point extraction method based on the 3D engine described above is all processed for a single target model. If multiple target models need to be processed, a different color can be assigned to the model texture map of each model. Assuming there are two models, one is a human model and the other is an object model, the human model can be assigned black and the object model can be assigned red. In this way, when processing the first target contour point set, the color can be used as a keyword to distinguish different models. In this way, the extracted contour point set includes the contour point sets of multiple models. In the target 3D engine, the angle and front and back rendering order of the human model and the object model can be changed, and the contour points can be extracted according to the multi-angle contour point extraction method based on the 3D engine in the above embodiment. A large amount of data of multiple models in different superposition states can be obtained, which helps to ensure that the training of large models can cope with different business scenarios and demand changes. Business scenarios can include multi-model superposition, superposition states with different front and back positions, superposition in motion, etc. Based on the target 3D engine, the model can also have various animations to meet the needs of users.
可以看出,本申请实施例提供的基于3D引擎的多角度轮廓点提取方法,通过将目标3D引擎中的目标3D引擎摄像机对目标模型进行拍摄,可以实现360度无死角的拍摄目标模型,得到多个角度下目标模型的目标图像,然后,对该目标图像进行轮廓提取,能够得到大量的轮廓点数据,从而,提高了轮廓提取技术的提取效率。It can be seen that the multi-angle contour point extraction method based on the 3D engine provided in the embodiment of the present application can achieve 360-degree shooting of the target model without blind spots by shooting the target model with the target 3D engine camera in the target 3D engine, and obtain the target image of the target model at multiple angles. Then, the contour is extracted from the target image to obtain a large amount of contour point data, thereby improving the extraction efficiency of the contour extraction technology.
请参阅图7,图7是本申请实施例提供的一种电子设备的结构示意图,该电子设备包括处理器、存储器、通信接口以及一个或多个程序,所述处理器、存储器和通信接口通过总线相互连接。上述一个或多个程序被存储在上述存储器中,并且被配置由上述处理器执行,本申请实施例中,上述程序包括用于执行以下步骤的指令:Please refer to Figure 7, which is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application, the electronic device includes a processor, a memory, a communication interface and one or more programs, and the processor, the memory and the communication interface are interconnected via a bus. The one or more programs are stored in the memory and are configured to be executed by the processor. In the embodiment of the present application, the program includes instructions for executing the following steps:
获取目标模型;所述目标模型为3D模型;Acquire a target model; the target model is a 3D model;
确定所述目标模型对应的目标3D引擎以及目标3D引擎摄像机;Determine a target 3D engine and a target 3D engine camera corresponding to the target model;
通过所述目标3D引擎摄像机在目标拍摄角度下对所述目标模型进行拍摄,得到目标图像;所述目标拍摄角度为360度中的任一角度;The target model is photographed by the target 3D engine camera at a target shooting angle to obtain a target image; the target shooting angle is any angle in 360 degrees;
针对所述目标图像进行像素点遍历,找出其中的所有轮廓点,得到第一目标轮廓点集;Perform pixel traversal on the target image to find all contour points therein to obtain a first target contour point set;
根据目标递归算法对所述第一目标轮廓点集进行拆分,得到n个轮廓点集;n为大于或等于1的整数;The first target contour point set is split according to the target recursive algorithm to obtain n contour point sets; n is an integer greater than or equal to 1;
在n大于1时,对所述n个轮廓点集采用射线交叉法判断其内外轮廓,得到内外轮廓数据;所述内外轮廓数据包括所述n个轮廓点集中每一轮廓点集的轮廓属性;所述轮廓属性为内轮廓或外轮廓;When n is greater than 1, the inner and outer contours of the n contour point sets are determined by using a ray intersection method to obtain inner and outer contour data; the inner and outer contour data include contour attributes of each contour point set in the n contour point sets; the contour attribute is an inner contour or an outer contour;
基于格林公式计算所述n个轮廓点集中轮廓点构成的多边形的面积,得到n个面积数据;Calculate the area of the polygon formed by the contour points in the n contour point set based on Green's formula to obtain n area data;
对所述n个轮廓点集、所述内外轮廓数据和所述n个面积数据进行整合导出,得到目标轮廓点数据。The n contour point sets, the inner and outer contour data and the n area data are integrated and exported to obtain target contour point data.
可选的,在所述通过所述目标3D引擎摄像机在目标拍摄角度下对所述目标模型进行拍摄,得到目标图像方面,上述程序还包括用于执行以下步骤的指令:Optionally, in the aspect of photographing the target model at a target shooting angle by the target 3D engine camera to obtain a target image, the program further includes instructions for executing the following steps:
将所述目标模型导入所述目标3D引擎,并将所述目标模型放置于所述目标3D引擎中的预设场景中;Importing the target model into the target 3D engine, and placing the target model in a preset scene in the target 3D engine;
确定所述目标3D引擎摄像机针对所述目标模型的初始角度;Determining an initial angle of the target 3D engine camera with respect to the target model;
获取目标对象的目标需求数据;Obtain target demand data of target objects;
根据所述目标需求数据确定所述目标拍摄角度;Determine the target shooting angle according to the target requirement data;
基于所述目标拍摄角度和所述初始角度确定所述目标模型的目标调节参数;Determining a target adjustment parameter of the target model based on the target shooting angle and the initial angle;
根据所述目标调节参数对所述目标模型的位置进行调节,以使所述目标模型处于所述目标拍摄角度;Adjusting the position of the target model according to the target adjustment parameter so that the target model is at the target shooting angle;
将所述目标模型的纹理贴图修改为预设颜色,确定所述目标模型在所述目标3D引擎中所处的目标层级;Modify the texture map of the target model to a preset color, and determine the target level of the target model in the target 3D engine;
根据所述目标层级调节所述目标3D引擎摄像机的初始拍摄层级参数,得到目标拍摄层级参数;adjusting the initial shooting level parameters of the target 3D engine camera according to the target level to obtain the target shooting level parameters;
通过所述目标拍摄层级参数的所述目标3D引擎摄像机对处于所述目标拍摄角度下的所述目标模型进行拍摄,得到所述目标图像。The target model at the target shooting angle is photographed by the target 3D engine camera with the target shooting level parameter to obtain the target image.
可选的,在所述针对所述目标图像进行像素点遍历,找出其中的所有轮廓点,得到第一目标轮廓点集方面,上述程序还包括用于执行以下步骤的指令:Optionally, in the aspect of performing pixel traversal on the target image to find all contour points therein and obtain a first target contour point set, the program further includes instructions for executing the following steps:
步骤A1:获取所述目标图像中的第一像素点;Step A1: Acquire a first pixel point in the target image;
步骤A2:确定所述第一像素点周围的i个像素点;i为2、4、8中的任一数字;Step A2: determining i pixel points around the first pixel point; i is any number among 2, 4, and 8;
步骤A3:将所述第一像素点与所述i个像素点中每一像素点进行颜色比较,得到与所述第一像素点颜色不同的j个像素点;j为小于或等于i的自然数;Step A3: Compare the colors of the first pixel with each of the i pixel points to obtain j pixel points with different colors from the first pixel point; j is a natural number less than or equal to i;
步骤A4:在所述j个像素点大于指定值个点时,判断所述第一像素点为轮廓点,将所述第一像素点加入到初始轮廓点集中;所述初始轮廓点集初始为以0起始的空列表;Step A4: when the j pixel points are greater than a specified value, the first pixel point is determined to be a contour point, and the first pixel point is added to an initial contour point set; the initial contour point set is initially an empty list starting with 0;
基于预设遍历算法从所述第一像素点开始遍历所述目标图像中的像素点,每遍历一个像素点均重复一次上述步骤A1-A4,直到将所述目标图像遍历完成,得到所述第一目标轮廓点集。Based on a preset traversal algorithm, pixel points in the target image are traversed starting from the first pixel point, and the above steps A1-A4 are repeated each time a pixel point is traversed until the target image is completely traversed to obtain the first target contour point set.
可选的,在所述将所述第一像素点与所述i个像素点中每一像素点进行颜色比较,得到与所述第一像素点颜色不同的j个像素点方面,上述程序还包括用于执行以下步骤的指令:Optionally, in the aspect of comparing the first pixel with each of the i pixels to obtain j pixels having a different color from the first pixel, the program further includes instructions for executing the following steps:
获取所述第一像素点的RGBA颜色值,得到第一RGBA值;Obtaining the RGBA color value of the first pixel to obtain a first RGBA value;
根据所述第一RGBA值确定所述第一像素点的颜色归属,得到第一颜色归属;Determine the color attribution of the first pixel according to the first RGBA value to obtain a first color attribution;
获取所述i个像素点中每一像素点的RGBA颜色值,得到i个RGBA值;Obtain the RGBA color value of each pixel in the i pixels to obtain i RGBA values;
根据所述i个RGBA值确定所述i个像素点中每一像素点的颜色归属,得到i个颜色归属;Determine the color attribution of each pixel in the i pixels according to the i RGBA values to obtain i color attributions;
将所述i个颜色归属依次与所述第一颜色归属进行比较,得到与所述第一颜色归属不同的j个颜色归属;Compare the i color attributions with the first color attribution in sequence to obtain j color attributions different from the first color attribution;
确定所述j个颜色归属对应的所述j个像素点。Determine the j pixel points corresponding to the j colors.
可选的,所述第一目标轮廓点集包括m个点;m为大于或等于n的正整数;在所述根据目标递归算法对所述第一目标轮廓点集进行拆分,得到n个轮廓点集方面,上述程序还包括用于执行以下步骤的指令:Optionally, the first target contour point set includes m points; m is a positive integer greater than or equal to n; in the aspect of splitting the first target contour point set according to the target recursive algorithm to obtain n contour point sets, the program further includes instructions for executing the following steps:
步骤B1:获取所述第一目标轮廓点集中顺序排在第一的轮廓点,得到点p;Step B1: obtaining the contour point ranked first in the first target contour point set, and obtaining point p;
步骤B2:计算所述点p与所述第一目标轮廓点集中除了所述点p之外的所有点之间的距离,得到m-1个距离;Step B2: Calculate the distances between the point p and all points in the first target contour point set except the point p to obtain m-1 distances;
步骤B3:若所述m-1个距离均小于预设距离,则将所述点p从所述第一目标轮廓点集中除去,将所述点p加入新的点集,得到第一轮廓点集LP1;所述第一轮廓点集LP1为所述n个轮廓点集中的一个;Step B3: if the m-1 distances are all less than the preset distance, the point p is removed from the first target contour point set, and the point p is added to a new point set to obtain a first contour point set LP1; the first contour point set LP1 is one of the n contour point sets;
步骤B4:按所述第一目标轮廓点集的列表顺序对其中除了点p之外的其他点均重复上述步骤B1-B3,重复m-1次,以得到最终的所述第一轮廓点集LP1,以及所述第一目标轮廓点集拆分出所述第一轮廓点集LP1之后的第二目标轮廓点集;Step B4: repeating the above steps B1-B3 for all points except point p in the list order of the first target contour point set, repeating m-1 times, to obtain the final first contour point set LP1, and the second target contour point set after the first contour point set LP1 is split from the first target contour point set;
若所述第二目标轮廓点集中的轮廓点数量大于3,则按上述B1-B4步骤继续对所述第二目标轮廓点集进行拆分,直到所述第二目标轮廓点集中的点被取完或剩余点个数小于3,以得到所述n个轮廓点集。If the number of contour points in the second target contour point set is greater than 3, the second target contour point set is split according to the above steps B1-B4 until all the points in the second target contour point set are taken or the number of remaining points is less than 3, so as to obtain the n contour point sets.
可选的,在所述对所述n个轮廓点集采用射线交叉法判断其内外轮廓,得到内外轮廓数据方面,上述程序还包括用于执行以下步骤的指令:Optionally, in the aspect of using the ray intersection method to determine the inner and outer contours of the n contour point sets to obtain the inner and outer contour data, the program further includes instructions for executing the following steps:
步骤C1:获取第二轮廓点集LP2中的点A;所述第二轮廓点集LP2为所述n个轮廓点集中任一点集;Step C1: obtaining point A in the second contour point set LP2; the second contour point set LP2 is any point set in the n contour point sets;
步骤C2:通过所述射线交叉法判断所述点A与所述n个轮廓点集中除了所述第二轮廓点集LP2之外的点集的位置关系,得到n-1个位置关系;Step C2: determining the positional relationship between the point A and the point sets in the n contour point sets except the second contour point set LP2 by the ray intersection method, and obtaining n-1 positional relationships;
步骤C3:根据所述n-1个位置关系确定所述第二轮廓点集LP2的第一轮廓属性数据;Step C3: determining the first contour attribute data of the second contour point set LP2 according to the n-1 positional relationships;
对所述n个轮廓点集中除了所述第二轮廓点集LP2之外的每一轮廓点集均重复一次上述步骤C1-C3,得到n-1个轮廓属性数据;Repeat the above steps C1-C3 once for each contour point set among the n contour point sets except the second contour point set LP2, to obtain n-1 contour attribute data;
基于所述第一轮廓属性数据和所述n-1个轮廓属性数据确定所述内外轮廓数据。The inner and outer contour data are determined based on the first contour attribute data and the n-1 contour attribute data.
可选的,在所述射线交叉法判断所述点A与第三轮廓点集LP3之间的位置关系方面,所述第三轮廓点集LP3为所述n个轮廓点集中除了所述第二轮廓点集LP2之外的任一点集,上述程序还包括用于执行以下步骤的指令:Optionally, in determining the positional relationship between the point A and the third contour point set LP3 by the ray intersection method, the third contour point set LP3 is any point set among the n contour point sets except the second contour point set LP2, and the program further includes instructions for executing the following steps:
建立目标直角坐标系;Establish target rectangular coordinate system;
确定所述点A和所述第三轮廓点集LP3在所述目标直角坐标系中的位置坐标,得到坐标A和坐标集合LP3;所述坐标集合LP3为列表,所述坐标集合LP3的列表顺序与所述第三轮廓点集LP3的顺序相同;Determine the position coordinates of the point A and the third contour point set LP3 in the target rectangular coordinate system to obtain coordinates A and a coordinate set LP3; the coordinate set LP3 is a list, and the list order of the coordinate set LP3 is the same as the order of the third contour point set LP3;
初始化目标计数器counter为0和第一多边形的第一列表索引r为1;所述目标计数器counter用于记录所述点A向正无穷大方向引出的射线A1与所述第一多边形的边的交叉次数;所述第一多边形为所述坐标集合LP3构成的多边形;Initialize the target counter counter to 0 and the first list index r of the first polygon to 1; the target counter counter is used to record the number of intersections between the ray A1 drawn from the point A to the positive infinity direction and the edge of the first polygon; the first polygon is a polygon formed by the coordinate set LP3;
根据所述第一列表索引r依次遍历所述第一多边形的每条边与所述射线A1的交点,每检测到一个交点,将所述目标计数器counter的值加1;Traversing the intersections of each edge of the first polygon and the ray A1 in sequence according to the first list index r, and adding 1 to the value of the target counter counter each time an intersection is detected;
若最终所述目标计数器counter的值为偶数,则确定所述点A与所述第三轮廓点集LP3之间的位置关系包括外部关系;If the value of the target counter counter is an even number, it is determined that the positional relationship between the point A and the third contour point set LP3 includes an external relationship;
若最终所述目标计数器counter的值为奇数,则确定所述点A与所述第三轮廓点集LP3之间的位置关系包括内部关系。If the final value of the target counter counter is an odd number, it is determined that the positional relationship between the point A and the third contour point set LP3 includes an internal relationship.
可选的,在所述基于格林公式计算第四轮廓点集LP4中轮廓点构成的多边形的面积,得到目标面积数据方面,所述第四轮廓点集LP4为所述n个轮廓点集中任一点集,上述程序还包括用于执行以下步骤的指令:Optionally, in the aspect of calculating the area of the polygon formed by the contour points in the fourth contour point set LP4 based on the Green's formula to obtain the target area data, the fourth contour point set LP4 is any point set in the n contour point sets, and the above program further includes instructions for executing the following steps:
获取所述第四轮廓点集LP4的轮廓点个数q;q为正整数;Obtain the number q of contour points of the fourth contour point set LP4; q is a positive integer;
在所述轮廓点个数q大于2时,初始化目标面积S为0;所述目标面积S用于累加所述第四轮廓点集LP4中各点构成的多边形的面积有向和;When the number of contour points q is greater than 2, the target area S is initialized to 0; the target area S is used to accumulate the directed sum of the areas of the polygons formed by the points in the fourth contour point set LP4;
确定所述第四轮廓点集LP4在所述目标直角坐标系构成的多边形,得到第二多边形;Determine a polygon formed by the fourth contour point set LP4 in the target rectangular coordinate system to obtain a second polygon;
初始化所述第二多边形的第二列表索引k为0;所述第二列表索引k在使用之前通过所述轮廓点个数q对所述第二列表索引k进行模运算,防止所述第二列表索引k超出所述第二多边形的范围;Initialize the second list index k of the second polygon to 0; perform a modulo operation on the second list index k by the number of contour points q before using the second list index k to prevent the second list index k from exceeding the range of the second polygon;
根据所述第二列表索引k对所述第二多边形的每条边进行迭代,根据所述格林公式计算由当前点、前一个点和下一个点形成的三角形面积,并将所述三角形面积累加到所述目标面积S中;Iterate each edge of the second polygon according to the second list index k, calculate the area of a triangle formed by the current point, the previous point and the next point according to the Green's formula, and add the area of the triangle to the target area S;
将所述目标面积S除以2并取绝对值,得到所述目标面积数据;所述目标面积数据为所述n个面积数据中的一个。The target area S is divided by 2 and the absolute value is taken to obtain the target area data; the target area data is one of the n area data.
可选的,在所述对所述n个轮廓点集、所述内外轮廓数据和所述n个面积数据进行整合导出,得到目标轮廓点数据方面,上述程序还包括用于执行以下步骤的指令:Optionally, in the aspect of integrating and deriving the n contour point sets, the inner and outer contour data and the n area data to obtain target contour point data, the program further includes instructions for executing the following steps:
将所述n个轮廓点集、所述内外轮廓数据和所述n个面积数据的数据格式转化为预设数据格式;Converting the data formats of the n contour point sets, the inner and outer contour data, and the n area data into a preset data format;
确定所述n个轮廓点集、所述内外轮廓数据和所述n个面积数据之间的对应关系,得到目标对应关系;一个轮廓点集对应一个轮廓属性数据;一个轮廓点集对应一个面积数据;Determine the correspondence between the n contour point sets, the inner and outer contour data and the n area data to obtain a target correspondence; one contour point set corresponds to one contour attribute data; one contour point set corresponds to one area data;
根据所述目标对应关系将所述n个轮廓点集、所述内外轮廓数据和所述n个面积数据进行合并导出,得到所述目标轮廓点数据。The n contour point sets, the inner and outer contour data and the n area data are combined and exported according to the target corresponding relationship to obtain the target contour point data.
本申请实施例还提供一种计算机可读存储介质,其中,该计算机可读存储介质存储用于电子数据交换的计算机程序,该计算机程序使得计算机执行如上述方法实施例中记载的任一方法的部分或全部步骤,上述计算机包括电子设备。An embodiment of the present application also provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program for electronic data exchange, wherein the computer program enables a computer to execute part or all of the steps of any method recorded in the above method embodiments, and the above computer includes an electronic device.
本申请实施例还提供一种计算机程序产品,上述计算机程序产品包括存储了计算机程序的非瞬时性计算机可读存储介质,上述计算机程序可操作来使计算机执行如上述方法实施例中记载的任一方法的部分或全部步骤。该计算机程序产品可以为一个软件安装包,上述计算机包括电子设备。The present application also provides a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program, and the computer program is operable to cause a computer to execute some or all of the steps of any method described in the method embodiment. The computer program product may be a software installation package, and the computer includes an electronic device.
需要说明的是,对于前述的各方法实施例,为了简单描述,故将其都表述为一系列的动作组合,但是本领域技术人员应该知悉,本申请并不受所描述的动作顺序的限制,因为依据本申请,某些步骤可以采用其他顺序或者同时进行。其次,本领域技术人员也应该知悉,说明书中所描述的实施例均属于优选实施例,所涉及的动作和模块并不一定是本申请所必须的。It should be noted that, for the above-mentioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the order of the actions described, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present application.
在上述实施例中,对各个实施例的描述都各有侧重,某个实施例中没有详述的部分,可以参见其他实施例的相关描述。In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
在本申请所提供的几个实施例中,应该理解到,所揭露的装置,可通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如上述单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性或其它的形式。In the several embodiments provided in the present application, it should be understood that the disclosed devices can be implemented in other ways. For example, the device embodiments described above are only schematic, such as the division of the above-mentioned units, which is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, and the indirect coupling or communication connection of devices or units can be electrical or other forms.
上述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。The units described above as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
另外,在本申请各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
上述集成的单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储器中。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的全部或部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储器中,包括若干指令用以使得一台计算机设备(可为个人计算机、服务器或者网络设备等)执行本申请各个实施例上述方法的全部或部分步骤。而前述的存储器包括:U盘、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、移动硬盘、磁碟或者光盘等各种可以存储程序代码的介质。If the above-mentioned integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable memory. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a memory, including a number of instructions to enable a computer device (which can be a personal computer, server or network device, etc.) to perform all or part of the steps of the above-mentioned methods of each embodiment of the present application. The aforementioned memory includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, disk or CD-ROM and other media that can store program codes.
以上对本申请实施例进行了详细介绍,本文中应用了具体个例对本申请的原理及实施方式进行了阐述,以上实施例的说明只是用于帮助理解本申请的方法及其核心思想;同时,对于本领域的一般技术人员,依据本申请的思想,在具体实施方式及应用范围上均会有改变之处,综上所述,本说明书内容不应理解为对本申请的限制。The embodiments of the present application are introduced in detail above. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for general technical personnel in this field, according to the idea of the present application, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims (10)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202410694998.3A CN118710670A (en) | 2024-05-31 | 2024-05-31 | Multi-angle contour point extraction method and storage medium based on 3D engine |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202410694998.3A CN118710670A (en) | 2024-05-31 | 2024-05-31 | Multi-angle contour point extraction method and storage medium based on 3D engine |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| CN118710670A true CN118710670A (en) | 2024-09-27 |
Family
ID=92808030
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202410694998.3A Pending CN118710670A (en) | 2024-05-31 | 2024-05-31 | Multi-angle contour point extraction method and storage medium based on 3D engine |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN118710670A (en) |
Cited By (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN119472877A (en) * | 2025-01-13 | 2025-02-18 | 上海浦佳航食品有限公司 | A water bath temperature control system based on image analysis |
-
2024
- 2024-05-31 CN CN202410694998.3A patent/CN118710670A/en active Pending
Cited By (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN119472877A (en) * | 2025-01-13 | 2025-02-18 | 上海浦佳航食品有限公司 | A water bath temperature control system based on image analysis |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN111243093B (en) | Three-dimensional face grid generation method, device, equipment and storage medium | |
| CN112581629A (en) | Augmented reality display method and device, electronic equipment and storage medium | |
| CN109242961A (en) | A kind of face modeling method, apparatus, electronic equipment and computer-readable medium | |
| CN112652046A (en) | Game picture generation method, device, equipment and storage medium | |
| CN108230434B (en) | Image texture processing method and device, storage medium and electronic device | |
| CN116977522A (en) | Rendering method and device of three-dimensional model, computer equipment and storage medium | |
| WO2022022260A1 (en) | Image style transfer method and apparatus therefor | |
| CN109688343A (en) | The implementation method and device of augmented reality studio | |
| WO2023024441A1 (en) | Model reconstruction method and related apparatus, and electronic device and storage medium | |
| JP2019091436A (en) | Classification of 2d image according to type of 3d arrangement | |
| US20240203030A1 (en) | 3d model rendering method and apparatus, electronic device, and storage medium | |
| CN117218266B (en) | 3D white model texture map generation method, device, equipment and medium | |
| US20240161391A1 (en) | Relightable neural radiance field model | |
| CN118710670A (en) | Multi-angle contour point extraction method and storage medium based on 3D engine | |
| WO2019042028A1 (en) | All-around spherical light field rendering method | |
| CN106997366B (en) | Database construction method, augmented reality fusion tracking method and terminal equipment | |
| CN112085855B (en) | Interactive image editing method, device, storage medium and computer equipment | |
| CN118570351A (en) | Model processing method, device, equipment and storage medium | |
| CN118555352A (en) | Video generation method, device, computer equipment and storage medium | |
| CN108846897B (en) | Three-dimensional model surface material simulation method and device, storage medium and electronic equipment | |
| CN116977539A (en) | Image processing methods, devices, computer equipment, storage media and program products | |
| US20250363741A1 (en) | Depth rendering from neural radiance fields for 3d modeling | |
| CN115482341B (en) | Method, electronic device, program product and medium for generating mirage image | |
| US11210849B2 (en) | System for procedural generation of braid representations in a computer image generation system | |
| Xie | Dance Performance in New Rural Areas Based on 3D Image Reconstruction Technology |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication |