Gemstone measurement method, device, equipment and medium based on target edge tracking

By preprocessing the gem image and extracting the target contour, combining weight kernel calculation and sub-contour fitting, the existing gem measurement methods are solved, and efficient and accurate gem measurement is achieved.

CN119762570APending Publication Date: 2025-04-04SHENZHEN JIEENSHI INTELLIGENT TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411928420.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-25
Publication Date
2025-04-04

AI Technical Summary

Technical Problem

The existing gem measurement methods are inefficient, difficult to guarantee accuracy, and poor repeatability, which cannot meet the gem industry's demand for high-precision measurement.

Method used

Using a gem measurement method based on target edge tracking, the image is preprocessed, the target contour is extracted, the contour features are calculated using the weight kernel, the effective contour is filtered and segmented into subcontours, and the subcontours are fitted to obtain gem size data.

Benefits of technology

Automatic measurement is realized, measurement efficiency, accuracy and stability are improved, and physical parameters of gemstones can be accurately obtained.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119762570A_ABST
    Figure CN119762570A_ABST
Patent Text Reader

Abstract

The present application relates to the field of data processing technology, and in particular to a gemstone measurement method, device, equipment and medium based on target edge tracking, wherein the method comprises: preprocessing a current image to obtain a preprocessed image; extracting a target contour based on the preprocessed image; calculating the weight of each pixel in the target contour by a weight kernel to obtain contour features; screening effective contours according to contour features, and dividing the effective contours into multiple sub-contours; fitting each sub-contour, and obtaining gemstone size data based on fitting information. The present application can greatly improve the measurement efficiency and measurement accuracy in the gemstone measurement process.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data processing, and in particular to a gemstone measurement method, device, equipment and medium based on target edge tracking. Background Art

[0002] Gemstone size measurement technology mainly involves the precise determination of the physical parameters of gemstones to meet the needs of the jewelry industry, scientific research and industrial applications. Gemstones, including but not limited to diamonds, crystals, emeralds, rubies, sapphires, etc., are widely used in many fields due to their beautiful color and high hardness. In the jewelry industry, parameters such as the size, weight, and density of gemstones are crucial for their value assessment and classification. At present, the measurement of gemstone size mainly relies on traditional manual measurement methods, such as the use of calipers and other tools. The manual measurement method requires manual picking up of gemstones for measurement, which is not only inefficient, but also affects the accuracy of the measurement because the fingers may block the values ​​on the scale. For smaller gemstones, manual measurement is difficult to ensure accuracy and has poor repeatability, which is a major defect for the gemstone industry that requires high-precision measurement.

[0003] Therefore, the existing gemstone measurement methods have low measurement efficiency, difficulty in ensuring accuracy, and poor repeatability, which need to be solved urgently. Summary of the invention

[0004] The main purpose of this application is to provide a gemstone measurement method, device, equipment and medium based on target edge tracking, aiming to solve the technical problems of low measurement efficiency, difficulty in ensuring accuracy and poor repeatability of existing gemstone measurement methods.

[0005] In order to achieve the above-mentioned invention object, the present application proposes a gemstone measurement method based on target edge tracking, the method comprising:

[0006] Preprocessing the current image to obtain a preprocessed image;

[0007] Extracting a target contour based on the preprocessed image;

[0008] Calculating the weight of each pixel in the target contour by using a weight kernel to obtain a contour feature;

[0009] Screening a valid contour according to contour features, and dividing the valid contour into a plurality of sub-contours;

[0010] Fit each sub-contour and obtain the gemstone size data based on the fitting information.

[0011] Furthermore, the step of preprocessing the current image to obtain a preprocessed image includes:

[0012] Use the binarization method to extract the foreground information of the current image, eliminate useless background and remove noise;

[0013] Gaussian filtering is performed on the binarized image to smooth the edge of the target and obtain the preprocessed image.

[0014] Furthermore, the step of extracting the target contour based on the preprocessed image comprises:

[0015] Extracting the outer contour of the preprocessed image using the Suzuki85 boundary tracking algorithm;

[0016] identifying the number of contour points in the outer contour;

[0017] If the number of contour points is less than a preset number threshold, it is determined to be a spot contour;

[0018] Eliminating the spot outline to obtain an outline containing the gemstone outline;

[0019] The outline including the gemstone outline is converted into a grayscale image for storage to obtain the target outline.

[0020] Furthermore, the step of converting the outline containing the gemstone outline into a grayscale image for storage to obtain the target outline comprises:

[0021] Calculate the minimum value of the x and y coordinates of all the outline pixels of the outline containing the gemstone outline as the offset of the outline relative to the upper left corner of the image;

[0022] Determine the height and width of the grayscale image by finding the maximum x and y coordinates of the contour pixels;

[0023] The outline including the gemstone outline is written into a grayscale image based on the height and width to obtain the target outline.

[0024] Furthermore, the step of calculating the weight of each pixel in the target contour by using a weight kernel to obtain contour features includes:

[0025] Determine the top vertex coordinates of the target contour, and divide the contour into a left contour and a right contour based on the corresponding vertex coordinates;

[0026] Starting from the vertex coordinates, traverse along the left contour and the right contour respectively, and for the point P on the corresponding contour, use the weight kernel to calculate its weight; wherein the weight kernel is a matrix with m rows and n columns, and the value of each element in the weight kernel represents the weight of the position of the element;

[0027] With point P as the center, the weight kernel is placed on the image as a sliding window, and the weight kernel elements corresponding to the pixels on the corresponding contour are summed to obtain the weight of point P;

