A method for detecting agarwood quality based on machine vision
Through the adaptive global-local optimization technology based on machine vision and the carbon line grayscale adaptive threshold, the high cost and complexity of agarwood quality detection were solved, and efficient and accurate evaluation of agarwood quality was achieved.
Patent Information
- Application Number
- CN202210582088.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-26
- Publication Date
- 2025-09-09
- Estimated Expiration
- 2042-05-26
AI Technical Summary
Existing agarwood quality testing methods are cumbersome to operate, take a long time to test, and require expensive equipment. They are not suitable for use by private agarwood enthusiasts, and there is a lack of simple and low-cost testing methods.
A machine vision-based method is used to accurately locate the carbon line and detect the ash shrinkage rate. The adaptive global-local optimization technology is used, combined with the carbon line grayscale adaptive threshold and ash shrinkage rate compensation parameters to evaluate the quality of agarwood.
It achieves efficient and accurate detection of agarwood quality, reduces detection costs, is suitable for private use, and simplifies the operating process.
Smart Images

Figure CN115018873B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of agarwood quality detection technology, and more specifically, to a method for detecting agarwood quality based on machine vision. Background Art
[0002] Agarwood, a resinous medicinal herb from the Thymelaeaceae family, is known for its properties of promoting qi and relieving pain, warming the middle and stopping vomiting, and promoting qi and relieving asthma. It is used to treat chest and abdominal distension and pain, vomiting and hiccups due to stomach cold, and shortness of breath due to kidney deficiency. There are 15 species of Aquilaria worldwide, primarily found in tropical and subtropical Southeast Asia. Agarwood is a precious, high-end spice, and its quality is graded based on factors such as size, oil content, fragrance, and color. High-purity agarwood oil can retail for up to $50 per gram in its native region and is widely used in medicine, beauty products, and religious practices. However, the quality of agarwood varies greatly, and with the scarcity of wild agarwood resources, counterfeit and inferior products are circulated in the market. Therefore, developing a method to identify the quality of agarwood is crucial for both quality grading and the agarwood industry. Currently, the main methods for grading agarwood quality include chemical composition analysis, chromatography, and spectroscopy. However, these methods are cumbersome, time-consuming, and require expensive equipment, making them unsuitable for individual agarwood enthusiasts. So far, there is no method that has a simple detection process, low detection cost, and does not require the purchase of expensive equipment.
[0003] By consulting the data, it was found that the four effective active ingredients with higher concentrations that are unique to agarwood are 2-(2-phenylethyl) chromone, 6,7-dimethoxy-2-(2-phenylethyl) chromone, 6,7-dimethoxy-2-[2-(4'-methoxyphenyl)ethyl] chromone and agarwood tetraol. Obviously, the content and proportion of the effective active ingredients unique to agarwood in wild agarwood, counterfeit agarwood and inferior agarwood are different. When the content and proportion of these effective active ingredients are different, the characteristics of the ash shrinkage and carbon line height during the burning of agarwood will show different results. Then, by manual painting, the ash shrinkage and carbon line height can be specifically and quantitatively determined. Therefore, the quality of agarwood can be reflected by the ash shrinkage, carbon line height and other characteristics. Next Figure 1 The image shows a burning agarwood incense. Arrow 1 points to the ash, arrow 2 points to the carbon line, and arrow 3 points to the cracks that may appear during burning. Manually capturing parameters such as ash shrinkage and carbon line height is both time-consuming and laborious.
[0004] A patented method for identifying the authenticity of agarwood using fluorescence spectral imaging technology is currently available. This patented method obtains a spectral cube of authentic, untouched agarwood, performs data analysis, extracts spectral features, and establishes a standard agarwood database. The method then performs a full-band scan of the agarwood sample from 450nm to 950nm, collects the spectral cube, performs data correction, and obtains spectra in regions of interest. The characteristic spectrum of the sample is then extracted and matched with spectra of authentic agarwood in the standard agarwood database. The authenticity of the sample is determined based on the similarity of the spectral curves. However, the hardware platform required for this patented method is large and expensive, making it impractical for private agarwood collectors to use for testing. Summary of the Invention
[0005] The present invention provides an agarwood quality detection method based on machine vision. The method is based on the precise positioning of the agarwood carbon line, and then detects the ash shrinkage rate of the agarwood ash and the height of the carbon line, and then uses these two indicators to evaluate the agarwood quality.
[0006] In order to achieve the above technical effects, the technical solutions of the present invention are as follows:
[0007] A method for detecting agarwood quality based on machine vision, comprising the following steps:
[0008] S1: Locate the agarwood and cut out the area around it;
[0009] S2: Optimize the weight coefficients of the agarwood carbon line to find the three weight coefficients that can best highlight the difference between the real carbon line and the crack. Substitute the obtained weight coefficients into the feature vector to calculate the dissimilarity between each target and the real carbon line; the smaller the dissimilarity of a target, the more likely it is to be the real carbon line. Finally, through iterative optimization of each target, find the target with the smallest dissimilarity. This target is considered to be the real carbon line, thus completing the highly coarse positioning of the agarwood carbon line and completing the global optimization of the agarwood carbon line;
[0010] S3: performing local optimization on the carbon line that has been globally optimized in step S2 to complete fine positioning of the agarwood carbon line, that is, completing highly precise positioning of the agarwood carbon line;
[0011] S4: Calculate the ash shrinkage rate of the agarwood carbon line that has been precisely positioned in step S3 to complete the evaluation of the agarwood quality.
[0012] Furthermore, in step S2, since the similarity between vectors is measured inversely by dissimilarity, the smaller the dissimilarity, the more similar the two vectors are. Therefore, let Represents an unknown pattern vector and the known pattern vector The sign of the dissimilarity between , if:
[0013]
[0014] The unknown pattern vector With known pattern vector More similar;
[0015] Unknown pattern vector With the Known pattern vectors The Euclidean distance between Defined as:
[0016]
[0017] in , two vectors whose Euclidean distance is zero are completely similar, that is:
[0018]
[0019] like:
[0020]
[0021] Then it is called Yes The nearest neighbor is the nearest neighbor, and this nearest neighbor is the agarwood carbon line to be found during global optimization;
[0022] The solution to the dissimilarity has a common basis, that is, the unknown pattern vector , then all known pattern vectors and Substituting into formula (2) to solve the dissimilarity, we can know which known pattern vector with unknown pattern vector Most similar;
[0023] Furthermore, in step S2, due to the presence of agarwood with different radii, the various characteristics of its carbon lines are also changing, that is, there is no fixed known vector to solve the dissimilarity. Therefore, by observing the characteristics of real agarwood carbon lines and pseudo-targets such as cracks, it is found that the closer the width of the detected target is to the diameter of the agarwood, the more likely it is an agarwood carbon line, and the closer the area of the connected domain of the target is to the area of the circumscribed rectangle of the target, and the closer the area of the minimum circumscribed rectangle of the target is to the area of the circumscribed rectangle, the more likely the target is an agarwood carbon line; therefore, for the special case of agarwood carbon lines, the solution formula for the dissimilarity is shown in (5), The continuous change of represents the different targets iterated when searching for carbon lines. From formula (5), we can also know that as the targets change, the two vectors for solving the dissimilarity are constantly changing:
[0024]
[0025] in, , , , The width of the agarwood stick, that is, the width of the real agarwood carbon line. is the area of the connected domain of the target, is the area of the circumscribed rectangle of the connected domain, is the width of the target, The area of the minimum circumscribed rectangle of the connected domain;
[0026] To solve the problem that length and area are not in the same dimension, the length is converted into area. and Convert to and , and then substitute into formula (5) to solve the dissimilarity:
[0027]
[0028]
[0029] The dissimilarity of all targets is obtained by formula (5), and then the target with the minimum dissimilarity is found by iterative optimization, and it is regarded as the agarwood carbon line. However, in fact, the width, area, and area of the minimum circumscribed rectangle of the target should contribute differently to the final result of the dissimilarity solution. Therefore, and Each feature in Three different coefficients:
[0030]
[0031]
[0032] in , by setting The values of the three coefficients make the difference between the dissimilarity of the real agarwood carbon line and the dissimilarity of other pseudo targets the largest. When the difference is the largest, it means that this set of coefficients is the best coefficient for the global optimization of carbon lines. Given that the lower limit of these three weight coefficients is 0.1, their upper limit is 0.8. Through experiments, it is found that when Take 0.8, Take 0.1, When the value is 0.1, the difference between different targets is the largest.
[0033] Furthermore, in step S3, the grayscale value is used to perform local optimization of the carbon line. Since the grayscale value of the darkest part of the carbon line when burning under different types of agarwood and different lighting environments is not necessarily the same, a method for solving the grayscale threshold of the upper and lower boundaries of the carbon line that is applicable to different situations needs to be formulated. In other words, an adaptive threshold is required for the search of carbon lines:
[0034] Before solving the grayscale thresholds of the upper and lower boundaries of the carbon line, the image is cut on the part selected by the rough positioning frame of the carbon line. The number of cuts for different carbon line heights is also different. Indicates the lower edge position of the carbon line after rough positioning. Indicates the upper edge position, [] indicates the rounding symbol. represents the central position of the carbon line, in formula (7), It represents the number of image cuts in the carbon line rough positioning area. After counting the carbon line heights of various agarwood samples after rough positioning, it is found that the smallest carbon line heights are between 40 and 45. The denominator in formula (7) is set to 4:
[0035]
[0036]
[0037] Furthermore, in step S3, the average grayscale value of each part after image cutting of the carbon line rough positioning area is obtained, as shown in formula (8), Indicates the image segmentation of the carbon line rough positioning area. The average gray value of the image, Indicates that the image is cut into share:
[0038]
[0039] As shown in formula (9), the grayscale value with the smallest value is retained by iteration. , and use it as the boundary grayscale threshold for local optimization of carbon line :
[0040]
[0041] After the boundary threshold of the carbon line is obtained through adaptive calculation, the image of the rough positioning area of the carbon line is cut, and then the contour of the carbon line is searched again in the cut area using the boundary threshold obtained through adaptive calculation. The carbon line contour searched out at this time is the true contour of the carbon line.
[0042] Furthermore, in step S3, after finding the true outline of the carbon line, it does not mean that the height of the carbon line has been determined. Although the shape of the carbon line is relatively flat at the upper and lower edges in most cases during the combustion process, it is sometimes uneven or tilted. If the carbon line height is directly calculated without considering this situation, the carbon line height of the same agarwood will show huge differences. At this time, it is necessary to continue to optimize the carbon line height for special cases.
[0043] Furthermore, after obtaining the boundary threshold of the carbon line, we start looking for the upper and lower edges of the carbon line as shown in formulas (10) and (11), and use the upper and lower edge positions of the carbon line obtained by rough positioning of the carbon line. and To retrieve the origin, the image is cut from both the top and bottom directions with a certain pixel value as the step unit, and the average grayscale value of each cut image is calculated; in order to improve the efficiency of carbon line optimization, the optimization is subdivided into two steps: large step optimization and small step optimization. The pixel cutting threshold of large step optimization is t, and the pixel cutting threshold of small step optimization is 1. The pixel cutting threshold t of large step optimization is set to 4;
[0044] The upper edge of the coordinate axis in image processing The value is greater than the lower edge The numerical value is smaller, and the The meaning is representative to The average gray value of this area, The meaning is representative to The average gray value of this area, because the upper and lower edges of the carbon line are mostly not flat, and the calculation of the carbon line height is not to find the difference between the highest point and the lowest point of the true contour of the carbon line, so for the optimization of the true carbon line height, it is allowed that when the gray value of half of the pixels in a row reaches the boundary threshold of the carbon line, it is still considered to constitute the carbon line height; here, the average gray value of each image calculated during the local optimization is multiplied by 1.5 times the boundary threshold. For comparison, when the requirements are met for the first time, the initial position of the carbon line precision positioning is determined. The initial positions of the carbon line precision positioning at the upper and lower edges are and :
[0045] (10)
[0046] (11).
[0047] Furthermore, in step S3, the step of the preliminary fine positioning of the carbon line is 4 pixels. To ensure that the positioning accuracy of the carbon line reaches the pixel level, as shown in equations (12) and (13), the steps of the carbon line fine positioning are repeated, but the step of the image segmentation is changed to one pixel, and the initial point of the retrieval is changed to and Finally, the final position of the upper and lower edges of the carbon line after the carbon line is precisely positioned is obtained. and , so far, the local optimization of the carbon line is completed:
[0048] (12)
[0049] (13).
[0050] Furthermore, in step S4, the gray shrinkage rate is calculated:
[0051]
[0052]
[0053] in, Represents the gray shrinkage rate, Represents the original area of agarwood ash, Represents the area of agarwood ash.
[0054] Compared with the prior art, the beneficial effects of the technical solution of the present invention are:
[0055] This paper proposes, for the first time, a method for evaluating agarwood quality from a machine vision perspective. It proposes an agarwood quality machine vision inspection method based on adaptive global-local optimization to address the challenges of detecting various agarwood indicators. During the global optimization phase for agarwood carbon lines, the concept of target dissimilarity is introduced to perform a global search for carbon lines to eliminate possible interference from pseudo-targets such as cracks. During the local optimization phase for carbon lines, a two-stage local optimization scheme with adaptive carbon line grayscale constraints is proposed to address the issue of varying thresholds for identifying agarwood carbon lines due to differences in agarwood species and variable illumination intensity in the detection scene. Coarse carbon line positioning is used to determine the agarwood species and an adaptive threshold for the carbon line boundary under the given illumination environment. This adaptive threshold is then used to perform secondary local optimization for the carbon line contour and height. To address the gray shrinkage detection error caused by uneven carbon line contour edges, this paper proposes a gray shrinkage compensation parameter to calibrate the error. The gray shrinkage compensation parameter is calculated using dissimilarity, which reflects the degree of unevenness of the carbon line contour edges. BRIEF DESCRIPTION OF THE DRAWINGS
[0056] Figure 1 This is a picture of the actual agarwood;
[0057] Figure 2 This is the overall flow chart of the method of the present invention;
[0058] Figure 3 This is a schematic diagram of the true outline of the agarwood carbon line;
[0059] Figure 4 On the left is a rough positioning diagram of the carbon line;
[0060] Figure 4 The right side shows the precise positioning of the carbon line;
[0061] Figure 5 This is a schematic diagram of the change of the gray value from top to bottom when the outline of the carbon line is not clear;
[0062] Figure 6 Schematic diagram of the agarwood ash area and the original agarwood ash area. DETAILED DESCRIPTION
[0063] The accompanying drawings are for illustrative purposes only and are not to be construed as limiting this patent;
[0064] In order to better illustrate this embodiment, some parts in the drawings may be omitted, enlarged, or reduced, and do not represent the actual product size;
[0065] It is understandable to those skilled in the art that some well-known structures and descriptions thereof may be omitted in the drawings.
[0066] The technical solution of the present invention is further described below with reference to the accompanying drawings and embodiments.
[0067] Example 1
[0068] like Figure 2 As shown, a method for detecting agarwood quality based on machine vision includes the following steps:
[0069] S1: Locate the agarwood and cut out the area around it;
[0070] S2: Optimize the weight coefficients of the agarwood carbon line to find the three weight coefficients that can best highlight the difference between the real carbon line and the crack. Substitute the obtained weight coefficients into the feature vector to calculate the dissimilarity between each target and the real carbon line; the smaller the dissimilarity of a target, the more likely it is to be the real carbon line. Finally, through iterative optimization of each target, find the target with the smallest dissimilarity. This target is considered to be the real carbon line, thus completing the highly coarse positioning of the agarwood carbon line and completing the global optimization of the agarwood carbon line;
[0071] S3: performing local optimization on the carbon line that has been globally optimized in step S2 to complete fine positioning of the agarwood carbon line, that is, completing highly precise positioning of the agarwood carbon line;
[0072] S4: Calculate the ash shrinkage rate of the agarwood carbon line that has been precisely positioned in step S3 to complete the evaluation of the agarwood quality.
[0073] In step S2, since the similarity between vectors is measured inversely by dissimilarity, the smaller the dissimilarity, the more similar the two vectors are. Therefore, let Represents an unknown pattern vector and the known pattern vector The sign of the dissimilarity between , if:
[0074]
[0075] The unknown pattern vector With known pattern vector More similar;
[0076] Unknown pattern vector With the Known pattern vectors The Euclidean distance between Defined as:
[0077]
[0078] in , two vectors whose Euclidean distance is zero are completely similar, that is:
[0079]
[0080] like:
[0081]
[0082] Then it is called Yes The nearest neighbor is the nearest neighbor, and this nearest neighbor is the agarwood carbon line to be found during global optimization;
[0083] The solution to the dissimilarity has a common basis, that is, the unknown pattern vector , then all known pattern vectors and Substituting into formula (2) to solve the dissimilarity, we can know which known pattern vector with unknown pattern vector Most similar;
[0084] In step S2, due to the existence of agarwood with different radii, the various characteristics of its carbon lines are also changing, that is, there is no fixed known vector to solve the dissimilarity. Therefore, by observing the characteristics of real agarwood carbon lines and pseudo-targets such as cracks, it is found that the closer the width of the detected target is to the diameter of the agarwood, the more likely it is an agarwood carbon line, and the closer the area of the connected domain of the target is to the area of the circumscribed rectangle of the target, and the closer the area of the minimum circumscribed rectangle of the target is to the area of the circumscribed rectangle, the more likely the target is an agarwood carbon line; therefore, for the special case of agarwood carbon lines, the solution formula for the dissimilarity is shown in (5). The continuous change of represents the different targets iterated when searching for carbon lines. From formula (5), we can also know that as the targets change, the two vectors for solving the dissimilarity are constantly changing:
[0085]
[0086] in, , , , The width of the agarwood stick, that is, the width of the real agarwood carbon line. is the area of the connected domain of the target, is the area of the circumscribed rectangle of the connected domain, is the width of the target, The area of the minimum circumscribed rectangle of the connected domain;
[0087] To solve the problem that length and area are not in the same dimension, the length is converted into area. and Convert to and , and then substitute into formula (5) to solve the dissimilarity:
[0088]
[0089]
[0090] The dissimilarity of all targets is obtained by formula (5), and then the target with the minimum dissimilarity is found by iterative optimization, and it is regarded as the agarwood carbon line. However, in fact, the width, area, and area of the minimum circumscribed rectangle of the target should contribute differently to the final result of the dissimilarity solution. Therefore, and Each feature in Three different coefficients:
[0091]
[0092]
[0093] in , by setting The values of the three coefficients make the difference between the dissimilarity of the real agarwood carbon line and the dissimilarity of other pseudo targets the largest. When the difference is the largest, it means that this set of coefficients is the best coefficient for the global optimization of carbon lines. Given that the lower limit of these three weight coefficients is 0.1, their upper limit is 0.8. Through experiments, it is found that when Take 0.8, Take 0.1, When the value is 0.1, the difference between different targets is the largest.
[0094] In step S3, the grayscale value is used to perform local optimization of the carbon line. Since the grayscale value of the darkest part of the carbon line when burning in different types of agarwood and different lighting environments is not necessarily the same, a method for solving the grayscale threshold of the upper and lower boundaries of the carbon line that is applicable to different situations needs to be formulated. In other words, an adaptive threshold is required for the search of carbon lines:
[0095] Before solving the grayscale thresholds of the upper and lower boundaries of the carbon line, the image is cut on the part selected by the rough positioning frame of the carbon line. The number of cuts for different carbon line heights is also different. Indicates the lower edge position of the carbon line after rough positioning. Indicates the upper edge position, [] indicates the rounding symbol. represents the central position of the carbon line, in formula (7), It represents the number of image cuts in the carbon line rough positioning area. After counting the carbon line heights of various agarwood samples after rough positioning, it is found that the smallest carbon line heights are between 40 and 45. The denominator in formula (7) is set to 4:
[0096]
[0097]
[0098] The average gray value of each part after image cutting of the carbon line rough positioning area is calculated, as shown in formula (8): Indicates the image segmentation of the carbon line rough positioning area. The average gray value of the image, Indicates that the image is cut into share:
[0099]
[0100] As shown in formula (9), the grayscale value with the smallest value is retained by iteration. , and use it as the boundary grayscale threshold for local optimization of carbon line :
[0101]
[0102] After the boundary threshold of the carbon line is obtained through adaptive calculation, the image of the rough positioning area of the carbon line is cut, and then the contour of the carbon line is searched again in the cut area using the boundary threshold obtained through adaptive calculation. The carbon line contour searched out at this time is the true contour of the carbon line.
[0103] Once the true outline of the carbon line is found, it does not mean that the height of the carbon line has been determined. Although the upper and lower edges of the carbon line are relatively flat in most cases during the burning process, it is sometimes uneven or tilted. If the carbon line height is directly calculated without considering this situation, the carbon line height of the same agarwood will show huge differences. At this time, it is necessary to continue to optimize the carbon line height for special cases.
[0104] After obtaining the boundary threshold of the carbon line, start looking for the upper and lower edges of the carbon line as shown in formulas (10) and (11). The upper and lower edge positions of the carbon line obtained by rough positioning of the carbon line are and To retrieve the origin, the image is cut from both the top and bottom directions with a certain pixel value as the step unit, and the average grayscale value of each cut image is calculated; in order to improve the efficiency of carbon line optimization, the optimization is subdivided into two steps: large step optimization and small step optimization. The pixel cutting threshold of large step optimization is t, and the pixel cutting threshold of small step optimization is 1. The pixel cutting threshold t of large step optimization is set to 4;
[0105] The upper edge of the coordinate axis in image processing The value is greater than the lower edge The numerical value is smaller, and the The meaning is representative to The average gray value of this area, The meaning is representative to The average gray value of this area, because the upper and lower edges of the carbon line are mostly not flat, and the calculation of the carbon line height is not to find the difference between the highest point and the lowest point of the true contour of the carbon line, so for the optimization of the true carbon line height, it is allowed that when the gray value of half of the pixels in a row reaches the boundary threshold of the carbon line, it is still considered to constitute the carbon line height; here, the average gray value of each image calculated during the local optimization is multiplied by 1.5 times the boundary threshold. For comparison, when the requirements are met for the first time, the initial position of the carbon line precision positioning is determined. The initial positions of the carbon line precision positioning at the upper and lower edges are and :
[0106] (10)
[0107] (11).
[0108] The step size of the initial fine positioning of the carbon line is 4 pixels. To ensure that the positioning accuracy of the carbon line reaches the pixel level, as shown in Equations (12) and (13), the steps of the carbon line fine positioning are repeated, but the step size of the image segmentation is changed to one pixel, and the initial point of the retrieval is changed to and Finally, the final position of the upper and lower edges of the carbon line after the carbon line is precisely positioned is obtained. and , so far, the local optimization of the carbon line is completed:
[0109] (12)
[0110] (13).
[0111] In step S4, the gray shrinkage rate is calculated:
[0112]
[0113]
[0114] in, Represents the gray shrinkage rate, Represents the original area of agarwood ash, Represents the area of agarwood ash.
[0115] Example 2
[0116] like Figure 2As shown, the present invention proposes a method for detecting agarwood quality based on machine vision. The key to this method lies in the precise pixel-level positioning of agarwood carbon lines. Based on this, two indicators that reflect agarwood quality, carbon line height and ash shrinkage rate, are then tested. After inputting an image of burning agarwood captured by the data acquisition system, the algorithm first locates the agarwood and cuts out the area near the agarwood to save time in the subsequent carbon line optimization. The second step is to optimize the weight coefficients during the global optimization of carbon lines, finding the three weight coefficients that best highlight the difference between the true carbon line and the crack. The obtained weight coefficients are then substituted into the feature vector to calculate the dissimilarity between each target and the true carbon line. The smaller the dissimilarity of a target, the more likely it is to be a true carbon line. Finally, through iterative optimization of each target, the target with the smallest dissimilarity is found and is considered the true carbon line. This completes the high-speed coarse positioning of the agarwood carbon lines, i.e., the global optimization of carbon lines. At the same time, it is necessary to point out that during global optimization, even if a target found by iteration is indeed a true carbon line, the dissimilarity calculated based on that target may not be 0, because the algorithm originally assumed that the true carbon line should be a rectangle. At the same time, after global optimization, the algorithm will calculate the carbon line adaptive threshold based on the area where the searched true carbon line is located, preparing for the subsequent secondary optimization of the carbon line contour.
[0117] The reason for continuing to search for carbon lines locally is that the carbon lines selected by the global search do not exactly select the true contours of the carbon lines, as shown below. Figure 3As shown, the grayscale values at the junctions of the carbon line with the ash and the agarwood about to burn vary gradually, without a clear demarcation between the carbon line and the rest of the image. This selection inevitably includes some areas that are not carbon lines but closely resemble them in color. Directly calculating the carbon line height and gray shrinkage rate based on this result would clearly yield inaccurate results. Therefore, further refinement of the carbon line positioning is necessary. The first step involves performing a secondary optimization of the carbon line outline using the carbon line adaptive threshold calculated after global optimization. The second step involves performing a local optimization of the carbon line height based on the secondary optimization of the carbon line outline and using the carbon line adaptive threshold as a condition. These first and second steps together achieve pixel-level precision in the positioning of the carbon line outline and height. Finally, based on this pixel-level precision, the agarwood ash area, the original agarwood ash area, and the upper and lower edge positions of the carbon line are calculated. Regarding the calculation of ash shrinkage, it's important to note that when the actual carbon line isn't a perfect rectangle—for example, if the upper and lower edges fluctuate in a certain direction—the selected rectangle will inevitably include some agarwood ash area, which will inevitably affect the accuracy of the subsequent ash shrinkage calculation. Dissimilarity, which reflects the irregularity of the carbon line's profile, is therefore calculated using the results of a secondary optimization search for the carbon line profile. This dissimilarity is then converted into a compensation parameter for the agarwood ash area to improve the accuracy of the final ash shrinkage calculation. This process ultimately allows for high-precision detection of ash shrinkage and carbon line height, ultimately achieving the goal of evaluating agarwood quality through machine vision.
[0118] Since the similarity between vectors is measured inversely by dissimilarity, the smaller the dissimilarity, the more similar the two vectors are. Therefore, let Represents an unknown pattern vector and the known pattern vector The sign of the dissimilarity between , if:
[0119]
[0120] The unknown pattern vector With known pattern vector More similar;
[0121] Unknown pattern vector With the Known pattern vectors The Euclidean distance between Defined as:
[0122]
[0123] in , two vectors whose Euclidean distance is zero are completely similar, that is:
[0124]
[0125] like:
[0126]
[0127] Then it is called Yes The nearest neighbor is the nearest neighbor, and this nearest neighbor is the agarwood carbon line to be found during global optimization;
[0128] The solution to the dissimilarity has a common basis, that is, the unknown pattern vector , then all known pattern vectors and Substituting into formula (2) to solve the dissimilarity, we can know which known pattern vector with unknown pattern vector Most similar;
[0129] In step S2, due to the existence of agarwood with different radii, the various characteristics of its carbon lines are also changing, that is, there is no fixed known vector to solve the dissimilarity. Therefore, by observing the characteristics of real agarwood carbon lines and pseudo-targets such as cracks, it is found that the closer the width of the detected target is to the diameter of the agarwood, the more likely it is an agarwood carbon line, and the closer the area of the connected domain of the target is to the area of the circumscribed rectangle of the target, and the closer the area of the minimum circumscribed rectangle of the target is to the area of the circumscribed rectangle, the more likely the target is an agarwood carbon line; therefore, for the special case of agarwood carbon lines, the solution formula for the dissimilarity is shown in (5). The continuous change of represents the different targets iterated when searching for carbon lines. From formula (5), we can also know that as the targets change, the two vectors for solving the dissimilarity are constantly changing:
[0130]
[0131] in, , , , The width of the agarwood stick, that is, the width of the real agarwood carbon line. is the area of the connected domain of the target, is the area of the circumscribed rectangle of the connected domain, is the width of the target, The area of the minimum circumscribed rectangle of the connected domain;
[0132] To solve the problem that length and area are not in the same dimension, the length is converted into area. and Convert to and , and then substitute into formula (5) to solve the dissimilarity:
[0133]
[0134]
[0135] The dissimilarity of all targets is obtained by formula (5), and then the target with the minimum dissimilarity is found by iterative optimization, and it is regarded as the agarwood carbon line. However, in fact, the width, area, and area of the minimum circumscribed rectangle of the target should contribute differently to the final result of the dissimilarity solution. Therefore, and Each feature in Three different coefficients:
[0136]
[0137]
[0138] in , by setting The values of the three coefficients make the difference between the dissimilarity of the real agarwood carbon line and the dissimilarity of other pseudo targets the largest. When the difference is the largest, it means that this set of coefficients is the best coefficient for the global optimization of carbon lines. Given that the lower limit of these three weight coefficients is 0.1, their upper limit is 0.8. Through experiments, it is found that when Take 0.8, Take 0.1, When the value is 0.1, the difference between different targets is the largest.
[0139] In step S3, the grayscale value is used to perform local optimization of the carbon line. Since the grayscale value of the darkest part of the carbon line when burning in different types of agarwood and different lighting environments is not necessarily the same, a method for solving the grayscale threshold of the upper and lower boundaries of the carbon line that is applicable to different situations needs to be formulated. In other words, an adaptive threshold is required for the search of carbon lines:
[0140] Before solving the grayscale thresholds of the upper and lower boundaries of the carbon line, the image is cut on the part selected by the rough positioning frame of the carbon line. The number of cuts for different carbon line heights is also different. Indicates the lower edge position of the carbon line after rough positioning. Indicates the upper edge position, [] indicates the rounding symbol. represents the central position of the carbon line, in formula (7), It represents the number of image cuts in the carbon line rough positioning area. After counting the carbon line heights of various agarwood samples after rough positioning, it is found that the smallest carbon line heights are between 40 and 45. The denominator in formula (7) is set to 4:
[0141]
[0142]
[0143] The average gray value of each part after image cutting of the carbon line rough positioning area is calculated, as shown in formula (8): Indicates the image segmentation of the carbon line rough positioning area. The average gray value of the image, Indicates that the image is cut into share:
[0144]
[0145] As shown in formula (9), the grayscale value with the smallest value is retained by iteration. , and use it as the boundary grayscale threshold for local optimization of carbon line :
[0146]
[0147] After the boundary threshold of the carbon line is obtained through adaptive calculation, the image of the rough positioning area of the carbon line is cut, and then the contour of the carbon line is searched again in the cut area using the boundary threshold obtained through adaptive calculation. The carbon line contour searched out at this time is the true contour of the carbon line.
[0148] Once the true outline of the carbon line is found, it does not mean that the height of the carbon line has been determined. Although the upper and lower edges of the carbon line are relatively flat in most cases during the burning process, it is sometimes uneven or tilted. If the carbon line height is directly calculated without considering this situation, the carbon line height of the same agarwood will show huge differences. At this time, it is necessary to continue to optimize the carbon line height for special cases.
[0149] After obtaining the boundary threshold of the carbon line, start looking for the upper and lower edges of the carbon line as shown in formulas (10) and (11). The upper and lower edge positions of the carbon line obtained by rough positioning of the carbon line are and To retrieve the origin, the image is cut from both the top and bottom directions with a certain pixel value as the step unit, and the average grayscale value of each cut image is calculated; in order to improve the efficiency of carbon line optimization, the optimization is subdivided into two steps: large step optimization and small step optimization. The pixel cutting threshold of large step optimization is t, and the pixel cutting threshold of small step optimization is 1. The pixel cutting threshold t of large step optimization is set to 4;
[0150] The upper edge of the coordinate axis in image processing The value is greater than the lower edge The numerical value is smaller, and the The meaning is representative to The average gray value of this area, The meaning is representative to The average gray value of this area, because the upper and lower edges of the carbon line are mostly not flat, and the calculation of the carbon line height is not to find the difference between the highest point and the lowest point of the true contour of the carbon line, so for the optimization of the true carbon line height, it is allowed that when the gray value of half of the pixels in a row reaches the boundary threshold of the carbon line, it is still considered to constitute the carbon line height; here, the average gray value of each image calculated during the local optimization is multiplied by 1.5 times the boundary threshold. For comparison, when the requirements are met for the first time, the initial position of the carbon line precision positioning is determined. The initial positions of the carbon line precision positioning at the upper and lower edges are and :
[0151] (10)
[0152] (11).
[0153] The step size of the initial fine positioning of the carbon line is 4 pixels. To ensure that the positioning accuracy of the carbon line reaches the pixel level, as shown in Equations (12) and (13), the steps of the carbon line fine positioning are repeated, but the step size of the image segmentation is changed to one pixel, and the initial point of the retrieval is changed to and Finally, the final position of the upper and lower edges of the carbon line after the carbon line is precisely positioned is obtained. and , so far, the local optimization of the carbon line is completed:
[0154] (12)
[0155] (13).
[0156] In step S4, the gray shrinkage rate is calculated:
[0157]
[0158]
[0159] in, Represents the gray shrinkage rate, Represents the original area of agarwood ash, Represents the area of agarwood ash.
[0160] The global optimization of agarwood carbon lines using dissimilarity is only a rough positioning. Figure 4 The left figure shows the result of global optimization of carbon lines. If the carbon line height and ash shrinkage rate are directly calculated based on this result, the carbon line height will obviously be too high, and the other indicator will have different deviations. The different detection errors of these two indicators caused by the large error in carbon line detection will inevitably lead to large deviations in the final evaluation of agarwood quality. Therefore, it is necessary to further accurately locate the agarwood carbon line, such as Figure 4 The figure on the right shows the target of precise positioning of carbon wires that needs to be achieved, and then various indicators are calculated based on this precise positioning.
[0161] like Figure 5 The figure shows the change of the gray value from top to bottom when the outline of the carbon line is not clear. It can be seen from the figure that the gray value of the edge area of the carbon line changes relatively slowly. In this case, the non-carbon line part is easily selected, which may cause the carbon line height to be too large. If some thresholds in the detection method are single and fixed or the selection is not accurate enough, it will appear Figure 4 The situation shown on the left is that the selected area is too large.
[0162] Example 3
[0163] like Figure 2 As shown, a method for detecting agarwood quality based on machine vision includes the following steps:
[0164] S1: Locate the agarwood and cut out the area around it;
[0165] S2: Optimize the weight coefficients of the agarwood carbon line to find the three weight coefficients that can best highlight the difference between the real carbon line and the crack. Substitute the obtained weight coefficients into the feature vector to calculate the dissimilarity between each target and the real carbon line; the smaller the dissimilarity of a target, the more likely it is to be the real carbon line. Finally, through iterative optimization of each target, find the target with the smallest dissimilarity. This target is considered to be the real carbon line, thus completing the highly coarse positioning of the agarwood carbon line and completing the global optimization of the agarwood carbon line;
[0166] S3: performing local optimization on the carbon line that has been globally optimized in step S2 to complete fine positioning of the agarwood carbon line, that is, completing highly precise positioning of the agarwood carbon line;
[0167] S4: Calculate the ash shrinkage rate of the agarwood carbon line that has been precisely positioned in step S3 to complete the evaluation of the agarwood quality.
[0168] In step S2, since the similarity between vectors is measured inversely by dissimilarity, the smaller the dissimilarity, the more similar the two vectors are. Therefore, let Represents an unknown pattern vector and the known pattern vector The sign of the dissimilarity between , if:
[0169]
[0170] The unknown pattern vector With known pattern vector More similar;
[0171] Unknown pattern vector With the Known pattern vectors The Euclidean distance between Defined as:
[0172]
[0173] in , two vectors whose Euclidean distance is zero are completely similar, that is:
[0174]
[0175] like:
[0176]
[0177] Then it is called Yes The nearest neighbor is the nearest neighbor, and this nearest neighbor is the agarwood carbon line to be found during global optimization;
[0178] The solution to the dissimilarity has a common basis, that is, the unknown pattern vector , then all known pattern vectors and Substituting into formula (2) to solve the dissimilarity, we can know which known pattern vector with unknown pattern vector Most similar;
[0179] In step S2, due to the existence of agarwood with different radii, the various characteristics of its carbon lines are also changing, that is, there is no fixed known vector to solve the dissimilarity. Therefore, by observing the characteristics of real agarwood carbon lines and pseudo-targets such as cracks, it is found that the closer the width of the detected target is to the diameter of the agarwood, the more likely it is an agarwood carbon line, and the closer the area of the connected domain of the target is to the area of the circumscribed rectangle of the target, and the closer the area of the minimum circumscribed rectangle of the target is to the area of the circumscribed rectangle, the more likely the target is an agarwood carbon line; therefore, for the special case of agarwood carbon lines, the solution formula for the dissimilarity is shown in (5). The continuous change of represents the different targets iterated when searching for carbon lines. From formula (5), we can also know that as the targets change, the two vectors for solving the dissimilarity are constantly changing:
[0180]
[0181] in, , , , The width of the agarwood stick, that is, the width of the real agarwood carbon line. is the area of the connected domain of the target, is the area of the circumscribed rectangle of the connected domain, is the width of the target, The area of the minimum circumscribed rectangle of the connected domain;
[0182] To solve the problem that length and area are not in the same dimension, the length is converted into area. and Convert to and , and then substitute into formula (5) to solve the dissimilarity:
[0183]
[0184]
[0185] The dissimilarity of all targets is obtained by formula (5), and then the target with the minimum dissimilarity is found by iterative optimization, and it is regarded as the agarwood carbon line. However, in fact, the width, area, and area of the minimum circumscribed rectangle of the target should contribute differently to the final result of the dissimilarity solution. Therefore, and Each feature in Three different coefficients:
[0186]
[0187]
[0188] in , by setting The values of the three coefficients make the difference between the dissimilarity of the real agarwood carbon line and the dissimilarity of other pseudo targets the largest. When the difference is the largest, it means that this set of coefficients is the best coefficient for the global optimization of carbon lines. Given that the lower limit of these three weight coefficients is 0.1, their upper limit is 0.8. Through experiments, it is found that when Take 0.8, Take 0.1, When the value is 0.1, the difference between different targets is the largest.
[0189] In step S3, the grayscale value is used to perform local optimization of the carbon line. Since the grayscale value of the darkest part of the carbon line when burning in different types of agarwood and different lighting environments is not necessarily the same, a method for solving the grayscale threshold of the upper and lower boundaries of the carbon line that is applicable to different situations needs to be formulated. In other words, an adaptive threshold is required for the search of carbon lines:
[0190] Before solving the grayscale thresholds of the upper and lower boundaries of the carbon line, the image is cut on the part selected by the rough positioning frame of the carbon line. The number of cuts for different carbon line heights is also different. Indicates the lower edge position of the carbon line after rough positioning. Indicates the upper edge position, [] indicates the rounding symbol. represents the central position of the carbon line, in formula (7), It represents the number of image cuts in the carbon line rough positioning area. After counting the carbon line heights of various agarwood samples after rough positioning, it is found that the smallest carbon line heights are between 40 and 45. The denominator in formula (7) is set to 4:
[0191]
[0192]
[0193] The average gray value of each part after image cutting of the carbon line rough positioning area is calculated, as shown in formula (8): Indicates the image segmentation of the carbon line rough positioning area. The average gray value of the image, Indicates that the image is cut into share:
[0194]
[0195] As shown in formula (9), the grayscale value with the smallest value is retained by iteration. , and use it as the boundary grayscale threshold for local optimization of carbon line :
[0196]
[0197] After the boundary threshold of the carbon line is obtained through adaptive calculation, the image of the rough positioning area of the carbon line is cut, and then the contour of the carbon line is searched again in the cut area using the boundary threshold obtained through adaptive calculation. The carbon line contour searched out at this time is the true contour of the carbon line.
[0198] Once the true outline of the carbon line is found, it does not mean that the height of the carbon line has been determined. Although the upper and lower edges of the carbon line are relatively flat in most cases during the burning process, it is sometimes uneven or tilted. If the carbon line height is directly calculated without considering this situation, the carbon line height of the same agarwood will show huge differences. At this time, it is necessary to continue to optimize the carbon line height for special cases.
[0199] After obtaining the boundary threshold of the carbon line, start looking for the upper and lower edges of the carbon line as shown in formulas (10) and (11). The upper and lower edge positions of the carbon line obtained by rough positioning of the carbon line are and To retrieve the origin, the image is cut from both the top and bottom directions with a certain pixel value as the step unit, and the average grayscale value of each cut image is calculated; in order to improve the efficiency of carbon line optimization, the optimization is subdivided into two steps: large step optimization and small step optimization. The pixel cutting threshold of large step optimization is t, and the pixel cutting threshold of small step optimization is 1. The pixel cutting threshold t of large step optimization is set to 4;
[0200] The upper edge of the coordinate axis in image processing The value is greater than the lower edge The numerical value is smaller, and the The meaning is representative to The average gray value of this area, The meaning is representative to The average gray value of this area, because the upper and lower edges of the carbon line are mostly not flat, and the calculation of the carbon line height is not to find the difference between the highest point and the lowest point of the true contour of the carbon line, so for the optimization of the true carbon line height, it is allowed that when the gray value of half of the pixels in a row reaches the boundary threshold of the carbon line, it is still considered to constitute the carbon line height; here, the average gray value of each image calculated during the local optimization is multiplied by 1.5 times the boundary threshold. For comparison, when the requirements are met for the first time, the initial position of the carbon line precision positioning is determined. The initial positions of the carbon line precision positioning at the upper and lower edges are and :
[0201] (10)
[0202] (11).
[0203] The step size of the initial fine positioning of the carbon line is 4 pixels. To ensure that the positioning accuracy of the carbon line reaches the pixel level, as shown in Equations (12) and (13), the steps of the carbon line fine positioning are repeated, but the step size of the image segmentation is changed to one pixel, and the initial point of the retrieval is changed to and Finally, the final position of the upper and lower edges of the carbon line after the carbon line is precisely positioned is obtained. and , so far, the local optimization of the carbon line is completed:
[0204] (12)
[0205] (13).
[0206] Specific experiments:
[0207] A. Carbon line height
[0208] In the detection of cigarette paper characteristics, the carbon line uniformity is used as an indicator to reflect the quality of cigarette paper. Combined with the characteristics of agarwood burning, it is decided to introduce the carbon line height as an indicator to reflect the quality of agarwood. The calculation of carbon line height is shown in the following formula (14): This is the lower edge of the agarwood carbon line after fine positioning. This is the upper edge position of the agarwood carbon line after fine positioning. and The difference is the carbon line height:
[0209] .
[0210] B. Ash shrinkage rate
[0211] In the field of cigarettes, the ash shrinkage rate of cigarette packs after burning can be used to reflect the quality of tobacco and cigarette paper. Therefore, the ash shrinkage rate is also used as an indicator. However, the calculation accuracy of this indicator is easily affected by the irregularity of the carbon line. The irregularity of the carbon line will lead to a low result of the calculated ash area. Therefore, a compensation ash shrinkage rate indicator is proposed. Before calculating the ash shrinkage rate, the compensation value of the ash area must be calculated. Calculated:
[0212]
[0213] The calculation of the ash shrinkage rate is as follows:
[0214]
[0215] Represents the gray shrinkage rate, Represents the original area of agarwood ash, Represents the area of agarwood ash. The area of agarwood ash and the original area of agarwood ash are as follows Figure 6 The area enclosed by the curve is the ash area, and the rectangular area represents the original area of the ash:
[0216] The same or similar reference numerals correspond to the same or similar components;
[0217] The positional relationships described in the drawings are for illustrative purposes only and should not be construed as limiting this patent.
[0218] Obviously, the above embodiments of the present invention are merely examples for the purpose of clearly illustrating the present invention, and are not intended to limit the embodiments of the present invention. Those skilled in the art will appreciate that other variations or modifications can be made based on the above description. It is not necessary and impossible to enumerate all embodiments here. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention shall be included within the scope of protection of the claims of the present invention.
Claims
1. A method for detecting agarwood quality based on machine vision, characterized in that: The following steps are involved: S1: Locate the agarwood and cut out the area around it; S2: Optimize the weight coefficients of the agarwood carbon line to find the three weight coefficients that can best highlight the difference between the real carbon line and the crack. Substitute the obtained weight coefficients into the feature vector to calculate the dissimilarity between each target and the real carbon line; the smaller the dissimilarity of a target, the more likely it is to be the real carbon line. Finally, through iterative optimization of each target, find the target with the smallest dissimilarity. This target is considered to be the real carbon line, thus completing the highly coarse positioning of the agarwood carbon line and completing the global optimization of the agarwood carbon line; In step S2, due to the existence of agarwood with different radii, the various characteristics of its carbon lines are also changing, that is, there is no fixed known vector to solve the dissimilarity. Therefore, by observing the characteristics of real agarwood carbon lines and pseudo targets such as cracks, it is found that the closer the width of the detected target is to the diameter of the agarwood, the more likely it is an agarwood carbon line, and the closer the area of the connected domain of the target is to the area of the circumscribed rectangle of the target, and the closer the area of the minimum circumscribed rectangle of the target is to the area of the circumscribed rectangle, the more likely the target is an agarwood carbon line. Therefore, for the special case of agarwood carbon lines, the solution formula for the dissimilarity is shown in (5). The continuous change of τ represents the different targets iterated when searching for carbon lines. It can also be seen from formula (5) that as the target changes, the two vectors for solving the dissimilarity are constantly changing: Where τ=1,2,…,n, l is the width of the agarwood stick, that is, the width of the real agarwood carbon line, A τ is the area of the connected domain of the target, S τ is the area of the circumscribed rectangle of the connected domain, l τλ is the width of the target, S τλ The area of the minimum circumscribed rectangle of the connected domain; To solve the problem that length and area are not in the same dimension, convert the length into area, that is, τ and r τ Transformed into x′ τ and r′ τ , and then substitute into formula (5) to solve the dissimilarity: The dissimilarity of all targets is obtained by formula (5), and then the target with the minimum dissimilarity is found by iterative optimization, and it is regarded as the agarwood carbon line. However, in fact, the width, area, and area of the minimum circumscribed rectangle of the target should contribute differently to the final result of the dissimilarity solution. Therefore, x′ is given τ and r′ τ Each feature in is added with three different coefficients β1, β2, and β3: Among them, β1+β2+β3=1. By setting the values of the three coefficients β1, β2, and β3, β1 is set to 0.8, β2 is set to 0.1, and β3 is set to 0.1, so that the difference between the dissimilarity of the real agarwood carbon line and the dissimilarity of other pseudo targets is maximized. When the difference is maximized, it means that this set of coefficients is the best coefficient for the global optimization of the carbon line; S3: performing local optimization on the carbon line that has been globally optimized in step S2 to complete fine positioning of the agarwood carbon line, that is, completing highly precise positioning of the agarwood carbon line; S4: Calculating the ash shrinkage rate of the agarwood carbon line accurately positioned in step S3 to complete the evaluation of the agarwood quality; In step S4, the gray shrinkage rate is calculated: Among them, SR represents the ash shrinkage rate, s represents the original area of agarwood ash, and s1 represents the area of agarwood ash.
2. The agarwood quality detection method based on machine vision according to claim 1, characterized in that: In step S2, since the similarity between vectors is measured inversely by the dissimilarity, the smaller the dissimilarity, the more similar the two vectors are. Therefore, let D(x, r1),…,D(x, r n ) represents the unknown pattern vector x and the known pattern vectors r1, r2, ..., r n The sign of the dissimilarity between , if: D(x,r1)≤D(x,r2) (1) Then the unknown pattern vector x is said to be more similar to the known pattern vector r1; The unknown pattern vector x and the i-th known pattern vector r i The Euclidean distance between E (x,r i ) is defined as: Where i = 1, 2, 3, ..., n, two vectors with Euclidean distance equal to zero are completely similar, that is: like: Then it is called r i ∈{r1,…,r n } is the nearest neighbor to x, which is the agarwood carbon line to be found during global optimization; The solution to the dissimilarity is to have a common basis, that is, the unknown pattern vector x, and then all the known pattern vectors r1, r2, ..., r n Substituting x into formula (2) to solve the dissimilarity, we can know which known pattern vector r i is most similar to the unknown pattern vector x.
3. The agarwood quality detection method based on machine vision according to claim 2, characterized in that: In step S3, the grayscale value is used to perform local optimization of the carbon line. Since the grayscale value of the darkest part of the carbon line when burning in different types of agarwood and different lighting environments is not necessarily the same, a method for solving the grayscale threshold of the upper and lower boundaries of the carbon line that is applicable to different situations needs to be formulated. In other words, an adaptive threshold is required for the search of carbon lines: Before solving the grayscale thresholds of the upper and lower boundaries of the carbon line, the image is cut on the part selected by the rough positioning frame of the carbon line. The number of cuts for different carbon line heights is also different. In formula (6), l0 represents the lower edge position of the carbon line after rough positioning, h represents the upper edge position, [] represents the upward rounding symbol, and m represents the central position of the carbon line. In formula (7), k represents the number of image cuts in the rough positioning area of the carbon line. After counting the carbon line heights of various agarwood samples after rough positioning, it is found that the smallest carbon line heights are between 40 and 45. The denominator in formula (7) is set to 4:
4. The agarwood quality detection method based on machine vision according to claim 3 is characterized in that: In step S3, the average grayscale value of each part after image cutting of the carbon line rough positioning area is obtained, as shown in formula (8), Y(I i ) represents the average grayscale value of the i-th image after image segmentation of the carbon line rough positioning area, and k represents the total number of image segments segmented into k parts: Y(I i )=[I1,I2,…,I k ](8) As shown in formula (9), the Y(I i ), and use it as the boundary grayscale threshold for local optimization of carbon line After the boundary threshold of the carbon line is obtained through adaptive calculation, the image of the rough positioning area of the carbon line is cut, and then the contour of the carbon line is searched again in the cut area using the boundary threshold obtained through adaptive calculation. The carbon line contour searched out at this time is the true contour of the carbon line.
5. The agarwood quality detection method based on machine vision according to claim 4 is characterized in that: In step S3, after finding the true outline of the carbon line, it does not mean that the height of the carbon line has been determined. Although the upper and lower edges of the carbon line are relatively flat in most cases during the combustion process, it is sometimes uneven or tilted. If the carbon line height is directly obtained without considering this situation, the carbon line height of the same agarwood will show huge differences. At this time, it is necessary to continue to optimize the carbon line height for special cases.
6. The agarwood quality detection method based on machine vision according to claim 5, characterized in that: After obtaining the boundary threshold of the carbon line, we start searching for the upper and lower edges of the carbon line as shown in formulas (10) and (11). The upper and lower edge positions h and l0 of the carbon line obtained by rough positioning of the carbon line are used as the search origins. Then, the image is cut from both the upper and lower directions with a certain pixel value as the step unit, and the average grayscale value of each cut image is calculated. In order to improve the efficiency of carbon line optimization, the optimization is subdivided into two steps: large-step optimization and small-step optimization. The pixel cutting threshold of large-step optimization is t, and the pixel cutting threshold of small-step optimization is 1. The pixel cutting threshold t of large-step optimization is set to 4. In the coordinate axis of image processing, the upper edge h is numerically smaller than the lower edge l0. The meaning of represents the average grayscale value of the area from l0-4n to l0-4n+4. The meaning of represents the average gray value of the area from h+4n-4 to h+4n. Since the upper and lower edges of the carbon line are mostly not flat, and the calculation of the carbon line height is not to find the difference between the highest point and the lowest point of the true contour of the carbon line, so for the optimization of the true carbon line height, when the gray value of half of the pixels in a row reaches the boundary threshold of the carbon line, it is still considered to constitute the carbon line height; here, the average gray value of each image calculated during the local optimization is multiplied by 1.5 times the boundary threshold. For comparison, when the requirements are met for the first time, the initial position of the carbon line precision positioning is determined. The initial positions of the carbon line precision positioning at the upper and lower edges are h1 and l1 respectively:
7. The agarwood quality detection method based on machine vision according to claim 6, characterized in that: In step S3, the step of the preliminary fine positioning of the carbon line is 4 pixels. To ensure that the positioning accuracy of the carbon line reaches the pixel level, as shown in equations (12) and (13), the steps of the carbon line fine positioning are repeated, but the step of the image segmentation is changed to 1 pixel, and the initial points of the search are changed to h1 and l1. Finally, the final positions h2 and l2 of the upper and lower edges of the carbon line after the fine positioning of the carbon line are obtained. At this point, the local optimization of the carbon line is completed:
Citation Information
Patent Citations
Evaluation method of cigarette ash characteristics
CN114062589A
Method for measuring the dissimilarity between a first and a second images and a first and second video sequences
US20100254573A1