[0028] The weights of all points on the left contour and the right contour are respectively constructed into a left contour feature sequence and a right contour feature sequence, thereby obtaining the contour features.

[0029] Furthermore, the step of screening a valid contour according to contour features and dividing the valid contour into a plurality of sub-contours comprises:

[0030] The value range of the weight is divided into multiple sub-intervals, so that the contour coordinates of the weights belonging to the same sub-interval have the characteristic of similar contour directions in the neighborhood, and a valid contour is obtained;

[0031] For each weight, the average of the weights in the neighborhood of the contour coordinates is used as a new weight to replace the original weight;

[0032] According to the adjacency relationship of contour coordinates and the interval to which the weight belongs, the effective contour is segmented to obtain the corresponding target contour segmentation information;

[0033] Based on the target contour segmentation information, any isomorphic target contour is extracted and parsed to obtain various sub-contours.

[0034] Furthermore, the step of fitting each sub-contour and obtaining gemstone size data according to the fitting information includes:

[0035] Fitting straight lines respectively using the contour point coordinate sets corresponding to each sub-contour to obtain the fitting lines of each sub-contour;

[0036] Find the intersection points of adjacent sub-contour fitting lines;

[0037] The gemstone size data is calculated based on the information of the intersection points of each sub-contour fitting line and the adjacent sub-contour fitting lines.

[0038] The second aspect of the present application provides a gemstone measuring device based on target edge tracking, comprising:

[0039] A preprocessing module, used for preprocessing the current image to obtain a preprocessed image;

[0040] An extraction module, used for extracting a target contour based on the preprocessed image;

[0041] A calculation module, used for calculating the weight of each pixel in the target contour through a weight kernel to obtain contour features;

[0042] A segmentation module, used for screening effective contours according to contour features, and segmenting the effective contours into a plurality of sub-contours;

[0043] The fitting module is used to fit each sub-contour and obtain gemstone size data based on the fitting information. The third aspect of the present application also includes a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of any of the above methods when executing the computer program.

[0044] The fourth aspect of the present application also includes a computer-readable storage medium having a computer program stored thereon, wherein the computer program implements the steps of any of the above methods when executed by a processor.

[0045] Beneficial Effects

[0046] The present application proposes a new target contour feature representation, namely a weight sequence. This feature representation is simple and efficient, and can effectively describe and distinguish the various measurement parts on the target contour in one-dimensional space. The gemstone measurement method based on target edge tracking obtains the measurement results from the target image and realizes automatic measurement without human intervention, which greatly improves the measurement efficiency and ensures the measurement accuracy and stability. BRIEF DESCRIPTION OF THE DRAWINGS

[0047] Figure 1 A schematic flow chart of a gemstone measurement method based on target edge tracking according to an embodiment of the present application;

[0048] Figure 2 This is a schematic block diagram of the structure of a gemstone measuring device based on target edge tracking according to an embodiment of the present application;

[0049] Figure 3 A schematic diagram of a pre-processed image according to an embodiment of the present application;

[0050] Figure 4 This is a schematic diagram of a gemstone outline with noise according to an embodiment of the present application;

[0051] Figure 5 A schematic diagram of the contour features of an embodiment of the present application;

[0052] Figure 6 This is a schematic diagram of the interval division of an embodiment of the present application;

[0053] Figure 7 This is a schematic diagram of a contour fitting result of an embodiment of the present application;

[0054] Figure 8 A schematic block diagram of the structure of a computer device according to an embodiment of the present application.

[0055] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION

[0056] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0057] It will be understood by those skilled in the art that, unless expressly stated, the singular forms "one", "above", and "the" used herein may also include plural forms. It should be further understood that the term "comprising" used in the specification of the present invention refers to the presence of features, integers, steps, operations, elements, modules, and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, modules, components, and / or groups thereof. It should be understood that when an element is said to be "connected" or "coupled" to another element, it may be directly connected or coupled to the other element, or there may be an intermediate element. In addition, the "connection" or "coupling" used herein may include wireless connection or wireless coupling. The term "and / or" used herein includes all or any module and all combinations of one or more associated listed items.

[0058] It will be understood by those skilled in the art that, unless otherwise defined, all terms (including technical and scientific terms) used herein have the same meaning as generally understood by those skilled in the art in the art to which the present invention belongs. It should also be understood that terms such as those defined in general dictionaries should be understood to have meanings consistent with the meanings in the context of the prior art, and will not be interpreted with idealized or overly formal meanings unless specifically defined as herein.

[0059] Reference Figure 1 The embodiment of the present invention provides a gemstone measurement method based on target edge tracking, including steps S1-S6, specifically:

[0060] S1, preprocessing the current image to obtain a preprocessed image;

[0061] S2, extracting the target contour based on the preprocessed image;

[0062] S3, calculating the weight of each pixel in the target contour by a weight kernel to obtain contour features;

[0063] S4, screening effective contours according to contour features, and dividing the effective contours into multiple sub-contours;

[0064] S5. Fit each sub-contour and obtain gemstone size data based on the fitting information.

[0065] As described in step S1 above, the purpose is to ensure the accuracy and efficiency of subsequent contour extraction and feature analysis by performing a series of preprocessing operations on the current image. Specifically, the preprocessing process includes the following key operations:

[0066] First, the original image is processed using a binarization method to extract the foreground information (i.e., gemstones) in the image, while eliminating useless background and removing noise. Binarization is the process of converting a color or grayscale image into a black and white image. By setting a threshold, the part of the image that belongs to the gemstone is marked as white (pixel value 255) and the background is marked as black (pixel value 0). This step helps to remove information in the image that is not related to measurement and focus on the gemstone area.

[0067] Next, after binarization, in order to offset the over-sharpening of edges that may be caused by binarization and maintain the stability of the target edge, Gaussian filtering is applied to the binarized image. Gaussian filtering is a common smoothing filter that can effectively reduce noise in the image while maintaining the continuity and integrity of the edge. By performing Gaussian filtering on the binary image, the image quality can be further optimized to ensure that the subsequent contour tracking algorithm can more accurately capture the true contour of the gemstone.

[0068] In summary, the implementation process of step S1 not only clarifies the boundary between the measurement target and the background through the binarization method, but also uses Gaussian filtering to achieve the effect of smoothing the target edge and smooth transition, and finally obtains a clean, high-contrast and low-noise preprocessed image. Figure 3 As shown in the figure, the preprocessed image lays a solid foundation for the subsequent target contour extraction. This series of operations work together to ensure that the extracted gemstone contour is both accurate and clear, thus supporting the subsequent gemstone measurement process based on target edge tracking.

[0069] As described in step S2 above, the purpose is to accurately extract the target contour of the gemstone from the preprocessed image. Specifically, the process includes the following key operations:

[0070] First, the outer contour of the pre-processed image is extracted using the Suzuki85 boundary tracking algorithm. The Suzuki85 algorithm can generate one or more coordinate sequences, each of which represents an independent contour on the image. Through the application of this algorithm, the outer boundary of the gemstone in the pre-processed image can be effectively captured, ensuring that the basic data for subsequent analysis is accurate.

[0071] Next, the number of contour points in the extracted contour is identified to distinguish the gemstone contour from possible spot contours. In order to exclude small independent spots (such as noise or irrelevant image features), a threshold (e.g., 200 contour points) is set. When the number of contour points is less than the threshold, it is determined to be a spot contour and is directly eliminated; on the contrary, if the number of contour points exceeds or equals the threshold, the contour is considered to belong to the gemstone contour and is retained. This process ensures that only those contours with sufficient length and continuity are retained for further analysis, thereby improving the accuracy of the measurement. For valid contours that are confirmed to contain gemstone contours, they are converted into grayscale images for storage, that is, for a given grayscale image, the grayscale image size is set to the given contour size, and then the contour is filled into the grayscale image as the target contour image for subsequent processing. The specific steps are as follows: First, calculate the coordinate offset of the contour image, and take the minimum x-coordinate value Xmin and the minimum y-coordinate value Ymin of the contour pixels as the contour coordinate offset Offset (Offset = (Xmin, Ymin)); then determine the size of the grayscale image: find the maximum x and y coordinates of the contour pixels to determine the height (Rows = Ymax-Ymin) and width (Cols = Xmax-Xmin) of the grayscale image. Corresponding to rows and columns respectively. Then write the contour into the grayscale image: For a given grayscale image with a height of Rows rows and a width of Cols columns, the method of writing a given contour into a given grayscale image is: for each pixel of a given grayscale image, if the pixel coordinate is included in the new contour coordinate sequence obtained by subtracting the contour coordinate offset from each coordinate of the given contour coordinate sequence, then set the pixel value to 255, otherwise it has no value and takes 0. This step can also be described as: Let M{(x, y)|0≤x<Cols, 0≤y<Rows} represent a given grayscale image, M xy is the pixel value of the yth row and xth column in the grayscale image M. NP{(x, y)} represents the new coordinate set obtained by subtracting the contour image coordinate offset Offset obtained in step S2-3-1 from each pixel coordinate on the contour. Then, when (x, y)∈NP, M xy =255, when Time xy = 0. The contour obtained in step S2-2 is written into the grayscale image according to the method described in this step to obtain the target contour map. The extracted target contour map is as follows Figure 4 shown.

[0072] In summary, step S2 realizes the process of accurately extracting the target gemstone contour from the preprocessed image by applying the Suzuki85 boundary tracking algorithm to the preprocessed image, identifying and removing the spot contour, and converting the effective contour into a grayscale image. These operations work together to ensure that the extracted gemstone contour is both complete and clear, providing a reliable data basis for the subsequent weight calculation and size measurement based on contour features.

[0073] As described in step S3 above, the purpose is to extract information that can characterize the gemstone contour features by using a weight kernel to calculate the weight of each pixel in the target contour. Specifically, the process includes the following key operations: First, determine the top vertex coordinates of the target contour. This vertex can divide the entire contour into two parts, namely the left contour and the right contour. This step is crucial for the subsequent processing of the two side contours separately.

[0074] Then, starting from the vertex, traverse along the left contour and the right contour respectively. For each point P on the contour encountered during the traversal, use the weight kernel (a matrix with m rows and n columns) to calculate its weight. The design of the weight kernel places special emphasis on the sensitivity to specific directions (such as ±45°), and also responds to the horizontal and vertical directions, but the impact is smaller. For example: use the given 3x3 weight kernel to calculate its weight, and obtain the left weight sequence and the right weight sequence of the contour as the left contour feature and the right contour feature respectively. After the left and right contour features are spliced ​​and connected end to end, they become the complete contour feature. The extracted contour features are as follows: Figure 5 As shown, the feature x-coordinate is the contour point number, the y-coordinate is the weight of the contour point under the number, the y-coordinate is, there are four segments from top to bottom, the horizontal line on each segment is the 0-value reference line, there is a floating point rounding error between the image value and the actual value, and there is a difference with the actual value; the four segments from top to bottom are the original feature of the right side contour of the vertex, the feature after preprocessing of the right side contour of the vertex, the original feature of the left side contour of the vertex, and the feature after preprocessing of the left side contour of the vertex.

[0075] Next, the weight kernel is placed on the image as a sliding window with point P as the center. The weight kernel elements corresponding to the pixels on the contour are summed to get the weight of point P. If an element in the weight kernel corresponds to a pixel not on the contour, the weight of the element is not included in the sum. Specifically, for a given contour point coordinate, the weight calculation method is as follows:

[0076]

[0077] Among them, ω is the weight, I is the contour image, I yx is the pixel value of the yth row and xth column of the contour image, R w is the number of convolution kernel rows, C w is the number of convolution kernel columns, W rc is the value of the convolution kernel in the rth row and cth column.

[0078] The following 3x3 weight kernel is used in this implementation:

[0079]

[0080] The main characteristics of the above weight kernel are: the weight of the extremely prominent ±45° tilt direction point, the weight in the +45° direction tends to be 10, and the weight in the -45° direction tends to be -10. On this basis, the weight will be slightly weakened or enhanced when tilted horizontally and vertically; the weight value range is [-14,12]. The left and right contour splicing method is as follows:

[0081] S i =L n-i-1

[0082] S n+j =R j

[0083] Wherein, S is a cyclic sequence, which represents the overall features of the contour, L is the left contour feature, R is the right contour feature, n is the number of left contour feature weights, i and j are the serial numbers of the left and right contour feature weights starting from zero. Subsequently, the weights of all points on the left contour and the right contour are respectively constructed into the left contour feature sequence and the right contour feature sequence, that is, the contour features are obtained. The purpose of this is to ensure that the left and right contour features can coherently represent the geometric characteristics of the entire gemstone contour. In summary, step S3 realizes the effective conversion from contour to feature by using the weight kernel to calculate the weight of each pixel in the target contour and constructing the corresponding feature sequence. This process not only simplifies the subsequent analysis, but also effectively captures the key geometric information of the gemstone contour, providing a solid foundation for the subsequent sub-contour segmentation and size measurement.

[0084] As described in step S4 above, first, the value range of the weight is divided into multiple sub-intervals, so that the contour coordinates whose weights belong to the same sub-interval have the characteristic of similar contour directions in the neighborhood; specifically, given contours C1, C2, and C3, where C1 and C2 are the same sub-contours of isomorphic measurement targets on different images, and C3 is a sub-contour adjacent to the C1 sub-contour of any isomorphic measurement target, then the contour directions of C1 and C2 are similar, but different from the contour direction of C3. In this way, possible valid contour parts can be preliminarily screened out. For each weight, the average of the weights in the neighborhood of the contour coordinates is used as the new weight to replace the original value, that is, Where ω is the weight, N is the neighborhood size, which is an odd number, ω iis the i-th weight in the neighborhood; based on the contour coordinate adjacency relationship and the weight interval, the contour is segmented. For two given points P1 and P2 on the contour, if P1 and P2 are adjacent and their weights belong to the same interval, the two points belong to the same segment, otherwise they belong to two segments; for a given segment D and a point P on the contour, if point P is adjacent to any point in segment D and point P and the points in segment D belong to the same interval, then point P belongs to segment D, otherwise it does not belong; the adjacency here is defined as: given two points P1 and P2 on the image, if P1 is within the 8-neighborhood range of P2, then P1 and P2 are adjacent. This process ensures that only those contour parts that are similar in geometric features (such as direction) are combined together, thereby excluding incoherent or abnormal contour segments. For a given standard target contour, based on the above steps and in combination with the sub-contour splitting scheme specified by the measurement requirements, the corresponding target contour segmentation information can be obtained, and the segmentation combination of each sub-contour can be known. According to the segmentation combination of each sub-contour of the standard target contour, any isomorphic target contour can be extracted and analyzed to obtain its sub-contours. Each segment represents a weight interval, and each sub-contour has multiple segments, that is, each sub-contour has multiple weight intervals. The weight intervals of each segment within the sub-contour are arranged in the order of the segments to form the segmentation combination of the sub-contour. The "isomorphic" here refers to contours with similar shapes or the same geometric structure.

[0085] Specifically, based on the left and right contour features obtained in step S3, two 9-neighborhood one-dimensional mean filters are used for smoothing; the value range of the feature weight is divided into 10 equally spaced intervals, each interval corresponds to an angle range, and points belonging to the same interval have the same angle tendency. The intervals are numbered from small to large according to (0ˉ9), and each weight of the contour feature belongs to a certain interval, that is, each point on the contour tends to a certain angle; in this way, the contour points represented by each weight of the contour feature can be further classified using the interval, and adjacent points belonging to the same category are merged to obtain an interval sequence. It can be seen that each member of the interval sequence represents a point or multiple continuous points on the contour. In the obtained interval sequence, due to different image stability, there is a special interval whose left and right adjacent intervals are of the same type. In this case, if there is a special interval with the same type of left and right adjacent intervals, and the number of contour points of the special interval is lower than the preset threshold, the special interval is merged into the left interval and the right interval, and the three intervals are merged, for example, when the number of contour points of the special interval is less than 3, the interval is merged. This processing method can remove small fragments caused by noise or other interference, and further optimize the continuity and rationality of the contour. Figure 6The result of the interval division of the contour in this step is shown as a schematic diagram, with different intervals marked with different colors. It can be seen from the weight kernel given in step S3 that a sequence of continuous points on the same straight line on the image is given as the contour, and each point on the contour is weighted to obtain a weight sequence as the contour feature. After the mean filtering of this contour feature, the weights belong to the same interval or adjacent intervals, and for the continuous point sequence on the horizontal, vertical, and different degrees of inclination straight line, the interval to which the weight belongs fluctuates around a certain interval. Using the weight kernel characteristics and combining the contour image characteristics, it can be known that the feature interval sequence that conforms to the gemstone contour is matched. The contour feature interval sequence is matched in the interval sequence, and the effective contour can be extracted from the noisy contour. According to the weight difference of the inclination points at different angles, the contour can be divided into multiple sub-contours, and each sub-contour represents a line segment on the overall gemstone contour.

[0086] In summary, step S4 ensures that the final result is a valid contour after careful screening by effectively eliminating invalid contours and reasonably segmenting the contours. These sub-contours not only meet specific conditions (such as consistent direction, sufficient length, etc.), but also provide a reliable basis for subsequent fitting and size calculation. This series of operations work together to ensure that the extracted contours are both accurate and clear, supporting the efficiency and high precision of the entire gemstone measurement method.

[0087] As described in step S5 above, step S4 has divided the contour into multiple sub-contours, and used the contour point coordinate sets corresponding to each sub-contour to fit straight lines respectively, to obtain the fitting lines of each sub-contour in the contour. The line connecting the intersection points of each adjacent sub-contour straight line represents the contour itself. Based on the intersection information of each sub-contour fitting line and the adjacent sub-contour fitting line, it is easy to find the required size information, such as the specified sub-contour length, contour width, height, and gem crown height. For the obtained size data, multiply it by the camera accuracy to get the physical size of the gem. The contour fitting result is as follows: Figure 7 As shown, the top horizontal line is the vertex position plus a vertical offset.

[0088] Based on steps S1-S6, this scheme proposes a new target contour feature representation, namely a weight sequence. This feature representation is simple and efficient, and can effectively describe and distinguish the various measurement parts on the target contour in one-dimensional space. The gemstone measurement method based on target edge tracking obtains the measurement results from the target image and realizes automatic measurement without human intervention, which greatly improves the measurement efficiency and ensures the measurement accuracy and stability.

[0089] In one embodiment, the step of preprocessing the current image to obtain a preprocessed image includes:

[0090] S10, using a binarization method to extract the foreground information of the current image, eliminate useless background and remove noise;

[0091] S11, performing Gaussian filtering on the binarized image to smooth the edge of the target and obtain the preprocessed image.

[0092] In this embodiment, first, the original image is converted into a black and white image by applying a binarization method. This process distinguishes the foreground (i.e., gemstone) and background in the image by setting a threshold. Specifically, the gemstone part is marked as white (pixel value 255), while the background part is marked as black (pixel value 0). This step not only extracts the foreground information of the image, but also effectively eliminates the irrelevant background and preliminarily removes the noise in the image, ensuring that subsequent processing is more focused on the target object. Next, in order to reduce the edge sharpening problem that may be introduced by binarization and maintain the stability and continuity of the target edge, Gaussian filtering is applied to the binarized image. Gaussian filtering is a common smoothing filter that can effectively reduce the noise in the image while retaining the main features of the edge. By performing Gaussian filtering on the binary image, the image quality can be further optimized to ensure that the contour tracking algorithm can more accurately capture the true contour of the gemstone.

[0093] In one embodiment, the step of extracting the target contour based on the preprocessed image comprises:

[0094] S20, extracting the outer contour of the preprocessed image using the Suzuki85 boundary tracking algorithm;

[0095] S21, identifying the number of contour points in the outer contour;

[0096] S22, if the number of contour points is less than a preset number threshold, determine it as a spot contour;

[0097] S23, removing the spot outline to obtain an outline including the gemstone outline;

[0098] S24, converting the outline including the gemstone outline into a grayscale image for storage to obtain the target outline.

[0099] In this embodiment, first, the Suzuki85 boundary tracking algorithm is applied to extract the outer contour of the preprocessed image. The Suzuki85 algorithm is a classic contour extraction method, which can generate one or more coordinate sequences, each of which represents an independent contour on the image. Through the application of this algorithm, the outer boundary of the gem in the preprocessed image can be effectively captured to ensure that the basic data for subsequent analysis is accurate. Next, the number of contour points in the extracted contour is counted. This process is to distinguish the gem contour from the possible spot contour (such as noise or other irrelevant features). By counting the number of contour points, a basis is provided for the next step of screening. A threshold value for the number of contour points (for example, 200 pixels) is set. If the number of points of a certain contour is less than this threshold, it is determined to be a spot contour. These spot contours are usually caused by noise or other irrelevant image features, so they need to be eliminated to avoid interfering with subsequent measurement and analysis. For those parts that are determined to be spot contours, they are directly eliminated. On the contrary, those valid contours whose number of contour points exceeds or equals the threshold are retained. This step ensures that only contours with sufficient length and continuity are retained for further analysis, thereby improving the accuracy of measurement. Finally, the valid outline confirmed to contain the gemstone outline is converted into a grayscale image for storage (the specific processing method is described in step S2) to facilitate subsequent processing.

[0100] In one embodiment, the step of converting the outline containing the gemstone outline into a grayscale image for storage to obtain the target outline comprises:

[0101] S30, calculating the minimum value of the x and y coordinates of all the outline pixels of the outline including the gemstone outline as the offset of the outline relative to the upper left corner of the image;

[0102] S31, determining the height and width of the grayscale image by finding the maximum x and y coordinates of the outline pixels;

[0103] S32. Writing the outline including the gemstone outline into a grayscale image based on the height and width to obtain the target outline.

[0104] In this embodiment, first, it is necessary to calculate the minimum x-coordinate and y-coordinate of all contour pixels containing the gemstone contour. This step is to determine the offset of the contour relative to the upper left corner of the image. By finding the minimum x-coordinate (Xmin) and the minimum y-coordinate (Ymin) of all contour points, the position of the contour in the entire image can be determined. This offset will be used to adjust the position of the contour points in the subsequent steps so that they can be correctly represented in the new grayscale image. Next, find the maximum x-coordinate (Xmax) and the maximum y-coordinate (Ymax) of the contour pixels. With this information, the height (Rows=Ymax-Ymin+1) and width (Cols=Xmax-Xmin+1) of the newly created grayscale image can be determined. Adding 1 here is to ensure that the pixels at the edge can also be included. In this way, we can get a grayscale image of the minimum size suitable for storing the gemstone contour. Finally, a new grayscale image is created based on the height and width calculated above, and the contour containing the gemstone contour is written into it. Specifically: a new grayscale image is created, and its size is set according to the height and width calculated in S31. For each pixel, if its coordinates (coordinates after deducting the offset) exist in the given gemstone outline coordinate sequence, the pixel is set to white (for example, the pixel value is set to 255), indicating that the pixel belongs to the gemstone outline; otherwise, it is set to black (for example, the pixel value is set to 0), indicating the background or non-outline part. In this way, the final grayscale image only contains the gemstone outline, and the outline is clearly visible, which is convenient for subsequent processing and analysis.

[0105] In one embodiment, the step of calculating the weight of each pixel in the target contour by using a weight kernel to obtain the contour feature includes:

[0106] S40, determining the top vertex coordinates of the target contour, and dividing the contour into a left contour and a right contour based on the corresponding vertex coordinates;

[0107] S41, starting from the vertex coordinates, traverse along the left contour and the right contour respectively, and for the point P on the corresponding contour, use the weight kernel to calculate its weight; wherein the weight kernel is a matrix with m rows and n columns, and the value of each element in the weight kernel represents the weight of the position of the element;

[0108] S42, with point P as the center, the weight kernel is placed on the image as a sliding window, and the weight kernel elements corresponding to the pixels located on the corresponding contour are summed to obtain the weight of point P;

[0109] S43, constructing the weights of all points on the left contour and the right contour into a left contour feature sequence and a right contour feature sequence respectively, so as to obtain the contour features.

[0110] In this embodiment, first, the top vertex coordinates of the target contour are identified and determined. This vertex is the highest point of the entire contour, and it naturally divides the contour into two parts, i.e., the left contour and the right contour. This step is crucial for the subsequent processing of the contours on both sides, ensuring the accuracy of the weight calculation. Then, starting from the vertex coordinates, traverse along the left contour and the right contour respectively. For each point P on the contour encountered during the traversal process, a weight kernel (a matrix with m rows and n columns) is used to calculate its weight. The design of the weight kernel particularly emphasizes the sensitivity to a specific direction (such as ± 45°), and also responds to the horizontal and vertical directions, but the effect is small. Then, with point P as the center, the weight kernel is placed on the image as a sliding window. The weight kernel elements corresponding to the pixels on the contour are summed to obtain the weight of point P. Specifically, if an element in the weight kernel corresponds to a pixel not on the contour, the weight of the element is not included in the sum. Finally, the weights of all points on the left contour and the right contour are constructed into a left contour feature sequence and a right contour feature sequence respectively. This means that the weights calculated for each point on the left contour form a sequence, and similarly, the weights calculated for each point on the right contour also form a sequence. These two feature sequences together constitute the complete contour feature for subsequent analysis and processing.

[0111] In one embodiment, the step of screening a valid contour according to contour features and dividing the valid contour into a plurality of sub-contours comprises:

[0112] S50, dividing the value range of the weight into multiple sub-intervals, so that the contour coordinates of the weights belonging to the same sub-interval have the characteristic of similar contour directions in the neighborhood, and obtaining a valid contour;

[0113] S51, for each weight, using the average of the weights in the neighborhood of the contour coordinates as a new weight to replace the original weight;

[0114] S52, segmenting the effective contour according to the contour coordinate adjacency relationship and the weight interval to obtain the corresponding target contour segmentation information;

[0115] S53: extract any isomorphic target contour based on the target contour segmentation information, and parse to obtain each sub-contour.

[0116] In this embodiment, first, the value range of the weight is divided into multiple sub-intervals. This division is to ensure that the contour coordinates of the same sub-interval have similar directional characteristics, that is, these points show consistent or similar contour trends in the local range. In this way, possible valid contour parts can be preliminarily screened out, and those contour segments with incoherent or sudden changes in direction can be excluded, thereby improving the accuracy of subsequent analysis. Then, each weight is smoothed. Specifically, the average value of the weights in the neighborhood of the contour coordinates (for example, 9 neighborhoods) is used to replace the original weight. This step helps to reduce noise interference and optimize the quality of the contour data, making the contour smoother and continuous, which is convenient for subsequent segmentation operations. Then, based on the adjacency relationship between the contour coordinates and the weight intervals to which they belong, the effective contour is segmented. Specifically: if the weights of two adjacent points P1 and P2 belong to the same interval, the two points are classified as the same segment; otherwise, they belong to different segments.

[0117] For a given segment D and a point P on the contour, if point P is adjacent to any point in segment D and the weights of the two points belong to the same interval, then point P belongs to segment D; otherwise, it does not belong. The adjacency here is defined as: given two points P1 and P2 on the image, if P1 is within the 8-neighborhood range of P2, then P1 and P2 are adjacent. This process ensures that only those contour parts that are similar in geometric features (such as direction) are combined together, thereby excluding incoherent or abnormal contour segments. Finally, based on the above segmentation information, any isomorphic target contour is extracted and parsed to obtain each sub-contour. The specific method is: for a given standard target contour, combined with the sub-contour splitting scheme specified by the measurement requirements, the logic in the above steps S50 to S52 is executed to obtain the segmentation information of the corresponding target contour and the segmentation combination of its each sub-contour. Based on the segmentation combination of each sub-contour of the standard target contour, any isomorphic target contour can be extracted and parsed to obtain its each sub-contour. Each segment represents a weight interval, and each sub-contour has multiple segments, that is, each sub-contour has multiple weight intervals. The weight intervals of each segment in the sub-contour are arranged in the order of segments to form the segment combination of the sub-contour.

[0118] Through this embodiment, it is possible to screen out effective contour parts from complex contour data and reasonably divide them into multiple sub-contours that are easy to analyze and process. This process not only improves the quality of contour data, but also enhances the accuracy and reliability of subsequent size calculations. The entire step ensures that the extracted sub-contours not only meet specific conditions (such as consistent direction, sufficient length, etc.), but also can accurately reflect the true geometric characteristics of the gemstone, supporting the efficiency and high precision of the entire gemstone measurement method.

[0119] In one embodiment, the step of fitting each sub-contour and obtaining gemstone size data based on the fitting information includes:

[0120] S60, fitting straight lines respectively using the contour point coordinate sets corresponding to the sub-contours to obtain fitting lines for the sub-contours;

[0121] S61, finding the intersection points of adjacent sub-contour fitting lines;

[0122] S62, calculating gemstone size data based on information of intersections of each sub-contour fitting line and adjacent sub-contour fitting lines.

[0123] In this embodiment, first, for each sub-contour, a straight line fitting is performed using its corresponding set of contour point coordinates. Specifically, the least squares method or other suitable fitting algorithms are used to process the points on each sub-contour to find a straight line that can best represent the distribution trend of these points. This step is intended to simplify the geometric features of the sub-contour and provide a basis for subsequent intersection calculations. Next, the intersection points of adjacent sub-contour fitting lines are calculated. By using analytical geometry methods, two sets of fitting line equations are solved to determine their intersection coordinates. These intersection points represent the key geometric features of the original contour, such as vertices, inflection points, etc., which are crucial for understanding the overall shape and size of the gemstone. Finally, based on the information of the intersection points of each sub-contour fitting line and the adjacent sub-contour fitting line, the size data of the gemstone is calculated. The specific calculation content includes but is not limited to:

[0124] Specify sub-contour length: Measures the length of a specific sub-contour.

[0125] Contour width: obtained by calculating the shortest distance between the corresponding sub-contour fitting lines on both sides.

[0126] Profile height: Usually determined by the distance from the vertex position to the base.

[0127] Gemstone crown height: For gemstones with obvious layered structures (such as diamonds), the height of their crowns can be calculated.

[0128] In addition, in order to convert the size data in the image into the actual physical size, it is also necessary to multiply the above calculation results by the camera accuracy to consider the impact of image resolution or calibration parameters. This is because the size in the image is usually in pixel units, which need to be converted into real-world measurement units (such as millimeters) based on the camera resolution.

[0129] By executing this embodiment, the specific size data of the gemstone can be accurately extracted from the fitted sub-contour. This process not only improves the measurement efficiency, but also ensures the reliability and stability of the results. The entire step provides a solid foundation for efficient and high-precision measurement of gemstones.

[0130] Reference Figure 2 , is a structural block diagram of a gemstone measuring device based on target edge tracking in an embodiment of the present application, the device includes:

[0131] The preprocessing module 100 is used to preprocess the current image to obtain a preprocessed image;

[0132] An extraction module 200, configured to extract a target contour based on the preprocessed image;

[0133] A calculation module 300 is used to calculate the weight of each pixel in the target contour by using a weight kernel to obtain contour features;

[0134] A segmentation module 400 is used to select a valid contour according to contour features and segment the valid contour into a plurality of sub-contours;

[0135] The fitting module 500 is used to fit each sub-contour and obtain gemstone size data based on the fitting information.

[0136] Reference Figure 8 In an embodiment of the present application, a computer device is also provided. The computer device may be a server, and its internal structure may be as follows: Figure 8 As shown. The computer device includes a processor, an internal memory, a storage medium (non-volatile storage medium) and a network interface connected through a system bus. Among them, the processor designed by the computer is used to provide computing and control capabilities. The memory of the computer device includes the above-mentioned storage medium (non-volatile storage medium) and the internal memory. The storage medium (non-volatile storage medium) stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the storage medium (non-volatile storage medium). The database of the computer device is used to store usage data in a gemstone measurement method based on target edge tracking, etc. The network interface of the computer device is used to communicate with an external terminal through a network connection. Furthermore, the above-mentioned computer device can also be provided with an input device and a display screen, etc. When the above computer program is executed by a processor, a gemstone measurement method based on target edge tracking is implemented, including the following steps: preprocessing the current image to obtain a preprocessed image; extracting the target contour based on the preprocessed image; calculating the weight of each pixel in the target contour by a weight kernel to obtain contour features; screening the effective contour according to the contour features, and dividing the effective contour into multiple sub-contours; fitting each sub-contour, and obtaining the gemstone size data based on the fitting information. Those skilled in the art can understand that Figure 8 The structure shown in is merely a block diagram of a portion of the structure related to the present application solution and does not constitute a limitation on the computer device to which the present application solution is applied.

[0137] An embodiment of the present application also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, a gemstone measurement method based on target edge tracking is implemented, including the following steps: preprocessing the current image to obtain a preprocessed image; extracting the target contour based on the preprocessed image; calculating the weight of each pixel in the target contour by a weight kernel to obtain contour features; screening effective contours according to the contour features, and dividing the effective contours into multiple sub-contours; fitting each sub-contour, and obtaining gemstone size data based on the fitting information. It can be understood that the computer-readable storage medium in this embodiment can be a volatile readable storage medium or a non-volatile readable storage medium.

[0138] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media provided in this application and used in the embodiments may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (SSRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.

[0139] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, device, article or method including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, device, article or method. In the absence of further restrictions, an element defined by the sentence "includes a ..." does not exclude the existence of other identical elements in the process, device, article or method including the element.

[0140] The above description is only a preferred embodiment of the present application, and does not limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.

Claims

1. A gemstone measurement method based on target edge tracking, characterized in that: The method comprises: Preprocessing the current image to obtain a preprocessed image; Extracting a target contour based on the preprocessed image; Calculating the weight of each pixel in the target contour by using a weight kernel to obtain a contour feature; Screening a valid contour according to contour features, and dividing the valid contour into a plurality of sub-contours; Fit each sub-contour and obtain the gemstone size data based on the fitting information.

2. The gemstone measurement method based on target edge tracking according to claim 1, characterized in that: The step of preprocessing the current image to obtain a preprocessed image includes: Use the binarization method to extract the foreground information of the current image, eliminate useless background and remove noise; Gaussian filtering is performed on the binarized image to smooth the edge of the target and obtain the preprocessed image.

3. The gemstone measurement method based on target edge tracking according to claim 1, characterized in that: The step of extracting the target contour based on the preprocessed image comprises: Extracting the outer contour of the preprocessed image using the Suzuki85 boundary tracking algorithm; identifying the number of contour points in the outer contour; If the number of contour points is less than a preset number threshold, it is determined to be a spot contour; Eliminating the spot outline to obtain an outline containing the gemstone outline; The outline including the gemstone outline is converted into a grayscale image for storage to obtain the target outline.

4. The gemstone measurement method based on target edge tracking according to claim 3, characterized in that: The step of converting the outline containing the gemstone outline into a grayscale image for storage to obtain the target outline comprises: Calculate the minimum value of the x and y coordinates of all the outline pixels of the outline containing the gemstone outline as the offset of the outline relative to the upper left corner of the image; Determine the height and width of the grayscale image by finding the maximum x and y coordinates of the contour pixels; The outline including the gemstone outline is written into a grayscale image based on the height and width to obtain the target outline.

5. The gemstone measurement method based on target edge tracking according to claim 1, characterized in that: The step of calculating the weight of each pixel in the target contour by using a weight kernel to obtain contour features comprises: Determine the top vertex coordinates of the target contour, and divide the contour into a left contour and a right contour based on the corresponding vertex coordinates; Starting from the vertex coordinates, traverse along the left contour and the right contour respectively, and for the point P on the corresponding contour, use the weight kernel to calculate its weight; wherein the weight kernel is a matrix with m rows and n columns, and the value of each element in the weight kernel represents the weight of the position of the element; With point P as the center, the weight kernel is placed on the image as a sliding window, and the weight kernel elements corresponding to the pixels on the corresponding contour are summed to obtain the weight of point P; The weights of all points on the left contour and the right contour are respectively constructed into a left contour feature sequence and a right contour feature sequence, thereby obtaining the contour features.

6. The gemstone measurement method based on target edge tracking according to claim 1, characterized in that: The step of screening a valid contour according to contour features and dividing the valid contour into a plurality of sub-contours comprises: The value range of the weight is divided into multiple sub-intervals, so that the contour coordinates of the weights belonging to the same sub-interval have the characteristic of similar contour directions in the neighborhood, and a valid contour is obtained; For each weight, the average of the weights in the neighborhood of the contour coordinates is used as a new weight to replace the original weight; According to the adjacency relationship of contour coordinates and the interval to which the weight belongs, the effective contour is segmented to obtain the corresponding target contour segmentation information; Based on the target contour segmentation information, any isomorphic target contour is extracted and parsed to obtain various sub-contours.

7. The gemstone measurement method based on target edge tracking according to claim 1, characterized in that: The step of fitting each sub-contour and obtaining gemstone size data according to the fitting information comprises: Fitting straight lines respectively using the contour point coordinate sets corresponding to each sub-contour to obtain the fitting lines of each sub-contour; Find the intersection points of adjacent sub-contour fitting lines; The gemstone size data is calculated based on the information of the intersection points of each sub-contour fitting line and the adjacent sub-contour fitting lines.

8. A gemstone measuring device based on target edge tracking, characterized in that: include: A preprocessing module, used for preprocessing the current image to obtain a preprocessed image; An extraction module, used for extracting a target contour based on the preprocessed image; A calculation module, used for calculating the weight of each pixel in the target contour through a weight kernel to obtain contour features; A segmentation module, used for screening effective contours according to contour features, and segmenting the effective contours into a plurality of sub-contours; The fitting module is used to fit each sub-contour and obtain the gemstone size data based on the fitting information.

9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.